NexusFi: Find Your Edge


Home Menu

 





Converted NT8 code not working properly.


Discussion in NinjaTrader

Updated
    1. trending_up 100 views
    2. thumb_up 0 thanks given
    3. group 1 followers
    1. forum 0 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 Joseph H 
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;
}
}
}

Started this thread Reply With Quote




Last Updated on December 13, 2024


© 2025 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Sitemap - Downloads - Top
no new posts