Hello,
I want to create a program where I place a Buy and Sell Stop order. When one gets filled, I want to cancel the other order. How do I do that? I tried using Totalorders but that tells me the total pending and open order. I also tried to use
if (OrderSelect(ticketsell,SELECT_BY_TICKET)==true) but that is for pending and open orders too.
-Manesh
profitvalue= highvalue +0.0010;
if ((highvalue - lowvalue) > 60) stopvalue=highvalue - 60;
else stopvalue= lowvalue;
ticketbuy=OrderSend(Symbol(),OP_BUYSTOP,1,highvalue,0,stopvalue,profitvalue,"buy order",16384,0,Green);
//sell
profitvalue= lowvalue - 0.0012;
if ((highvalue-0.0005 - lowvalue) > 60) stopvalue=lowvalue + 60;
else stopvalue= highvalue;
ticketsell=OrderSend(Symbol(),OP_SELLSTOP,1,lowvalue,0,stopvalue,profitvalue,"Sell order",16384,0,Green);
try this
if (OrderSelect(ticketsell,SELECT_BY_TICKET)==true && OrderType()< 1) // eliminates pending stop and limit orders.
HTH
Keith
try this
if (OrderSelect(ticketsell,SELECT_BY_TICKET)==true && OrderType()< 1) // eliminates pending stop and limit orders.
HTH
Keith
Hello,
Unfortunately that did not work. Here is what I have now.... Also, I have included a snapshot of the strategy tester where a buy/sell orders are entered. When the sell is filled, it should cancel the buy but it still says active even after the sell order is closed for a profit.
ticketbuy=OrderSend(Symbol(),OP_BUYSTOP,1,highvalue,0,stopvalue,profitvalue,"buy order",16384,0,Green);
//sell
profitvalue= lowvalue - 0.0012;
if ((highvalue-0.0005 - lowvalue) > 60) stopvalue=lowvalue + 60;
else stopvalue= highvalue;
ticketsell=OrderSend(Symbol(),OP_SELLSTOP,1,lowvalue,0,stopvalue,profitvalue,"Sell order",16384,0,Green);
if (OrderSelect(ticketsell,SELECT_BY_TICKET)==true && OrderType()< 1) // eliminates pending stop and limit orders.
{
OrderDelete(ticketbuy);
Print("Open",OrderOpenTime());
}
Hello,
Unfortunately that did not work. Here is what I have now.... Also, I have included a snapshot of the strategy tester where a buy/sell orders are entered. When the sell is filled, it should cancel the buy but it still says active even after the sell order is closed for a profit.
ticketbuy=OrderSend(Symbol(),OP_BUYSTOP,1,highvalue,0,stopvalue,profitvalue,"buy order",16384,0,Green);
//sell
profitvalue= lowvalue - 0.0012;
if ((highvalue-0.0005 - lowvalue) > 60) stopvalue=lowvalue + 60;
else stopvalue= highvalue;
ticketsell=OrderSend(Symbol(),OP_SELLSTOP,1,lowvalue,0,stopvalue,profitvalue,"Sell order",16384,0,Green);
if (OrderSelect(ticketsell,SELECT_BY_TICKET)==true && OrderType()< 1) // eliminates pending stop and limit orders.
{
OrderDelete(ticketbuy);
Print("Open",OrderOpenTime());
}
Beats me, do you get any error messages in the experts log?
Keith
not quite see what requirement is but for the heck of it - might find something of use below...
#define BUY_MAGIC 16384 #define SELL_MAGIC 26384 ticketbuy=OrderSend(Symbol(),OP_BUYSTOP,1,highvalue,0,stopvalue,profitvalue,"buy order",BUY_MAGIC,0,Green); //sell profitvalue= lowvalue - 0.0012; if ((highvalue-0.0005 - lowvalue) > 60) stopvalue=lowvalue + 60; else stopvalue= highvalue; ticketsell=OrderSend(Symbol(),OP_SELLSTOP,1,lowvalue,0,stopvalue,profitvalue,"Sell order",SELL_MAGIC,0,Green); //When the sell is filled, it should cancel the buy // if(OrderSelect(ticketbuy,SELECT_BY_TICKET)) { if(OrderMagicNumber()==BUY_MAGIC) { if(OrderType()==OP_BUYSTOP) OrderDelete(ticketbuy); /*else //maybe you use this part IF any potential for buy pending to become buy market order... if(OrderType()==OP_BUY) OrderClose(ticketbuy,OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),/*PUT SLIPPAGE VALUE HERE*/,Violet); */ Print("Open",OrderOpenTime()); } }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I want to create a program where I place a Buy and Sell Stop order. When one gets filled, I want to cancel the other order. How do I do that? I tried using Totalorders but that tells me the total pending and open order. I also tried to use
if (OrderSelect(ticketsell,SELECT_BY_TICKET)==true) but that is for pending and open orders too.
-Manesh
profitvalue= highvalue +0.0010;
if ((highvalue - lowvalue) > 60) stopvalue=highvalue - 60;
else stopvalue= lowvalue;
ticketbuy=OrderSend(Symbol(),OP_BUYSTOP,1,highvalue,0,stopvalue,profitvalue,"buy order",16384,0,Green);
//sell
profitvalue= lowvalue - 0.0012;
if ((highvalue-0.0005 - lowvalue) > 60) stopvalue=lowvalue + 60;
else stopvalue= highvalue;
ticketsell=OrderSend(Symbol(),OP_SELLSTOP,1,lowvalue,0,stopvalue,profitvalue,"Sell order",16384,0,Green);