Select the low or high of previous pending order's bar!!!!

 

hi.... i need help in ea......i had an order placed in a bar and it is still pending and many bars have passed without trading, now i want to select the low or high of that pending order's bar....how to do it ??...please some one tell me the code snippet for it???

 

First you need to get the order ticket . . .

Then using the Order Ticket you get the time the order was placed, then find the bar you want for the Timeframe you want

The once you have the BarShift value you can look up the low or high for that BarShift.

For example . . .

I haven't tested this . . . .

for(int OrderPosition = OrdersTotal()-1; OrderPosition >= 0 ; OrderPosition--) 
   if ( OrderSelect(OrderPosition, SELECT_BY_POS, MODE_TRADES) &&  
        OrderMagicNumber() == YourMagicNo && 
        OrderType() >= OP_BUYLIMIT && OrderType() <= OP_SELLSTOP &&
        OrderSymbol() == YourSymbol )
      {
       double BarHigh = iHigh(YourSymbol, YourTimeframe, iBarShift( YourSymbol, YourTimeframe, OrderOpenTime() ) );  
       double BarLow  = iLow(YourSymbol, YourTimeframe, iBarShift( YourSymbol, YourTimeframe, OrderOpenTime() ) ); 
      }
 
Or if you're only running on the current chart
for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
    OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
&&  OrderMagicNumber()  == magic.number             // my magic number
&&  OrderSymbol()       == Symbol()                 // and my pair.
&&  OrderType()          > OP_SELL                  // Only pending orders
){
    int    iOOT    = iBarShift(NULL,0, OrderOpenTime());
    double BarHigh = High[iOOT],
           BarLow  =  Low[iOOT];
}
 
RaptorUK:

First you need to get the order ticket . . .

Then using the Order Ticket you get the time the order was placed, then find the bar you want for the Timeframe you want

The once you have the BarShift value you can look up the low or high for that BarShift.

For example . . .

I haven't tested this . . . .


thanks mate......i will check it when the market opens.....anyways..thanks for answering quick......
 
WHRoeder:
Or if you're only running on the current chart

oh...i get it.....thanks.....i will update u when i try it....thanks again for ur reply....
 
kmnatarajan:

thanks mate......i will check it when the market opens.....anyways..thanks for answering quick......
If you are just using one symbol you don't need to wait . . use the Strategy Tester.
 

thanks dude.....i never knew that there was such a thing known as strategy tester,...only after u have said, i did that....and voila!!!.....it is working properly...!!...thanks a lot....

 
Glad to hear you are making progress :-)