ATI user
10-23-2006, 04:20 AM
In anticipation of NT6 chart trading being available in the next few weeks, I am converting my efs strategies over to NinjaScript.
I strikes me that I am not the only one that will be doing this (from somenon-C# code)and that perhaps asking some very basic questions in this thread will save me and others many hours of searching for answers which are blatantly obvious to current NinjaScript users/experts.
While javascript and ninjascript are bascially very similar, there are some simple differences which are annoying/time-consuming to research. For instance, some common efs code:
Question 1:Printing a variable on a chart.
efs code: drawText(Close(0), AboveBar2); prints the last closing price two ticksizes above the current bar....drawText("Sell"....prints the string "Sell"....
nt code: DrawText("tag", Close[0], 0, High[0]+2*TickSize, Color.Yellow); results in errors including "can not convert from double to string"
Question 2: Checking current bar state.
efs code: prior to conditional.... nState = getBarState();....later in code if(nState == BARSTATE_NEWBAR).....is truefor first tick of new bar
nt code: temporary solution thanks to Ray:
We have logic in an NT6 Strategy bool FirsTickOfBar, there is nothing in NT5.
What you could do, is calculate yourself.
For TickChart use the Bars.TickCount property
private bool firstTick = true;
private int lastCount = 0;
if (Bars.TickCount< lastCount)
firstTick = true;
lastCount = Bars.TickCount;
for time chart use
private bool firstTick = false;
private DateTime currentTime = DateTime.MinValue;
if (Time[0].Minute > currentTime.Minute)
{
firstTick = true;
currentTime = Time[0];
}
else
firstTick = false;
Hope this helps!
Ray
I strikes me that I am not the only one that will be doing this (from somenon-C# code)and that perhaps asking some very basic questions in this thread will save me and others many hours of searching for answers which are blatantly obvious to current NinjaScript users/experts.
While javascript and ninjascript are bascially very similar, there are some simple differences which are annoying/time-consuming to research. For instance, some common efs code:
Question 1:Printing a variable on a chart.
efs code: drawText(Close(0), AboveBar2); prints the last closing price two ticksizes above the current bar....drawText("Sell"....prints the string "Sell"....
nt code: DrawText("tag", Close[0], 0, High[0]+2*TickSize, Color.Yellow); results in errors including "can not convert from double to string"
Question 2: Checking current bar state.
efs code: prior to conditional.... nState = getBarState();....later in code if(nState == BARSTATE_NEWBAR).....is truefor first tick of new bar
nt code: temporary solution thanks to Ray:
We have logic in an NT6 Strategy bool FirsTickOfBar, there is nothing in NT5.
What you could do, is calculate yourself.
For TickChart use the Bars.TickCount property
private bool firstTick = true;
private int lastCount = 0;
if (Bars.TickCount< lastCount)
firstTick = true;
lastCount = Bars.TickCount;
for time chart use
private bool firstTick = false;
private DateTime currentTime = DateTime.MinValue;
if (Time[0].Minute > currentTime.Minute)
{
firstTick = true;
currentTime = Time[0];
}
else
firstTick = false;
Hope this helps!
Ray