Should GomCDSMA be a regular indicator and not a GomRecoderIndicator?
I have tried to modify the GomCDSMA indicator to be plotted in different colors if it's rising or falling. I used the code from an EMA with up/down colors that I have created. I basically substituted EMA for GomCDSMA and also turned it into a GomRecorderIndicator, GomInitialize() etc. (Do I need to do that?) It works great with historic data but with live data it sometimes gets the colors mixed up, however, the values are always correct (the same as GomCDSMA). When i reload ninja script it shows the right colors again. I can't figure out why the colors get mixed up. Would be great if someone could figure out what the problem is with it. I'll attach a chart with the indicator where you can see the color is green the last few bars where it should be red.
The script looks like this.
//
// Copyright (C) 2007, NinjaTrader LLC <www.ninjatrader.com>.
// NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
//
#region Using declarations
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// This is an indicator plotting an ema in two colors.
/// </summary>
[Description("Cumulative Volume Delta plotted with two colors.")]
[Gui.Design.DisplayName("CDSMA_Up_Down")]
public class CDSMA_Up_Down : GomRecorderIndicator
{
#region Variables
private int period = 9;
#endregion
/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void GomInitialize()
{
// Add one plot for every color you wish to use.
Add(new Plot(Color.Lime, PlotStyle.Line, "Rising"));
Add(new Plot(Color.Red, PlotStyle.Line, "Falling"));
CalculateOnBarClose = false;
Overlay = false;
PriceTypeSupported = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void GomOnBarUpdate()
{
// Checks to make sure we have at least 1 bar before continuing
if (CurrentBar<1)
return;
// Plot green if the CVD is rising
// Rising() returns true when the current value is greater than the value of the previous bar.
if (Rising(GomCDSMA(Period)))
{
// Connects the rising plot segment with the other plots
RisingPlot.Set(1, GomCDSMA(Period)[1]);
// Adds the new rising plot line segment to the line
RisingPlot.Set(GomCDSMA(Period)[0]);
}
// Plot red if the CVD is falling
// Falling() returns true when the current value is less than the value of the previous bar.
else if (Falling(GomCDSMA(Period)))
{
// Connects the new falling plot segment with the rest of the line
FallingPlot.Set(1, GomCDSMA(Period)[1]);
// Adds the new falling plot line segment to the line
FallingPlot.Set(GomCDSMA(Period)[0]);
}
}
Comment