Download MetaTrader 5
To add comments, please log in or register
Post web links to other trader's signals and make profit
Subgenius
572
Subgenius 2015.08.27 01:30 

Okay, i'am just using profit amounts to place a stop if order profit is greater than or equal to half of  the expected profit

in tester the resulting journal entry says OrderModify error 1.  what is wrong just using orderopenprice for stoploss?

int OnInit()
 {
 sSymbol=Symbol(); 
 iType=-1;
 iDigits=Digits;
 if(iDigits==3){iMultiplier=100;} 
 if(iDigits==5){iMultiplier=10000;}
 return(INIT_SUCCEEDED);
 }

void OnBreakEven()
 {
 for(int iTickets=OrdersTotal()-1; iTickets>=0; iTickets--)
  {
  if(!OrderSelect(iTickets,SELECT_BY_POS,MODE_TRADES)){continue;}
   {
   if(OrderType()<=OP_SELL && OrderSymbol()==sSymbol && OrderMagicNumber()==iMagic())
    {
    if(OrderType()==OP_BUY && 
    OrderProfit()>=NormalizeDouble((OrderTakeProfit()-OrderOpenPrice())*iMultiplier*OrderLots()*10/2,2))
     {
     if(OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,CLR_NONE))
      {/*Print("***BREAKEVEN HAS BEEN MET***");*/return;}
     else
      {
      Print("CANNOT BREAKEVEN -- PROFIT("+OrderProfit()+") NOT >= ("+
      NormalizeDouble((OrderTakeProfit()-OrderOpenPrice())*iMultiplier*OrderLots()*10/2,2)+
      ")...( TP("+OrderTakeProfit()+")-OPEN("+OrderOpenPrice()+")="+
      ((OrderTakeProfit()-OrderOpenPrice())*iMultiplier)+" ) *ORDERLOTS("+OrderLots()+") / 2");
      return;
      }
     }
    if(OrderType()==OP_SELL && 
     OrderProfit()>=NormalizeDouble((OrderOpenPrice()-OrderTakeProfit())*iMultiplier*OrderLots()*10/2,2))
     {
     if(OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,CLR_NONE))
      {/*Print("***BREAKEVEN HAS BEEN MET***");*/return;}
     else
      {
      Print("CANNOT BREAKEVEN -- PROFIT("+OrderProfit()+") NOT >= ("+
      NormalizeDouble((OrderOpenPrice()-OrderTakeProfit())*iMultiplier*OrderLots()*10/2,2)+
      ")...( OPEN("+OrderOpenPrice()+")-TP("+OrderTakeProfit()+")="+
      ((OrderOpenPrice()-OrderTakeProfit())*iMultiplier)+" ) *ORDERLOTS("+OrderLots()+") / 2");
      }
     }
    }
   }
  }
 }

though it seems to be working it does get errors (picture updated)


Keith Watford
Moderator
7947
Keith Watford 2015.08.27 03:44  

You seem to be assuming that 1 pip is worth 10 $, not sure because I can't work out what you are trying to do.

  if(OrderClosePrice()-OrderOpenPrice()>=(OrderTakeProfit()-OrderOpenPrice())/2)

 is much simpler. Above is for a Buy order obviously

You should also check if the SL has already been modified 

Subgenius
572
Subgenius 2015.08.27 12:46  
GumRai:

You seem to be assuming that 1 pip is worth 10 $, not sure because I can't work out what you are trying to do.

 is much simpler. Above is for a Buy order obviously

You should also check if the SL has already been modified 

ok ive modified my original code

//+-------------------------------------------------------------------+
void OnBreakEven()
 {
 for(int iTickets=OrdersTotal()-1; iTickets>=0; iTickets--)
  {
  if(!OrderSelect(iTickets,SELECT_BY_POS,MODE_TRADES)){continue;}
  if(OrderType()>OP_SELL||OrderSymbol()!=sSymbol||OrderMagicNumber()!=iMagic()){continue;}
  // sells
  if(OrderType()==OP_SELL && OrderOpenPrice()-OrderClosePrice() >=
    (OrderOpenPrice()-OrderTakeProfit())*dBreakEvenPercent && 
     OrderStopLoss()!=OrderOpenPrice())
    {
    if(OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,CLR_NONE))
    {return;}
    }
  //buys
  if(OrderType()==OP_BUY && OrderClosePrice()-OrderOpenPrice() >=
    (OrderTakeProfit()-OrderOpenPrice())*dBreakEvenPercent && 
     OrderStopLoss()!=OrderOpenPrice())
    {
    if(OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,CLR_NONE))
    {return;}
    }
  } 
 }

seems im still getting the OrderModify Error 1 and it seems to begin even before any orders are present

again it does work.. it seems like it does it and other times not

Files:
20150827.txt 50 kb
Subgenius
572
Subgenius 2015.08.27 13:18  
GumRai:

You seem to be assuming that 1 pip is worth 10 $, not sure because I can't work out what you are trying to do.

 is much simpler. Above is for a Buy order obviously

You should also check if the SL has already been modified 

okay now perhaps ive done it -- thx!

void OnBreakEven()
 {
 for(int iTickets=OrdersTotal()-1; iTickets>=0; iTickets--)
  {
  if(!OrderSelect(iTickets,SELECT_BY_POS,MODE_TRADES)){continue;}
  if(OrderType()>OP_SELL||OrderSymbol()!=sSymbol||OrderMagicNumber()!=iMagic()){continue;}
  // sells
  if(OrderType()==OP_SELL && OrderStopLoss()!=OrderOpenPrice())
    if(OrderOpenPrice()-OrderClosePrice() >=
    (OrderOpenPrice()-OrderTakeProfit())*dBreakEvenPercent)
     {
     if(OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,CLR_NONE))
     {return;}
     }
  //buys
  if(OrderType()==OP_BUY && OrderStopLoss()!=OrderOpenPrice())
    if(OrderClosePrice()-OrderOpenPrice() >=
    (OrderTakeProfit()-OrderOpenPrice())*dBreakEvenPercent)
     {
     if(OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,CLR_NONE))
     {return;}
     }
  } 
 }
/
To add comments, please log in or register