Download MetaTrader 5

Help with OrderProfit()

To add comments, please log in or register
Subscribe to signals right in MetaTrader. It is easy!
Samuel Ogden
228
Samuel Ogden 2014.12.16 19:48 
void ExitConditions()
  {
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS))
        {
         int ticket=OrderTicket();
         if(OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol())
           {
            if(OrderType()==OP_BUY)
              {
               // Exit Condition 1 - in profit and close > 5ma

               if(Close[1]>OrderOpenPrice() && OrderProfit()>0 && Close[1]>iMA(Symbol(),Period(),MAPeriod,0,0,PRICE_CLOSE,1))
                 {
                  OrderClose(ticket,Lots,Bid,50,clrRed);
                 }

              }

           }
        }
     }
}
  • This is only supposed to close position if it is in profit and price is > 5ma, for some reason it wont do that and keeps on closing position and seems to just ignore " close[1] > OrderOpenPrice() and OrderProfit() >0
Please can someone let me know what it is im doing wrong? Thanks
sam.
Alain Verleyen
Moderator
30737
Alain Verleyen 2014.12.16 20:34  
samuelgo:
Print your values to check what happens.
To add comments, please log in or register