Get last trade from current bar

 

If I want to get information about last knowing and really executed trade (for example S&P emini) in the current bar. Is "Close[0]" the right way?

If i use Bid+Ask/2 i could get the average price. But will "Close[0]" work when I simulate and doing tests?

In simulation mode I am afraid of getting the future close price for the current bar (this happens in other trading programs) and this will mess up my tests.

 
Close[0] = Bid
 

Get last trade from current bar: are you looking for last trade info or last price info?

If I want to get information about last knowing and really executed trade (for example S&P emini) in the current bar. Is "Close[0]" the right way? Mql4 data is assumed to be Bid prices. The back-tester simulates fixed spreads to create the Ask price. OrderClosePrice() for trades, gives the last know close price example: for Sell Orders it'll be the Ask price. The Ask price is generated by adding the spreads to the Bid. I don't know anything about emini's.

If i use Bid+Ask/2 i could get the average price. But will "Close[0]" work when I simulate and doing tests? Close[0] will give you the Last Known Bid on Bar[0] for test symbol, and current Time-Frame Only. Becomes a mess when looking at other Symbols and/or other time-frames.The truth is, if your broker have variable spreads, there's no way to simulate what the average price was. Everything is an estimate even the data itself.

In simulation mode I am afraid of getting the future close price for the current bar (this happens in other trading programs) and this will mess up my tests. Don't use bar[0] information (except maybe open[0]) for other Time-Frames or Symbols.

 
RaptorUK:
Close[0] = Bid

Thanks!
 
ubzen:

Get last trade from current bar: are you looking for last trade info or last price info?

If I want to get information about last knowing and really executed trade (for example S&P emini) in the current bar. Is "Close[0]" the right way? Mql4 data is assumed to be Bid prices. The back-tester simulates fixed spreads to create the Ask price. OrderClosePrice() for trades, gives the last know close price example: for Sell Orders it'll be the Ask price. The Ask price is generated by adding the spreads to the Bid. I don't know anything about emini's.

If i use Bid+Ask/2 i could get the average price. But will "Close[0]" work when I simulate and doing tests? Close[0] will give you the Last Known Bid on Bar[0] for test symbol, and current Time-Frame Only. Becomes a mess when looking at other Symbols and/or other time-frames.The truth is, if your broker have variable spreads, there's no way to simulate what the average price was. Everything is an estimate even the data itself.

In simulation mode I am afraid of getting the future close price for the current bar (this happens in other trading programs) and this will mess up my tests. Don't use bar[0] information (except maybe open[0]) for other Time-Frames or Symbols.


Thanks for the info!
 
IntraTrade:
If I want to get information about last knowing and really executed trade...
    for(iPos=OrdersHistoryTotal()-1; iPos >= 0 ; iPos--) if (
        OrderSelect(iPos, SELECT_BY_POS, MODE_HISTORY)          // Only orders w/
    &&  OrderMagicNumber() == magic.number                      // my magic number
    &&  OrderSymbol()      == chart.symbol                      // and my pair.
    &&  OrderType()        <= OP_SELL// Avoid cr/bal forum.mql4.com/32363#325360
        ){
        Print("Last order #", OrderTicket(),
              " was closed on ", TimeToStr( OrderClosePrice() ),
              " @ ", PriceToStr( OrderClosePrice() )
             );
        break;
    }
Reason: