I have been able to convert 2 paintbar strategies to indicators successfully--the most recent was today converting a candle paintbar for O>C or O<C just because I hate the Ninja default candles with the outline I cant eliminate and still see the wicks so I wrote my own which I'll be glad to share if anyone wants it.
Anyhow, I wrote a strategy for 2 EMA with 2 different pricing types that crossover or under. The values it plots were correct except both lines were orange and I couldnt change it because I wasnt sure where to tell it or how to get the ability to change colors from the chart once its loaded.
I tried to copy it into a new indicator script window and added some things from previous forum attempts to help me, and it compiles but wont print as an indicator. In the Indicators Window it shows as TwoEMAs(<unknown>,<unknown>)
Reproducing each below:
Strategy first which plots correctly but unsure how to set colors as an input:
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// 2 EMAs Crossing
/// </summary>
[Description("2 EMAs Crossing")]
public class TwoEMAs : Strategy
{
#region Variables
// Wizard generated variables
private int periodF = 5; // Default setting for PeriodF
private int periodS = 6; // Default setting for PeriodS
// User defined variables (add any user defined variables below)
#endregion
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
Add(EMA(Close, 5));
Add(EMA(Open, 6));
Add(EMA(Close, 5));
Add(EMA(Open, 6));
CalculateOnBarClose = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (CrossAbove(EMA(Close, 5), EMA(Open, 6), 1))
{
DrawDiamond("My diamond" + CurrentBar, false, 0, 0, Color.Green);
}
// Condition set 2
if (CrossBelow(EMA(Close, 5), EMA(Open, 6), 1))
{
DrawDiamond("My diamond" + CurrentBar, false, 0, 0, Color.Red);
}
}
#region Properties
[Description("Fast EMA")]
[Category("Parameters")]
public int PeriodF
{
get { return periodF; }
set { periodF = Math.Max(1, value); }
}
[Description("SlowEMA")]
[Category("Parameters")]
public int PeriodS
{
get { return periodS; }
set { periodS = Math.Max(1, value); }
}
#endregion
}
}
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// 2 EMAs Crossing
/// </summary>
[Description("2 EMAs Crossing")]
public class TwoEMAs : Indicator
{
#region Variables
// Wizard generated variables
private int periodF = 5; // Default setting for PeriodF
private int periodS = 6; // Default setting for PeriodS
// User defined variables (add any user defined variables below)
#endregion
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
Add(new Plot(Color.Orange, "Fast"));
Add(new Plot(Color.Blue, "Slow"));
double periodF=EMA(Close, 5)[0];
double periodS=EMA(Open, 6)[0];
// Add(EMA(Close, 5));
// Add(EMA(Open, 6));
Plots[0].Pen.Color = Color.Orange;
Plots[1].Pen.Color = Color.Blue;
Overlay = true;
CalculateOnBarClose = false;
PriceTypeSupported = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (CrossAbove(EMA(Close, 5), EMA(Open, 6), 1))
{
DrawDiamond("My diamond" + CurrentBar, false, 0, 0, Color.Green);
}
// Condition set 2
if (CrossBelow(EMA(Close, 5), EMA(Open, 6), 1))
{
DrawDiamond("My diamond" + CurrentBar, false, 0, 0, Color.Red);
}
Value.Set(CurrentBar == 0 ? Close[0] : Close[0] * (2.0 / (1 + periodF)) + (1 - (2.0 / (1 + periodF))) * Value[1]);
Value.Set(CurrentBar == 0 ? Open[0] : Open[0] * (2.0 / (1 + periodS)) + (1 - (2.0 / (1 + periodS))) * Value[1]);
}
#region Properties
[Description("Fast EMA")]
[Category("Parameters")]
public int PeriodF
{
get { return periodF; }
set { periodF = Math.Max(1, value); }
}
[Description("SlowEMA")]
[Category("Parameters")]
public int PeriodS
{
get { return periodS; }
set { periodS = Math.Max(1, value); }
}
#endregion
}
}
#region NinjaScript generated code. Neither change nor remove.
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
public partial class Indicator : IndicatorBase
{
private TwoEMAs[] cacheTwoEMAs = null;
private static TwoEMAs checkTwoEMAs = new TwoEMAs();
/// <summary>
/// 2 EMAs Crossing
/// </summary>
/// <returns></returns>
public TwoEMAs TwoEMAs(int periodF, int periodS)
{
return TwoEMAs(Input, periodF, periodS);
}
/// <summary>
/// 2 EMAs Crossing
/// </summary>
/// <returns></returns>
public TwoEMAs TwoEMAs(Data.IDataSeries input, int periodF, int periodS)
{
checkTwoEMAs.PeriodF = periodF;
periodF = checkTwoEMAs.PeriodF;
checkTwoEMAs.PeriodS = periodS;
periodS = checkTwoEMAs.PeriodS;
if (cacheTwoEMAs != null)
for (int idx = 0; idx < cacheTwoEMAs.Length; idx++)
if (cacheTwoEMAs[idx].PeriodF == periodF && cacheTwoEMAs[idx].PeriodS == periodS && cacheTwoEMAs[idx].EqualsInput(input))
return cacheTwoEMAs[idx];
TwoEMAs indicator = new TwoEMAs();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
indicator.Input = input;
indicator.PeriodF = periodF;
indicator.PeriodS = periodS;
indicator.SetUp();
TwoEMAs[] tmp = new TwoEMAs[cacheTwoEMAs == null ? 1 : cacheTwoEMAs.Length + 1];
if (cacheTwoEMAs != null)
cacheTwoEMAs.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheTwoEMAs = tmp;
Indicators.Add(indicator);
return indicator;
}
}
}
// This namespace holds all market analyzer column definitions and is required. Do not change it.
namespace NinjaTrader.MarketAnalyzer
{
public partial class Column : ColumnBase
{
/// <summary>
/// 2 EMAs Crossing
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.TwoEMAs TwoEMAs(int periodF, int periodS)
{
return _indicator.TwoEMAs(Input, periodF, periodS);
}
/// <summary>
/// 2 EMAs Crossing
/// </summary>
/// <returns></returns>
public Indicator.TwoEMAs TwoEMAs(Data.IDataSeries input, int periodF, int periodS)
{
return _indicator.TwoEMAs(input, periodF, periodS);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// 2 EMAs Crossing
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.TwoEMAs TwoEMAs(int periodF, int periodS)
{
return _indicator.TwoEMAs(Input, periodF, periodS);
}
/// <summary>
/// 2 EMAs Crossing
/// </summary>
/// <returns></returns>
public Indicator.TwoEMAs TwoEMAs(Data.IDataSeries input, int periodF, int periodS)
{
if (InInitialize && input == null)
throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
return _indicator.TwoEMAs(input, periodF, periodS);
}
}
}
#endregion

Comment