Fractal Break Out-Stuck - page 3

 

Ive switched parameters in both functions OrderModify and OrderSelect to no avail...

The flow seems logical and I have double check all parameters.


This is happening during backtest, but should not matter.

 
//----------------------------------------------//
//-----------------EXITING ORDERS---------------//


for(int i=OrdersTotal()-1; i>=0;i--)
   {
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)  break;
    if(OrderMagicNumber()!=MagicNumber || OrderSymbol() !=Symbol()) continue;
    double SL=OrderStopLoss();
    bool   result;
    int    error;
    //Different OrderTypes
    if(OrderType()==OP_BUY)
       {
        if(BreakEven > 0) 
          {
           if(Bid - OrderOpenPrice() >= Point * BreakEven * mypoint)  //make input for BreakEven    StopLoss)
              {                                                                   //and don't forget mypoint !!!
               if(OrderStopLoss() < OrderOpenPrice()) 
                 {
                  SL = OrderOpenPrice()+Point;
                 }
              }
          }
       }
    if(OrderType()==OP_SELL)              
       {
         //For you to do
          
              
               
                
               
                  
                   
             
             
       }
    if(SL != OrderStopLoss()) result=OrderModify(OrderTicket(),OrderOpenPrice(),SL,OrderTakeProfit(),0,CLR_NONE);
         if(result!=TRUE) { error=GetLastError(); Print("ModifyError = ",OrderTicket(),"   ",error);}       
   }

Make the coding easie to read 

see difference with your own writing this is more easie count {{{{{{{{{{{{{{{   }}}}}}}}}}}}}} 

 
ZacharyRC:

Still having difficulties. I have conducted errors to find out why.


Journal Has Reported:

1) Error 4051=Incorrect Parameter

2) Invalid Ticket for Modifying Order

 

//----------------------------------------------//
//-----------------EXITING ORDERS---------------//


for(int i=OrdersTotal()-1; i>=0;i--)
   {
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)  break;


   if(OrderMagicNumber()!=MagicNumber || OrderSymbol() !=Symbol()) continue;

   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true) Print(GetLastError(),i);
   if(OrderType()==OP_BUY)
      {
      if(Move.BE && StopLoss > 0) 
         {
         if(Bid - OrderOpenPrice() >= Point * StopLoss)
            {
            if(OrderStopLoss() < OrderOpenPrice() + Point * MoveStopTo) 
               {
               OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() + Point * MoveStopTo, OrderTakeProfit(), 0, Red);
               Print("Cant Modify Order"+GetLastError(),i);
               }
            } 
         }
      }
   else
      {
      if(Move.BE && StopLoss > 0) 
         {
         if(OrderOpenPrice() - Ask >= Point * StopLoss)
            {
            if(OrderStopLoss() > OrderOpenPrice() - Point * MoveStopTo)
               {
               OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() - Point * MoveStopTo, OrderTakeProfit(), 0, Red);
               Print("Cant Modify Order"+GetLastError(),i);
               }
            }
         }
      }
   }

 For a Buy how can the SL be above the Open price ?  OrderOpenPrice() + Point * MoveStopTo

 
deVries:

for BUY Possible to have OrderStopLoss() above OrderOpenPrice()  after modified had succeed   and trade is in profit
LOL . . . oops  <red face smiley>
 
RaptorUK:
LOL . . . oops  <red face smiley>


beware the shame delete my post
 
ZacharyRC:

Still having difficulties. I have conducted errors to find out why.


Journal Has Reported:

1) Error 4051=Incorrect Parameter

2) Invalid Ticket for Modifying Order

OK,  maybe your error messages are spurious . . .

 if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true) Print(GetLastError(),i);


               OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() - Point * MoveStopTo, OrderTakeProfit(), 0, Red);
               Print("Cant Modify Order"+GetLastError(),i);

 Why are you calling GetLastError() if the OrderSelect() works ?  if it does show you an error it won't be due to the OrderSelect()

The same case for the OrderModify(),  if the modify works you are still calling GetLastError(),  why ?  only call it if the function fails . . .

            if(OrderStopLoss() > OrderOpenPrice() - Point * MoveStopTo)
               {
               if(!OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() - Point * MoveStopTo, OrderTakeProfit(), 0, Red))
                  Print("Cant Modify Order, error# " + GetLastError()," index ", i);
 
deVries:

beware the shame delete my post
Nope,  I'm human,  I make mistakes too,  I don't mind people knowing that  :-)
 

AHHH I love it. Both of your points make a lot of sense.


{{{{}}}}}-Is way easier as well!

Errors should only be called if function fails.


Thank you both, I hope your weekends went swell.

 
RaptorUK:

 

 For a Buy how can the SL be above the Open price ?  OrderOpenPrice() + Point * MoveStopTo

 


The SL is below the order.



Are you sure you are not refferring to the sell section?

 else{
 
    if(Move.BE && StopLoss > 0) {
               if(OrderOpenPrice() - Ask >= Point * StopLoss)
                {
                  if(OrderStopLoss() > OrderOpenPrice() - Point * MoveStopTo)
                   {
                  OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() - Point * MoveStopTo, OrderTakeProfit(), 0, Red);
                  Print("Cant Modify Order"+GetLastError(),i);
}
 
RaptorUK:
LOL . . . oops  <red face smiley>

It was an error on my part.
Reason: