thanks for answering Gumrai.
I tried several times as you said, but could not.
//GLOBAL VAR int modify; int ticketbuy,ticketshell; int ticket; //FIM GLOBAL VAR if(TotalOrdersCount()<2) { ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,0,0,0,NULL,MagicNumber,0,Blue); ticketbuy = OrderTicket(); ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,0,0,0,NULL,MagicNumber,0,Red); ticketbuy2 = OrderTicket(); } int cnt, total=OrdersTotal(); for(cnt=0;cnt<total;cnt++) { if (OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==true) if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber) { if(OrderType()==OP_BUY) { double stnewprice = OrderOpenPrice(); if(stnewprice< stnewprice+20*MyPoint) { modify = OrderModify(OrderTicket(),OrderOpenPrice(),stnewprice+20*MyPoint,0,0,clrLightGreen); } } } } if(modify==1) int close = OrderClose(ticketbuy2,Lots,Ask,0,0); }
THANKS FOR HELPING ME
int modify;
You should get into the habit of declaring variables correctly. modify is used as a bool, so should be declared as a bool.
Also, I don't see that it is necessary to declare it Globally as once it is set to true, it will remain true during subsequent ticks. This could result in trades being closed as soon as they are opened.
ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,0,0,0,NULL,MagicNumber,0,Blue); ticketbuy = OrderTicket(); ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,0,0,0,NULL,MagicNumber,0,Red); ticketbuy2 = OrderTicket();
No order has been selected, so OrderTicket() should not be used here.
ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,0,0,0,NULL,MagicNumber,0,Blue); if(ticket>0) ticketbuy = ticket; ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,0,0,0,NULL,MagicNumber,0,Red); if(ticket>0) ticketbuy2 = ticket;
if(modify==1) int close = OrderClose(ticketbuy2,Lots,Ask,0,0);
A Buy is closed at Bid, not Ask
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
People thanks very much for the help.
you help a lot and i am very grateful for the help in my learning.
In my studies, I'm trying to terminate an order if another order is closed.
Example SHELL:
if Order(1) OrderOpenPrice()-20PIPS then Order(2) CLOSE.
I can not imagine how to program!
please, I'm very doubts to solve.