View Full Version : BackColor in Strategy
NinjaTrader_Josh
05-31-2007, 03:19 AM
I'm having a bit of weird behavior in my strategy regarding backcolors. I have my strategy set to paint the background a certain color if the close in a certain time period is above/below the open in another time period. The painting works fine if my strategy is left with that alone, but the moment I add other indicators from within my strategy the painting of my main time frame disappears. I have some indicators with painting on separate panels that continue to paint fine. Just the main time frame's painting based on the close/open on multi-time frame disappears.
This part has me confused. If I comment out the initialization of my indicators and run the backtest the main time painting shows up. Immediately afterwards if I uncomment my indicators and click on my instrument name from the left bar everything works perfectly. The moment I refresh the chart or rebacktest the main time frame painting disappears again.
Any ideas as to why this is happening?
NinjaTrader_Dierk
05-31-2007, 04:39 AM
There are some cross dependencies as it goes to back coloring a chart. I suggest either setting the back color by strategy or by indicator but not by both.
NinjaTrader_Josh
05-31-2007, 09:24 AM
Hmm. I tried removing my indicators that have back coloring properties to see if that would help. No dice. I then stripped the strategy down to the bare-bones and added a simple SMA(5) indicator. When I backtest the first time everything works, but the moment I refresh or rebacktest the painting is gone. The painting stays gone until I repoen Strategy Analyzer or until I do some changes on the strategy code and recompile. Perhaps whats causing this isn't a cross dependency issue?
I don't have this issue with my non-multitime framed strategies. Maybe it is something to do with the strategy not reevaluating the different time frame's data when I refresh?
Here's my bare-bones strategy code. I'm pretty sure there are no mistakes in its coding.
protected override void Initialize()
{
Add(PeriodType.Minute, 5);
Add(PeriodType.Minute, 60);
Add(SMA(5));
CalculateOnBarClose = true;
}
protected override void OnBarUpdate()
{
double Diff1 = Closes[1][0] - Opens[1][0];
double Diff2 = Closes[2][0] - Opens[2][0];
if ( Diff1 > 0 && Diff2 > 0)
{
BackColor = Color.PaleGreen;
}
else if ( Diff1 < 0 && Diff2 < 0)
{
BackColor = Color.Pink;
}
else
{
BackColor = Color.Gold;
}
}
NinjaTrader_Dierk
05-31-2007, 09:27 AM
Please attach your (simple-as-possible) strategy to your post so I could try here. Thanks.
NinjaTrader_Josh
05-31-2007, 10:17 AM
Here you go. Thanks for the help Dierk.
I'm running this on a 1 minute chart and my other two periods are 5 minutes and 60 minutes.
From what I can tell, if no indicators are called from the strategy via Add() the refreshing/re-backtesting doesn't kill the background colors. I've added some debugging print commands and noticed that hitting F5 to refresh doesn't result in the strategy re-running, but re-backtesting does.
I also noticed that if you add an indicator after running the backtest, the background disappears when you rerun the strategy.
Edit: I think I might have spoken too early on the not having issues with non-multi time framed strategies. I just looked back on the coding and the painting was done via indicators so they don't count. I've included an even simpler strategy (BackColorTest.cs) that shows the painting problems from within a strategy. I'm thinking maybe its a bug in the Strategy Analyzer.
NinjaTrader_Dierk
05-31-2007, 11:44 AM
Ok, let's make sure your observations match mine:
- pull up new SA (important!), backtest TRO no SMA added, F5 -> no problem
- pull up new SA (important!), backtest TRO with SMA added, F5 -> won't work
- pull up new SA (important!), backtest BackColorTest no SMA added, F5 -> no problem
- pull up new SA (important!), backtest BackColorTest with SMA added, F5 -> won't work
Correct?
NinjaTrader_Josh
05-31-2007, 12:08 PM
Yup. That is exactly what I'm seeing on my end.
NinjaTrader_Dierk
05-31-2007, 12:12 PM
Thanks for confirmation.
The problem is that internally there really is no strategy running on the chart component on the performance manager (opposed to a stand alone chart). We will remove the refresh NS option (F5) on strategy analyzer with next update.
NinjaTrader_Josh
05-31-2007, 12:18 PM
What about these observations?
-new SA, backtest BackColorTest with SMA added -> works
-new SA, backtest BackColorTest with SMA added, rebacktest -> problem
NinjaTrader_Dierk
05-31-2007, 12:46 PM
This is a bug which will be fixed with next update. Thanks for bringing this up.
NinjaTrader_Josh
05-31-2007, 02:16 PM
Great. Hopefully in the next release we can have the ability to have multi-time framed indicators so I can push these painting routines into an indicator too. Thanks Dierk.
NinjaTrader_Dierk
05-31-2007, 02:17 PM
Sorry, no. Multi-time frame indicators won't come with next release. There is no ETA available yet.