Download MetaTrader 5

Query Order History within Indicator in Strategy Tester

To add comments, please log in or register
James Parker
1056
James Parker  

I'm writing an indicator that uses OrdersHistoryTotal() in the calculation. I'd like to test it in strategy tester but it's not working. I've attached the indicator to the chart window I am running the test on and the Print statement in the code below returns zero every time.

The function works fine on a live chart. But in strategy tester I just get zeros. Should this work? Am I misunderstanding how indicators work in the strategy tester?

This is my first time writing an indicator...

Thanks in advance for any help! 

 

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{                

Print("OrdersHistoryTotal = ",OrdersHistoryTotal());

return(rates_total);
}
Keith Watford
Moderator
8293
Keith Watford  
The strategy tester has no history until it has made trades during the current test. As you are testing an indicator, trades are not possible.
Fernando Carreiro
3916
Fernando Carreiro  
James Parker:

I'm writing an indicator that uses OrdersHistoryTotal() in the calculation. I'd like to test it in strategy tester but it's not working. I've attached the indicator to the chart window I am running the test on and the Print statement in the code below returns zero every time.

The function works fine on a live chart. But in strategy tester I just get zeros. Should this work? Am I misunderstanding how indicators work in the strategy tester?

When using the "Expert" mode of testing, the Indicator dropped on the Chart that makes use of the "Orders" information, such as the OrdersHistoryTotal, does not reflect the Orders of the EA being tested, but instead the Orders of the "live" account from your broker, be that a "demo" account or a "real" account. In essence, you will not be able to back-test such indicators in the Strategy Tester, not even in "Indicator" mode - only in live forward testing on a demo account, for example.
James Parker
1056
James Parker  
Thanks. I thought this might be the case. I'll have to test it with some trades on a demo accounts.
To add comments, please log in or register