Bars() in strategy is always 0

How to create strategies and indicators
Message
Author
edoughig
Posts: 7
Joined: Wed May 15, 2013 4:12 pm

Bars() in strategy is always 0

#1 Postby edoughig » Sat May 18, 2013 3:54 pm

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.

KelvinHand
Posts: 103
Joined: Sun Jan 02, 2011 6:05 pm

Re: Bars() in strategy is always 0

#2 Postby KelvinHand » Sat May 18, 2013 8:49 pm

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;
}

edoughig
Posts: 7
Joined: Wed May 15, 2013 4:12 pm

Re: Bars() in strategy is always 0

#3 Postby edoughig » Sun May 19, 2013 8:41 am

KelvinHand wrote:
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.

Thank you for your reply and help.

sajjad123
Posts: 1
Joined: Mon Dec 08, 2014 3:05 am

Re: Bars() in strategy is always 0

#4 Postby sajjad123 » Mon Dec 08, 2014 3:27 am

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




You can get score highest marks in Braindumps exam 1z0-058 and test king which are prepared by http:hsbc.edu certified professionals, stevenson & ccna.


Return to “FT API”

Who is online

Users browsing this forum: No registered users and 20 guests