Am I missing something, or is the return from Bars() in a strategy supposed to be 0? I wrote a strategy in c++ and in GetSingleTick() the first thing I do is check that the number of bars is greater than an input so I am sure I can pull the past prices I need for some calculations. When debugging I see that Bars() is always 0. Is there a better way to test for this? Here is the code:
If(Bars() < TotallBars)
{
return;
}
TotalBars shows the correct value but Bars() is always 0, so execution never gets past this if statement. Any ideas? Should use a StartTime variable instead?
I should say I have tested this in the quick test and not in the normal test mode.
edoughig wrote:Am I missing something, or is the return from Bars() in a strategy supposed to be 0? I wrote a strategy in c++ and in GetSingleTick() the first thing I do is check that the number of bars is greater than an input so I am sure I can pull the past prices I need for some calculations. When debugging I see that Bars() is always 0. Is there a better way to test for this? Here is the code:
If(Bars() < TotallBars) { return; }
TotalBars shows the correct value but Bars() is always 0, so execution never gets past this if statement. Any ideas? Should use a StartTime variable instead?
I should say I have tested this in the quick test and not in the normal test mode.
Based on most of the strategies in delphi:
=== Most like you did not add this === // set currency and timeframe SetCurrencyAndTimeframe(Symbol(), TimeFrame());
edoughig wrote:Am I missing something, or is the return from Bars() in a strategy supposed to be 0? I wrote a strategy in c++ and in GetSingleTick() the first thing I do is check that the number of bars is greater than an input so I am sure I can pull the past prices I need for some calculations. When debugging I see that Bars() is always 0. Is there a better way to test for this? Here is the code:
If(Bars() < TotallBars) { return; }
TotalBars shows the correct value but Bars() is always 0, so execution never gets past this if statement. Any ideas? Should use a StartTime variable instead?
I should say I have tested this in the quick test and not in the normal test mode.
Based on most of the strategies in delphi:
=== Most like you did not add this === // set currency and timeframe SetCurrencyAndTimeframe(Symbol(), TimeFrame());
If(Bars() < TotallBars) { return; }
Yeah, SetCurrencyAndTimeframe(...) is in there, but you are right, that was the issue. Bars() is always 0 BEFORE that method is called. After, all is good.
Thanks very much for confirming my experiences with the API.
In the end i was able to achieve what I needed to porting my metatrader code over. Apart from the language difference there was very little that changed