MoveToBreakEven Problem

 

Hello, I'm coding a grid system and have a problem. The orders have only a stoploss and no takeprofit, after one stoploss gets hit the ea will close all pending orders to let the winning orders open ! Now I want to let him move the Stoploss of the winning orders to breakeven but he dont do that. Here is my code :

at the onTick:

if (currentOpenOrders < previousOpenOrders) {closeallorders(); MoveToBreakeven(); }
          
          
          previousOpenOrders = currentOpenOrders;

my function : I let him print out TEST TEST to see if the ea open the function and he did but he doesent move the SL !

void MoveToBreakeven()
{
double breakevenpricebuy = Kaufpreis+Pipstolockin*Point;
double breakevenpricesell = Kaufpreis-Pipstolockin*Point;

for(int j=OrdersTotal()-1; j>=0;j--)
{
   if(OrderSelect(j,SELECT_BY_POS,MODE_TRADES))
      if(OrderMagicNumber()==magic)
      if(OrderType()==OP_BUY)
      
                  OrderModify(OrderTicket(),OrderOpenPrice(),Kaufpreis+Pipstolockin*Point,OrderTakeProfit(),OrderExpiration(),CLR_NONE);
                  Print("TEST TEST ");
}

for(int n=OrdersTotal()-1; n>=0;n--)
{
   if(OrderSelect(n,SELECT_BY_POS,MODE_TRADES))
      if(OrderMagicNumber()==magic)
      if(OrderType()==OP_SELL)

                  OrderModify(OrderTicket(),OrderOpenPrice(),breakevenpricesell,OrderTakeProfit(),OrderExpiration(),CLR_NONE);
}

}
 
Faat94:

Hello, I'm coding a grid system and have a problem. The orders have only a stoploss and no takeprofit, after one stoploss gets hit the ea will close all pending orders to let the winning orders open ! Now I want to let him move the Stoploss of the winning orders to breakeven but he dont do that. Here is my code :

at the onTick:

my function : I let him print out TEST TEST to see if the ea open the function and he did but he doesent move the SL !


you didn't check modify succeed or failed

and if it failed you don't call GetLastError() to get info why modify has failed

What are Function return values ? How do I use them ? - MQL4 forum

 
Thank you, you are right, I got the problem and solve it. But now I have another question. Is it possible to set the stoplos above the OrderOpenPrice? I'm asking because the ea dont do it
 
Faat94: Is it possible to set the stoplos above the OrderOpenPrice?
  1. Of course it's possible, you just can't set it above the market.
  2. for(int j=OrdersTotal()-1; j>=0;j--)
    {
       if(OrderSelect(j,SELECT_BY_POS,MODE_TRADES))
          if(OrderMagicNumber()==magic)
          if(OrderType()==OP_BUY)
          
                      OrderModify(OrderTicket(),OrderOpenPrice(),Kaufpreis+Pipstolockin*Point,OrderTakeProfit(),OrderExpiration(),CLR_NONE);
                      Print("TEST TEST ");
    
    This code will print TEST TEST for every open order order. (No braces.)
  3. Test your return codes
  4. Print out your variables and find out why.
 

What is "Kaufpreis+Pipstolockin*Point"?

It doesn't appear to be calculated by using either OrderOpenPrice or current price

Reason: