![]() |
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Mar 2008
Posts: 138
Thanks: 0
Thanked 0 times in 0 posts
|
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");
}}}
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 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 ........ ........ 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.
|
|
|
|
|
|
#2 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
>> 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.
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Mar 2008
Posts: 138
Thanks: 0
Thanked 0 times in 0 posts
|
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? |
|
|
|
|
|
#4 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
You could try adding something like
Code:
if (Historical)
return;
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Mar 2008
Posts: 138
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#6 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
>> Is there a way to stop a strategy completely so that it does not waste any CPU cycle?
Not that I'm aware of.
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#8 |
|
Senior Member
Join Date: Mar 2008
Posts: 138
Thanks: 0
Thanked 0 times in 0 posts
|
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.... |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |