PDA

View Full Version : The focus of the chart changes after reloading ninjascript


clearpicks
04-24-2008, 12:44 PM
Hello,

On intraday chart, after I reload ninjascript by pressing "F5", the last bar shown on chart changes to the last bar in historical database before I start NT. For example, if I keep NT running since 10:00 this morning. Now if I reload ninjascripts, the last bar to the right on the chart becomes the bar with time stamp 10:00. I have to click the black arrow at the right top corner to scroll the chart to the left and bring back those bars built in realtime. Is this a bug?


- Clearpicks

NinjaTrader_Eamon
04-24-2008, 01:51 PM
Hello,

On intraday chart, after I reload ninjascript by pressing "F5", the last bar shown on chart changes to the last bar in historical database before I start NT. For example, if I keep NT running since 10:00 this morning. Now if I reload ninjascripts, the last bar to the right on the chart becomes the bar with time stamp 10:00. I have to click the black arrow at the right top corner to scroll the chart to the left and bring back those bars built in realtime. Is this a bug?


- Clearpicks

Hi Clearpicks,

I am going to test this on my end. However, it might take a little while. Do I need to run the NinjaScript strategies the entire time my chart is open?

clearpicks
04-24-2008, 01:55 PM
No. Running on 1min for about 15min so that enough realtime bars have been build to fill the margin on right side. You may try sub-minute (5 second or tick) chart to get test done faster, but I never tried. I tried 5min chart only.


- Clearpicks



Hi Clearpicks,

I am going to test this on my end. However, it might take a little while. Do I need to run the NinjaScript strategies the entire time my chart is open?

NinjaTrader_Eamon
04-24-2008, 02:08 PM
No. Running on 1min for about 15min so that enough realtime bars have been build to fill the margin on right side. You may try sub-minute (5 second or tick) chart to get test done faster, but I never tried. I tried 5min chart only.


- Clearpicks

Hello,

What datafeed are you connected to?

clearpicks
04-24-2008, 02:12 PM
InteractiveBrokers.

NinjaTrader_Eamon
04-25-2008, 08:08 AM
InteractiveBrokers.

Hi Clearpicks,

I tested this on my end and was unable to reproduce. Could you send in a note to my attention to Support at NinjaTrader dot com.

clearpicks
04-25-2008, 09:55 AM
I can not reproduce it. I will try it during the weekend.
It might be caused the some texts drawn on chart disappear when reload ninjascript so that I mistakenly think the focus has been changed.
Anyway either the focus was changed or drawtext() was not executed. It might have something to do this function I stole from sone post. When the chart is scrolled to the right for a few bars (exceeding the chart margin?), reloading ninjascript may cause LastBarOnChart never set to draw so that my texts are not drawn. However scrolling the chart to the left for even one bar would make the texts appear again. Anyway something is wrong here. I will post my test script next week.

privatebool LastBarOnChart
{
get
{
if ( ! CalculateOnBarClose && CurrentBar == Bars.Count - 1 )
returntrue;
elseif ( CalculateOnBarClose && CurrentBar == Bars.Count - 2 )
returntrue;
else
returnfalse;
}
}

clearpicks
04-25-2008, 07:54 PM
Hello,

I just found out why I mistakenly thought the focus of the chart is changed.

In my script, at the biginning of the last bar, some texts are drawn on the chart. If I scroll the chart to the right for a few bars, say 20 bars and reload the ninjascript. Then the function OnBarUpdate() is executed for every bar but the script pauses at the bar with index (Count - 20), which is different as I expected. I expected the script would run on every bar no matter it is out side of the right margin of the chart or not.

Attched is a script to demonstrate this behavior. Just apply this script to any chart and scroll to the right for a few bar and press "F5", watch the output, and scroll the chart to the LEFT untill the last trading bar shows up, check the output window again.

Where can I find the document on such behavior of NinjaScript? Maybe I have not spent enough time on learning details of Ninjascript.

- Clearpicks

clearpicks
04-25-2008, 07:56 PM
the script is attached.

NinjaTrader_Josh
04-26-2008, 03:21 AM
This is normal behavior. You will simply need to run your scripts at the last current bar to start. You can then proceed to scroll backwards or forwards after the strategy has started.