Wilmington Delaware
Experience: Intermediate
Platform: NinjaTrader, TOS
Trading: Futures
Posts: 24 since May 2019
Thanks Given: 3
Thanks Received: 16
|
1st off, thanks to ThinkDecoded for converting my TOS code over to NinjaTrader 8. It works properly when I hard code the colors for up/down conditions.
Example:
// Cambiar colores según la tendencia
PlotBrushes[0][0] = emaSeries[0] > emaSeries[1] ? System.Windows.Media.Brushes.White : System.Windows.Media.Brushes.Black;
PlotBrushes[1][0] = smoothingLine1[0] > smoothingLine1[1] ? System.Windows.Media.Brushes.LightGreen : System.Windows.Media.Brushes.Red;
PlotBrushes[2][0] = smoothingLine2[0] > smoothingLine2[1] ? System.Windows.Media.Brushes.LightGreen : System.Windows.Media.Brushes.Red;
PlotBrushes[3][0] = smoothingLine3[0] > smoothingLine3[1] ? System.Windows.Media.Brushes.Blue : System.Windows.Media.Brushes.Purple;
However the color selection inside the setting dialog for each EMA does not work. I tried to message ThinkDecoded about it, but haven't received an answer.
Here is the code. Any help would be greatly appreciated, Thanks!
Code:
#region Using declarations
using System;
using NinjaTrader.Gui.Tools;
using NinjaTrader.NinjaScript;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
using System.Windows.Media; // Necesario para Brushes
#endregion
namespace NinjaTrader.NinjaScript.Indicators
{
public class MultiSmoothedEMA : Indicator
{
private EMA emaSeries;
private EMA smoothingLine1;
private EMA smoothingLine2;
private EMA smoothingLine3;
[NinjaScriptProperty]
public int Length { get; set; } = 50;
[NinjaScriptProperty]
public int SmoothingLength1 { get; set; } = 5;
[NinjaScriptProperty]
public int SmoothingLength2 { get; set; } = 10;
[NinjaScriptProperty]
public int SmoothingLength3 { get; set; } = 15;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = "Indicator with EMA and multiple smoothed lines.";
Name = "MultiSmoothedEMA";
IsOverlay = true;
AddPlot(System.Windows.Media.Brushes.LawnGreen, "EMA Line");
AddPlot(System.Windows.Media.Brushes.Blue, "Smoothing Line 1");
AddPlot(System.Windows.Media.Brushes.Blue, "Smoothing Line 2");
AddPlot(System.Windows.Media.Brushes.Black, "Smoothing Line 3");
}
else if (State == State.DataLoaded)
{
emaSeries = EMA(Close, Length);
smoothingLine1 = EMA(emaSeries, SmoothingLength1);
smoothingLine2 = EMA(emaSeries, SmoothingLength2);
smoothingLine3 = EMA(emaSeries, SmoothingLength3);
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < Math.Max(Length, Math.Max(SmoothingLength1, Math.Max(SmoothingLength2, SmoothingLength3))))
return;
// Asignar valores a los plots
Values[0][0] = emaSeries[0];
Values[1][0] = smoothingLine1[0];
Values[2][0] = smoothingLine2[0];
Values[3][0] = smoothingLine3[0];
// Cambiar colores según la tendencia
PlotBrushes[0][0] = emaSeries[0] > emaSeries[1] ? System.Windows.Media.Brushes.White : System.Windows.Media.Brushes.Black;
PlotBrushes[1][0] = smoothingLine1[0] > smoothingLine1[1] ? System.Windows.Media.Brushes.LightGreen : System.Windows.Media.Brushes.Red;
PlotBrushes[2][0] = smoothingLine2[0] > smoothingLine2[1] ? System.Windows.Media.Brushes.LightGreen : System.Windows.Media.Brushes.Red;
PlotBrushes[3][0] = smoothingLine3[0] > smoothingLine3[1] ? System.Windows.Media.Brushes.Blue : System.Windows.Media.Brushes.Purple;
}
}
}
|