okay... this is melting my brain, there has to be a better way to do this?!
I want to hedge trades. When I place the hedge, I will put the original trade's ticket number along with "Hedge " in the hedge's comment. All I want to do is be able to select either the hedge OR the original trade, and determine if it is hedged or not using orderselect functions rather than long lots == short lots etc.
I can select the hedge using OrderSelect and find the OrderTicket() of the trade that it hedged quite simply buy just looking at the hedge's OrderComment(),
but what i'd really like to do is be able to select any trade and determine if it is hedged. The original trades contain no information about the hedges so I think I need to create a nested loop that selects a trade then loops through again comparing parameters with it's own but i'm not sure how to do that.
to maybe help clarify what I want to do, here's a demo of what I can't do because using a single loop means that you cant compare to other trades, but really, if you can think of a better way to do this then I am definitely all ears!!
for the code example, this is for when both trades are active so "you can search all trades simultaneously" would be a lovely result that I can't solve
I want to hedge trades. When I place the hedge, I will put the original trade's ticket number along with "Hedge " in the hedge's comment. All I want to do is be able to select either the hedge OR the original trade, and determine if it is hedged or not using orderselect functions rather than long lots == short lots etc.
I can select the hedge using OrderSelect and find the OrderTicket() of the trade that it hedged quite simply buy just looking at the hedge's OrderComment(),
but what i'd really like to do is be able to select any trade and determine if it is hedged. The original trades contain no information about the hedges so I think I need to create a nested loop that selects a trade then loops through again comparing parameters with it's own but i'm not sure how to do that.
to maybe help clarify what I want to do, here's a demo of what I can't do because using a single loop means that you cant compare to other trades, but really, if you can think of a better way to do this then I am definitely all ears!!
for the code example, this is for when both trades are active so "you can search all trades simultaneously" would be a lovely result that I can't solve
Inserted Code
int j=OrdersTotal()-1; for( int i=j;i>=0;i--) { if((OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true) && (OrderMagicNumber()==MagicNumber) && (OrderSymbol()==Pair)){ //order select if(StringFind(OrderComment(),"Hedge")>=0) { int ScalpTicket = StrToNumber(OrderComment());} //StrToNumber is a function removes all non-numerical characters if((StringFind(OrderComment(),"Hedge")>=0) &&(StringFind(OrderTicket(),IntegerToString(ScalpTicket))>=0)){ Print("you can search all trades simultaneously");} if((StringFind(OrderComment(),"Hedge")>=0) &&(StringFind(OrderTicket(),IntegerToString(ScalpTicket))>=0)){ Print("found hedge but not scalp");} if((StringFind(OrderComment(),"Hedge")<0) &&(StringFind(OrderTicket(),IntegerToString(ScalpTicket))>=0)){ Print("found scalp but not hedge");} }//end order select }//end of loop