Fractal Break Out-Stuck - page 4

 
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;
//-----The Differnt Order types---//

if(OrderType()==OP_BUY)
{
 if(BreakEven>0)
    {
     if(Bid-OrderOpenPrice() >= Point*BreakEven*mypoint)
      {
       if(OrderStopLoss() <OrderOpenPrice())
         {
          SL=OrderOpenPrice()*Point*mypoint;
          }}}}}

if(SL!=OrderStopLoss()) result=OrderModify(OrderTicket(),OrderOpenPrice(), SL,OrderTakeProfit(),0,CLR_NONE);
if(result!=true){error=GetLastError(); Print("ModifyError=",OrderTicket()," ",error);}

//--------CHECKING FOR ERRORS-------------------//

return(0);
}
}



I created the sell side also, but then deleted it because I was getting errors, so I put back in the one deVries showed me, still getting the same error codes.


4051

4108


Also, why do we add Point to OrderOpenPrice()=SL ?? That just adds the correct digits to the stop loss.

 
ZacharyRC:

I created the sell side also, but then deleted it because I was getting errors, so I put back in the one deVries showed me, still getting the same error codes.

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;
//-----The Differnt Order types---//

if(OrderType()==OP_BUY)
{
 if(BreakEven>0)
    {
     if(Bid-OrderOpenPrice() >= Point*BreakEven*mypoint)
      {
       if(OrderStopLoss() <OrderOpenPrice())
         {
          SL=OrderOpenPrice()*Point*mypoint;       // WRONG HERE
          }}}}}

if(SL!=OrderStopLoss()) result=OrderModify(OrderTicket(),OrderOpenPrice(), SL,OrderTakeProfit(),0,CLR_NONE);
if(result!=true){error=GetLastError(); Print("ModifyError=",OrderTicket()," ",error);}
     //Where is the  }  ??
//--------CHECKING FOR ERRORS-------------------//

return(0);
}
}

4051

4108


Also, why do we add Point to OrderOpenPrice()=SL ?? That just adds the correct digits to the stop loss.

  

Look again to my code and change that Red line   

it is different from what I gave  !!!! 

Can we see the code how it is now 

and the message you get to read giving those errors 

add one point to orderopenprice is to avoid trying modify trade again at breakeven  every tick 

 
deVries:

  

Look again to my code and change that Red line   

it is different from what I gave  !!!! 

Can we see the code how it is now 

and the message you get to read giving those errors 

add one point to orderopenprice is to avoid trying modify trade again at breakeven  every tick 


Yes I picked up on that error, I was just changing some things around and forgot to erase that before posting code. Apologies.


//-----------------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;
//-----The Differnt Order types---//

if(OrderType()==OP_BUY)
{
 if(BreakEven>0)
    {
     if(Bid-OrderOpenPrice() >= Point*BreakEven*mypoint)
      {
       if(OrderStopLoss() <OrderOpenPrice())
         {
          SL=OrderOpenPrice()+Point;
          }}}}}
          

if(OrderType()==OP_SELL)
{
 if(OrderOpenPrice()-Ask >= Point*BreakEven*mypoint)
 {
  if(OrderStopLoss()>OrderOpenPrice())
   {
    SL=OrderOpenPrice() + Point;
    
}}}


if(SL != OrderStopLoss()) result=OrderModify(OrderTicket(),OrderOpenPrice(),SL,OrderTakeProfit(),0,CLR_NONE);
         if(result!=TRUE) { error=GetLastError(); Print("ModifyError = ",OrderTicket(),"   ",error);}     
//--------CHECKING FOR ERRORS-------------------//
Print(GetLastError());
return(0);
}
}
 
2013.03.18 17:55:51    2013.03.11 23:59  Tester: order #6 is closed
2013.03.18 17:55:51    2013.03.11 15:48  BreakOutEA EURUSD,M1: 0
2013.03.18 17:55:51    2013.03.11 15:48  BreakOutEA EURUSD,M1: ModifyError = 6   0
2013.03.18 17:55:51    2013.03.11 15:48  BreakOutEA EURUSD,M1: modify #6 buy 0.03 EURUSD at 1.30390 sl: 1.30055 tp: 1.30855 ok
2013.03.18 17:55:51    2013.03.11 15:48  BreakOutEA EURUSD,M1: open #6 buy 0.03 EURUSD at 1.30390 ok
2013.03.18 17:55:51    2013.03.11 15:47  BreakOutEA EURUSD,M1: 0
2013.03.18 17:55:51    2013.03.11 15:47  BreakOutEA EURUSD,M1: ModifyError = 5   4108
2013.03.18 17:55:51    2013.03.11 15:47  BreakOutEA EURUSD,M1: OrderModify error 4108
2013.03.18 17:55:51    2013.03.11 15:47  BreakOutEA EURUSD,M1: unknown ticket 5 for OrderModify function
2013.03.18 17:55:51    2013.03.11 15:47  BreakOutEA EURUSD,M1: 0
 
Ok! So for a sell I should minus 1 point as well
 
//-----------------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;
   //-----The Differnt Order types---//
   if(OrderType()==OP_BUY)
      {
      if(BreakEven>0)
         {
         if(Bid-OrderOpenPrice() >= Point*BreakEven*mypoint)
            {
            if(OrderStopLoss() <OrderOpenPrice())
               {
               SL=OrderOpenPrice()+Point;
               }}}}   }     //PLACE THE BRACKETS IN LINE OPEN/CLOSE BRACKET AND YOU WILL SEE THE ERROR HERE
          

   if(OrderType()==OP_SELL)
      {
      if(OrderOpenPrice()-Ask >= Point*BreakEven*mypoint)
         {
         if(OrderStopLoss()>OrderOpenPrice())
            {
            SL=OrderOpenPrice() + Point;    //OrderStopLoss has to become point lower then orderopenprice
            }}}


   if(SL != OrderStopLoss()) result=OrderModify(OrderTicket(),OrderOpenPrice(),SL,OrderTakeProfit(),0,CLR_NONE);
         if(result!=TRUE) { error=GetLastError(); Print("ModifyError = ",OrderTicket(),"   ",error);} 
   }    
//--------CHECKING FOR ERRORS-------------------//
Print(GetLastError(
return(0);
}
}

 

 Inside the loop we check every modification for error not outside the loop we don't know for what orderticket last error is in that case

last line print( getlasterror()) b  is not needed

I like to see brackets more in a line

RaptorUK   and I didn't put closing brackets this way }}}}}}

you have made now errors because of that   

 
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;
//-----The Differnt Order types---//

if(OrderType()==OP_BUY)
{
 if(BreakEven>0)
   {
     if(Bid-OrderOpenPrice() >= Point*BreakEven*mypoint)
      {
       if(OrderStopLoss() <OrderOpenPrice())
         {
          SL=OrderOpenPrice()+Point;
}
   }
      }
         }
                  
          

if(OrderType()==OP_SELL)
{
 if(OrderOpenPrice()-Ask >= Point*BreakEven*mypoint)
 {
  if(OrderStopLoss()>OrderOpenPrice())
   {
    SL=OrderOpenPrice() - Point;
    
}
 }
   }


if(SL != OrderStopLoss()) result=OrderModify(OrderTicket(),OrderOpenPrice(),SL,OrderTakeProfit(),0,CLR_NONE);
         if(result!=TRUE) { error=GetLastError(); Print("ModifyError = ",OrderTicket(),"   ",error);}     
}
return(0);
}
}




Is that the order you are requesting for {{{ }}} opening and closing brackets?

That has been an issue for me, I feel very disorganized inside the code.

 

No errors now, but in visual backtest, the SL is not being moved. I had confidence in this but hurting now, apologies for depending so much on the message board.

The brackets were the error but still not functioning correctly.



I have been re-reading the book as well.

 
if(OrderType()==OP_BUY){

 if(BreakEven>0){
   
     if(Bid-OrderOpenPrice() >=BreakEven*mypoint*Point){
      
       if(OrderStopLoss() <OrderOpenPrice()){
         
          SL=OrderOpenPrice()+Point;
}
  }
     }
       }
                  

I think this will help me as well, placing the brackets directly underneath the operator.
 
ZacharyRC:
I think this will help me as well, placing the brackets directly underneath the operator.

Looks horrible to me, but if it makes sense to you then great.  I do it like this so the indenting shows where a block is . . .

if(OrderType()==OP_BUY)
   {
   if(BreakEven>0)
      {
      if(Bid-OrderOpenPrice() >=BreakEven*mypoint*Point)
         {
         if(OrderStopLoss() <OrderOpenPrice())
            {
            SL=OrderOpenPrice()+Point;
            }
         }
      }
   }

 or do it like this . . .

if(OrderType() == OP_BUY && BreakEven > 0 && 
   Bid - OrderOpenPrice() >= BreakEven * mypoint * Point &&
   OrderStopLoss() < OrderOpenPrice() )
   {
   SL = OrderOpenPrice() + Point;
   }
Reason: