MT4 Modify Take Profit

 

Hi, I'm trying to modify my take profit; I've set parameters to TAKE PROFIT after the TP is larger then the Order Open Price(). 

     {

      double TP = MarketInfo(Symbol(),MODE_TICKVALUE);

      for(int b= OrdersTotal()-1; b>=0; b--)

        {

         if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES))

            if(OrderSymbol()==Symbol())

               if(OrderType()==OP_SELL)

                  if(OrderOpenPrice() < TP)

                     OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), TP, 0, CLR_NONE);

        }

     }

 
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2.              if(OrderOpenPrice() < TP)

    On a sell order, the TP can only below the open price. Your condition will never be true.

  3. You can't move stops (or pending prices) closer to the market than the minimum: MODE_STOPLEVEL * _Point or SymbolInfoInteger(SYMBOL_TRADE_STOPS_LEVEL).
              Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial

    On some ECN type brokers the value might be zero (the broker doesn't know). Use a minimum of two (2) PIPs.

    The checks a trading robot must pass before publication in the Market - MQL5 Articles (2016)

  4.  double TP = MarketInfo(Symbol(),MODE_TICKVALUE);

    TP must be a price. Tickvalue is not a price.

 
William Roeder #:
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. On a sell order, the TP can only below the open price. Your condition will never be true.

  3. You can't move stops (or pending prices) closer to the market than the minimum: MODE_STOPLEVEL * _Point or SymbolInfoInteger(SYMBOL_TRADE_STOPS_LEVEL).
              Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial

    On some ECN type brokers the value might be zero (the broker doesn't know). Use a minimum of two (2) PIPs.

    The checks a trading robot must pass before publication in the Market - MQL5 Articles (2016)

  4. TP must be a price. Tickvalue is not a price.

Thanks William, 

I solved this. what i'm trying to do is input market info parameters at Take profit. Close[1]<Open[1] etc.


void TP()
{
 for(int b= OrdersTotal()-1; b>=0; b--)
{
    //we select an order
         if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES))

            //We check if the currency pairs match
            if(OrderSymbol()==Symbol())

               //We check if it is a sell order
               if(OrderType()==OP_SELL)
               
               if (OrderStopLoss()> OrderOpenPrice())
               
               if(Bid < OrderOpenPrice())
               {
             OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), OrderOpenPrice() > (Close[1]-Open[1]), 0, CLR_NONE);    
             
             }
             }     
             }