order Modify

 

Hello to all, hope some can help me

i got alwas Error 130 on order modify

 

extern int    TP = 200;
extern int    Spread =  10;

extern int    magic = 123456;
// function start------------------------------------------------------------------------------------

void OnTick()

  {
//---- 
//Setup comment
   string Text="xxxx "+Symbol();
                                                                     //Setup orders


   if(Volume[0] == 1)
     {
      SetOrders(Text);
     }


   for(int i=0;i<OrdersTotal();i++)
     {
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderComment()==Text )
        {

         if(OrderType()==OP_BUY && Ask <= (OrderOpenPrice() - StopLoss*Point)   )
           {
            OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderOpenPrice(),0,Blue);
            }
         if(OrderType()==OP_SELL   )
           {
           OrderModify(OrderTicket(),OrderOpenPrice(),0,NormalizeDouble(OrderOpenPrice() + TP*Point,Digits)  ,0,Red);
            Print( "Ticket: ", OrderTicket(), " OrderOpenPrice: ", OrderOpenPrice(), " Stop: ",OrderStopLoss() );
           
           }
      
       
        }
      Sleep(10000);
     }


  }

 i will insert a take profit inthe Sell order, the first part, the Take Profit on the OP_BUY will be set normally, The secont OP_SELL produce Error 130

is there something worng with the code?

i used before int start() now i changed it to voit OnTick()

 

regards and thanks in advance 

 
if(Volume[0] == 1)
Bars is unreliable (max bars on chart) volume is unreliable (miss ticks) Always use time.
for(int i=0;i<OrdersTotal();i++)
Get in the habit of counting down. Loops and Closing or Deleting Orders - MQL4 forum
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
:            
OrderModify(OrderTick
:
OrderModify(OrderTick
What happens when there are NO open orders? What are Function return values ? How do I use them ? - MQL4 forum
  OrderModify(OrderTicket(), OrderOpenPrice(), 0, NormalizeDouble(OrderOpenPrice() + TP*Point, Digits), 0, Red);
How can the TP be above the OOP on a sell?
Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
if(OrderComment()==Text )
Not a good idea, brokers can change comments, including complete replacement. Instead I'd use magic numbers.
if(OrderType()==OP_BUY && Ask <= (OrderOpenPrice() - StopLoss*Point)   )
If the Ask is below the SL, shouldn't the order be closed?
 

Thanks for the Answer WHRoeder

 

with

if(Volume[0] == 1)

 i indicate a new bar. how you mean tu use time in this case? i look out since long time for Candle Time to indicate, but i never had a bad experiance with this

can i use Time[0]???? 

 

 for 

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

 whats happen when no open order, in general, i dont know, i never get an error about this. for my computer doesnt matter, how may system power he need for calculate,

but in this case i will look out, bcs there is something changed in MT4. in newer versions i get the warning, check result of order select. This is only happen since, i think version 600

 

 this here will be very interresting

  OrderModify(OrderTicket(), OrderOpenPrice(), 0, NormalizeDouble(OrderOpenPrice() + TP*Point, Digits), 0, Red);

 bcs. i get it from here: https://docs.mql4.com/trading/ordermodify

 

 you are absolutly right, i will change this in my ea, i never had a bad experiance with

if(OrderComment()==Text )

 

but i also found out, that the comment will be changed after some reactions

 

 here

if(OrderType()==OP_BUY && Ask <= (OrderOpenPrice() - StopLoss*Point)   )

 not closed, i only want to set an Take Profit in the Order with OrderModify, on Buy order it works, in Sell order i didnt get an result

 

ok right, i must change the TP and SL on a sell order ;-)

 
loving :

ok right, i must change the TP and SL on a sell order ;-)

I understand that the issue is very old, but I have problems changing my TP in SELL orders, in BUY orders it works perfectly, I just want to use the highest TP in all.



for (int cnt = 0; cnt <OrdersTotal (); cnt ++)

{

if (cnt == 0) NewTakeProfit = OrderTakeProfit (); // use first reference tp

OrderSelect (cnt, SELECT_BY_POS, MODE_TRADES); // I select each order

// ONLY THE SELL ORDERS MADE BY THE ALGORITHM IN THAT PAR

if (OrderType () == OP_SELL && OrderSymbol () == Symbol () && OrderMagicNumber () == MagicNumber)

{

if (OrderTakeProfit () <= NewTakeProfit)

{

NewTakeProfit = OrderTakeProfit ();

}


}

}


// assign major TP to all open orders

for (int cnt = 0; cnt <OrdersTotal (); cnt ++)

{

OrderSelect (cnt, SELECT_BY_POS, MODE_TRADES); // I select each order

// ONLY PURCHASE ORDERS MADE BY THE ALGORITHM IN THAT PAR

if (OrderType () == OP_SELL && OrderSymbol () == Symbol () && OrderMagicNumber () == MagicNumber)

{

if (OrderTakeProfit () == NewTakeProfit)

{} // if the tp is the maximum, do not change

else

{

OrderModify (OrderTicket (), OrderOpenPrice (), OrderStopLoss (), NewTakeProfit, 0, Green);

}

}

}

 
junior rosado: I understand that the issue is very old, but
  1. Do you really expect that people are still watching this thread after six (6) years?
    Don't resurrect old threads without a very good reason. A lot has changed since Build 600 and Higher. 2014.02.03

  2. Don't Hijack other threads for your off-topic post. Next time, make your own, new, thread.

  3. 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.05.06
              Messages Editor

  4. Please post only in English on this forum. Use the automatic translation tool if needed. Use simple language structure when using mechanical translation.

  5. junior rosado: I just want to use the highest TP in all.
    if (OrderTakeProfit () <= NewTakeProfit)
    {
       NewTakeProfit = OrderTakeProfit ();
    } 
    if (OrderTakeProfit () == NewTakeProfit)
    {} // if the tp is the maximum, do not change
    
    For buy orders you ignore all higher TP values. You don't do that for sell orders.
  6. Doubles are rarely equal. Understand the links in:
              The == operand. - MQL4 programming forum #2 2013.06.07