Hello,
you could 'tie' the two orders together by using a "magic number" in the order comments.
How you generate the number (or string, or whatever) - is up to you
but if you open two orders with say 'Order Set 0001'
it would be trivial to parse the open orders, find the one you are interested in, parse all other orders and compare the comments - then use that to close both orders.
hope this helps
Great idea. I will work on that. I'm pretty new at programing, so all the ideas I can get really help.
Can you help me understand the { } and what they do?
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
How do you tie a new order to an older one so that when the collective profits equeal zero, you can close them both at the same time?
For example: an order is placed to go long, but the price starts falling. At half way to my stop loss, I would like to place a hedge short order. I double the lot size, or maybe even triple. But when the profits of the 2 orders zero out each other, then I want to close them both at the same time.
Here is the code I have for checking to see if the orders are halfway to stop loss, and the corresponding order where I take the original order's take profit, and make it the stop loss and visa versa.
Now how do I tie them together to do what I want to do as stated above?
Thanks anyone.
//------------------------------- if there are open orders, lets see if they need Hedged.
for(cnt=0;cnt<total;cnt++) //If we have opened orders
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()==OP_BUY) // and if it's a long trade should it be hedged?
{
if(Ask < (OrderOpenPrice()-(Stoploss*0.0001*0.5))) //Hedge
{
ticket=OrderSend(Symbol(),OP_SELL,OrderLots()*Hdg.Lots,Bid,3,OrderTakeProfit(),OrderStopLoss(),"",12345,0,Red);
return(0); // exit
}
}
if(OrderType()==OP_SELL) //If it's a short order should it be hedged?
{
if(Bid > (OrderOpenPrice()+(Stoploss*0.0001*0.5))) //Hedge
{
ticket=OrderSend(Symbol(),OP_BUY,OrderLots()*Hdg.Lots,Ask,3,OrderTakeProfit(),OrderStopLoss(),"",12345,0,Green);
return(0);
}
}