Download MetaTrader 5
To add comments, please log in or register
Have you made a screenshot in MetaTrader? Share it with friends!
Fatbardh Pakashtica
193
Fatbardh Pakashtica 2014.04.21 13:57 

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);
}

}
Tjipke de Vries
6275
Tjipke de Vries 2014.04.21 15:36  
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

Fatbardh Pakashtica
193
Fatbardh Pakashtica 2014.04.21 18:20  
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
whroeder1
13593
whroeder1 2014.04.21 18:56  
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.
Keith Watford
Moderator
7870
Keith Watford 2014.04.21 22:24  

What is "Kaufpreis+Pipstolockin*Point"?

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

/
To add comments, please log in or register