Download MetaTrader 5
To add comments, please log in or register
Publish your programs in the Market. Make money with your knowledge!
amando
389
amando 2014.08.17 17:20 

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 

whroeder1
13602
whroeder1 2014.08.17 18:04  
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?
amando
389
amando 2014.08.17 18:36  

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

amando
389
amando 2014.08.17 19:02  

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

/
To add comments, please log in or register