NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 04-11-2008, 05:58 AM   #1
skynetman
Senior Member
 
Join Date: Mar 2008
Posts: 138
Thanks: 0
Thanked 0 times in 0 posts
Exclamation Why? Strategy going back to past days!

I'm trying a simple strategy: Enter long if above stop, Enter short if under stop.
I can't make it work no matter what, because it uses OLD data in the past without any reason (data that do not even exist.....).
Simple code here with print to output as debug....

Code:
        protected override void OnBarUpdate()
        {
            PrintWithTimeStamp("Bar Update: "+ Close[0]+ "; Bar Time " + ToTime(Time[0]));
            if (Position.MarketPosition == MarketPosition.Flat)
            {
                Print("Flat");                      
                if (Close[0] >= StopLong)
                {
                    Print("Enter long");
                }
                if (Close[0] <= StopShort)
                {
                    Print("Enter Short");
              }}}
New strategy from strategy panel in control center, 10 seconds data series, required bars 1, calculate on bar close.
The problem is with Close[0].
In the output window i should have only the line:
Code:
11/04/2008 13.46.40 Bar Update: 1246,25; Bar Time 134640
Flat
While instead i have A LOT of previous lines referring to older time and days starting with:

Code:
27/03/2008 1.05.10 Bar Update: 1336; Bar Time 10510

Flat
Enter long
27/03/2008 1.05.20 Bar Update: 1336,25; Bar Time 10520

Flat
Enter long
27/03/2008 1.05.40 Bar Update: 1336; Bar Time 10540

Flat
Enter long
27/03/2008 1.05.50 Bar Update: 1336; Bar Time 10550

Flat
Enter long
27/03/2008 1.06.00 Bar Update: 1335,75; Bar Time 10600

Flat
Enter long
27/03/2008 1.06.20 Bar Update: 1336; Bar Time 10620

Flat
Enter long
27/03/2008 1.06.30 Bar Update: 1336; Bar Time 10630

........
........
What is going on?
Could it be that it goes back 43200 bars as market analyzer look back period i set? It should NOT be correlated, but i can't explain in any other way....

help....
Last edited by skynetman; 04-11-2008 at 06:05 AM.
skynetman is offline  
Reply With Quote
Old 04-11-2008, 06:18 AM   #2
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

>> In the output window i should have only the line
Incorrect. Real time strategies on the strategies tab are synced be using historical data which if configured by Tools->Options->Data->Lookback period. Only as that historical data is processed they roll to live data.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 04-11-2008, 06:46 AM   #3
skynetman
Senior Member
 
Join Date: Mar 2008
Posts: 138
Thanks: 0
Thanked 0 times in 0 posts
Default

So what is the solution to have graph loaded with old data AND strategies working only on new data and not old ones?
I add to "Initialize" method a variable with strategy launch time and skip in "bar update" old data?
skynetman is offline  
Reply With Quote
Old 04-11-2008, 06:49 AM   #4
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

You could try adding something like
Code:
if (Historical)
    return;
to your OnBarUpdate method. Note: You then no longer can backtest this strategy since it only will work live.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 04-11-2008, 06:57 AM   #5
skynetman
Senior Member
 
Join Date: Mar 2008
Posts: 138
Thanks: 0
Thanked 0 times in 0 posts
Default

I thought from the code examples that a return in on bar update stopped completely the strategy.....
Now i understand that it simply exit the method without a return variable as it should be in standard programming
Is there a way to stop a strategy completely so that it does not waste any CPU cycle?
Thx.
skynetman is offline  
Reply With Quote
Old 04-11-2008, 06:59 AM   #6
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

>> Is there a way to stop a strategy completely so that it does not waste any CPU cycle?
Not that I'm aware of.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 04-12-2008, 12:45 AM   #7
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

For stopping a strategy please see these reference samples: http://www.ninjatrader-support.com/v...ead.php?t=4804
http://www.ninjatrader-support.com/v...ead.php?t=4084
NinjaTrader_Josh is offline  
Reply With Quote
Old 04-12-2008, 05:34 AM   #8
skynetman
Senior Member
 
Join Date: Mar 2008
Posts: 138
Thanks: 0
Thanked 0 times in 0 posts
Default

Thx Josh i'm already using those examples....
But the strategy is not completely stopped, it is executed anyway and the return in the first IF inside "on bar update" just allows to skip the rest of the code (less cpu intensive but still useless loop).
What i meant was a command to really stop a strategy as clicking on stop in strategy tab

A question: if i set a strategy "on bar close" and as data series i choose "tick", it is less cpu intensive the a false in "on bar close" right? Because it is event driven and not looping as hell, right?

Thx guys....
skynetman is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Days Back field gets larger every day dcobbold123 Charting 1 02-19-2008 11:54 AM
Format data series: Days Back gregiii Charting 1 09-14-2007 11:38 AM
plotting markers on past data x2012 General Programming 2 08-16-2007 06:54 AM
Last and past trades MrBaffalo Strategy Development 1 04-17-2007 01:44 AM
Stop Loss Orders activated by number of trades past stop level DoveforUsAll Suggestions And Feedback 1 02-08-2006 01:19 AM


All times are GMT -6. The time now is 10:07 PM.