Rather than update the score and print just one updated number, the output is showing three different scores one for each time frame. When added together they are correct but why are they printing to the output window separately?
I want one updated score that updates at each tick on all time frames at once.
code below
-------------------------------------------------------------------------------------------------------------------
namespace NinjaTrader.Strategy
{
/// <summary>
/// for testing strategy componants
/// </summary>
[Description("for testing strategy componants")]
public class TESTSTRATEGY2 : Strategy
{
#region Variables
//These are the amounts to add or subtract to score
int HourlyScore = 1; int TenMinScore = 2; int TwoMinScore = 6;
#endregion
protected override void Initialize()
{
CalculateOnBarClose = false;
Add(PeriodType.Minute, 10); //adding 10 minute data
Add(PeriodType.Minute, 60); //adding 60 minute data
}
protected override void OnBarUpdate()
{
ClearOutputWindow();
if (CurrentBars[0] <= BarsRequired ||
CurrentBars[1] <= BarsRequired ||
CurrentBars[2] <= BarsRequired)
return;
//reset score on each bar update
int Score = 0;
//------------------------------------------------------------------------------------
//for each BarsInProgress
for(int x = 0; x <= 2; x++)
{
if(BarsInProgress == x)
{
bool MaUp; //define moving average up variable
string LongOrShort; //define Long or short string
// determines if 8ema is above the 15sma
if (EMA(8)[0] > SMA(25)[0])
{
MaUp = true;
}
else
MaUp = false;
if(MaUp)
{
LongOrShort = "SHORT"; //set short bias
switch(x) //score for each time frame
{
case 2:
Score = Score + HourlyScore;
break;
case 1:
Score = Score + TenMinScore;
break;
case 0:
Score = Score + TwoMinScore;
break;
}
}
else
if(MaUp == false)
{
LongOrShort = "LONG"; //set long bias
switch(x) //score for each time frame
{
case 2:
Score = Score - HourlyScore;
break;
case 1:
Score = Score - TenMinScore;
break;
case 0:
Score = Score - TwoMinScore;
break;
}
}
else
LongOrShort = "NOTRADE"; //set no trade bias
}
}
Print(ToTime(Time[0])); //print time of score
Print("Score is " + Score); //print score
}
#region Properties
#endregion
}
}

Comment