Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Select Trend Line as -1

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Select Trend Line as -1

    Hi, I'm building a strategy in SB and having an issue selecting the proper plot. I want the AuEMA Trend to be -1 but it appears to not select the Trend even though it is a plot. Is there something I can do to force the Trend to be selected? I have included a screengrab of the input plots.

    Click image for larger version

Name:	Screenshot 2024-04-17 171302.png
Views:	95
Size:	43.9 KB
ID:	1299951

    and below in red is the code SB writes.
    // Set 1
    if ((Times[0][0].TimeOfDay > StartTime.TimeOfDay)
    && (Times[0][0].TimeOfDay < EndTime.TimeOfDay)
    && (CrossBelow(ZeroLagTEMA2, ZeroLagHATEMA2, 1))
    && (AuEMA1[0] < ZeroLagTEMA2[0])
    && (AuEMA1[0] == -1))

    SB appears to just use the EMA, not the Trend.

    Thanks for your help.​​

    #2
    Hello mmenigma,

    Thank you for your post.

    It would seem this indicator only has one plot, or is not assigning anything to this plot value. You would need to edit the code of this indicator to add an additional plot for the Trend values.



    Once you have added the additional plot, you will be able to select which Value plot you want to use in the Strategy Builder.

    Please let us know if you have any further questions.
    Last edited by NinjaTrader_Gaby; 04-18-2024, 06:12 AM.
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      Hi, I'm revisiting this post. I understand what you're saying about the plot. However, I just created an Alert with this same indicator using Trend = -1 and the alert worked perfectly. The Alert GUI has a different menu for condition options than the Strategy Builder. The image in my original post is from the Strategy Builder conditions and the one here is from Alerts conditions. Is there a way to do the condition selection the same in Strategy Builder as an Alert?

      Click image for larger version

Name:	image.png
Views:	25
Size:	29.6 KB
ID:	1319862

      Thank you, Mitch

      ​​
      Attached Files

      Comment


        #4
        Hello,

        If you aren't seeing the Plot being selectable in the Builder, you'll need to review the code and ensure that there are two plots being added within the indicator's code.

        Gaby V.NinjaTrader Customer Service

        Comment


          #5
          This is where I'm confused. The plots ARE selectable in Alerts, but the same indicator when open in strategy builder are not. It's the exact same indicator with selectable plots in one ninjatrader wizard editor but not the other. It makes no sense.

          Comment


            #6
            Hello mmenigma,

            We would need to see the open source code. Do you have access to the code? If not, you'll need to reach out to the developer.
            Gaby V.NinjaTrader Customer Service

            Comment


              #7
              Hi Gabby, Yes I do have code access I pasted it below. Thanks for asking for it.

              Code:
              public class AuEMA : Indicator
              {
              [HASHTAG="t3322"]region[/HASHTAG] Variables
              private double constant1;
              private double constant2;
              
              private bool showPaintBars = true;
              private Brush upColor = Brushes.Lime;
              private Brush neutralColor = Brushes.Tan;
              private Brush downColor = Brushes.Red;
              private int opacity = 4;
              private int alphaBarClr = 0;
              private bool showPlot = true;
              #endregion
              
              protected override void OnStateChange()
              {
              if (State == State.SetDefaults)
              {
              Description = @"Exponential Moving Average with Paintbar option - Modified by RAYKO";
              Name = "AuEMA";
              IsOverlay = true;
              IsSuspendedWhileInactive = true;
              Period = 14;
              
              ShowTransparentPlotsInDataBox = true;
              
              AddPlot(Brushes.Orange, NinjaTrader.Custom.Resource.NinjaScriptIndicatorNa meEMA);
              AddPlot(new Stroke() { Brush = Brushes.Transparent }, PlotStyle.Dot, "Trend");
              }
              else if (State == State.Configure)
              {
              constant1 = 2.0 / (1 + Period);
              constant2 = 1 - (2.0 / (1 + Period));
              }
              }
              
              protected override void OnBarUpdate()
              {
              Value[0] = (CurrentBar == 0 ? Input[0] : Input[0] * constant1 + constant2 * Value[1]);
              
              if (CurrentBar < 1)
              {
              if (showPlot)
              Plots[0].Brush = Brushes.Gray;
              else
              Plots[0].Brush = Brushes.Transparent;
              }
              else
              {
              alphaBarClr = 25 * opacity;
              
              Trend[0] = 0;
              if (Value[0] > Value[1])
              Trend[0] = 1;
              else if (Value[0] < Value[1])
              Trend[0] = -1;
              
              if (showPlot)
              {
              if (Trend[0] == 1)
              PlotBrushes[0][0] = upColor;
              else if (Trend[0] == -1)
              PlotBrushes[0][0] = downColor;
              else if (Trend[0] == 0)
              PlotBrushes[0][0] = neutralColor;
              }
              
              if (showPaintBars)
              {
              if (Trend[0] == 1)
              {
              BarBrushes[0] = upColor;
              CandleOutlineBrushes[0] = upColor;
              }
              else if (Trend[0] == -1)
              {
              BarBrushes[0] = downColor;
              CandleOutlineBrushes[0] = downColor;
              }
              else
              {
              BarBrushes[0] = neutralColor;
              CandleOutlineBrushes[0] = neutralColor;
              }
              
              if (Close[0] > Open[0])
              {
              byte g = ((Color)BarBrushes[0].GetValue(SolidColorBrush.ColorProperty)).G;
              byte r = ((Color)BarBrushes[0].GetValue(SolidColorBrush.ColorProperty)).R;
              byte b = ((Color)BarBrushes[0].GetValue(SolidColorBrush.ColorProperty)).B;
              
              BarBrushes[0] = new SolidColorBrush(Color.FromArgb((byte)alphaBarClr, r, g, b));
              }
              }
              }
              }


              Code:
              [HASHTAG="t3322"]region[/HASHTAG] Properties
              [Browsable(false)]
              [XmlIgnore]
              public Series<double> Trend
              {
              get { return Values[1]; }
              }
              
              [Range(1, int.MaxValue), NinjaScriptProperty]
              [Display(ResourceType = typeof(Custom.Resource), Name = "Period", GroupName = "Gen. Parameters", Order = 0)]
              public int Period
              { get; set; }
              
              [Display(Name = "Show PaintBars", Description = "Show paint bars on price panel", Order = 1, GroupName = "Gen. Parameters")]
              public bool ShowPaintBars
              {
              get { return showPaintBars; }
              set { showPaintBars = value; }
              }
              
              [XmlIgnore]
              [Display(Name = "Average Chop Mode", Description = "Select color for neutral average", Order = 0, GroupName = "Plot Colors")]
              public Brush NeutralColor
              {
              get { return neutralColor; }
              set { neutralColor = value; }
              }
              
              [Browsable(false)]
              public string NeutralColorSerialize
              {
              get { return Serialize.BrushToString(neutralColor); }
              set { neutralColor = Serialize.StringToBrush(value); }
              }
              
              [XmlIgnore]
              [Display(Name = "Average Falling", Description = "Select color for falling average", Order = 1, GroupName = "Plot Colors")]
              public Brush DownColor
              {
              get { return downColor; }
              set { downColor = value; }
              }
              
              [Browsable(false)]
              public string DownColorSerialize
              {
              get { return Serialize.BrushToString(downColor); }
              set { downColor = Serialize.StringToBrush(value); }
              }
              
              [XmlIgnore]
              [Display(Name = "Average Rising", Description = "Select color for rising average", Order = 2, GroupName = "Plot Colors")]
              public Brush UpColor
              {
              get { return upColor; }
              set { upColor = value; }
              }
              
              [Browsable(false)]
              public string UpColorSerialize
              {
              get { return Serialize.BrushToString(upColor); }
              set { upColor = Serialize.StringToBrush(value); }
              }
              
              [Display(Name = "Upclose Opacity", Description = "When paint bars are activated, this parameter sets the opacity of the upclose bars", Order = 3, GroupName = "Plot Colors")]
              public int Opacity
              {
              get { return opacity; }
              set { opacity = value; }
              }
              
              [Display(Name = "Show Plot", Description = "Show plot", Order = 4, GroupName = "Plot Colors")]
              public bool ShowPlot
              {
              get { return showPlot; }
              set { showPlot = value; }
              }
              
              #endregion
              }
              }
              
              [HASHTAG="t3322"]region[/HASHTAG] NinjaScript generated code. Neither change nor remove.
              
              namespace NinjaTrader.NinjaScript.Indicators
              {
              public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
              {
              private AuEMA[] cacheAuEMA;
              public AuEMA AuEMA(int period)
              {
              return AuEMA(Input, period);
              }
              
              public AuEMA AuEMA(ISeries<double> input, int period)
              {
              if (cacheAuEMA != null)
              for (int idx = 0; idx < cacheAuEMA.Length; idx++)
              if (cacheAuEMA[idx] != null && cacheAuEMA[idx].Period == period && cacheAuEMA[idx].EqualsInput(input))
              return cacheAuEMA[idx];
              return CacheIndicator<AuEMA>(new AuEMA(){ Period = period }, input, ref cacheAuEMA);
              }
              }
              }
              
              namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
              {
              public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
              {
              public Indicators.AuEMA AuEMA(int period)
              {
              return indicator.AuEMA(Input, period);
              }
              
              public Indicators.AuEMA AuEMA(ISeries<double> input , int period)
              {
              return indicator.AuEMA(input, period);
              }
              }
              }
              
              namespace NinjaTrader.NinjaScript.Strategies
              {
              public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
              {
              public Indicators.AuEMA AuEMA(int period)
              {
              return indicator.AuEMA(Input, period);
              }
              
              public Indicators.AuEMA AuEMA(ISeries<double> input , int period)
              {
              return indicator.AuEMA(input, period);
              }
              }
              }
              
              #endregion
              Last edited by mmenigma; 10-03-2024, 01:50 PM.

              Comment


                #8
                Hello,

                Can you share the actual .zip file? The code you've posted is throwing compile errors.

                To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
                1. Click Tools -> Export -> NinjaScript Add-on...
                2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
                3. Click the 'Export' button
                4. Enter a unique name for the file in the value for 'File name:'
                5. Choose a save location -> click Save
                6. Click OK to clear the export location message
                By default your exported file will be in the following location:
                • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
                Below is a link to the help guide on Exporting NinjaScripts.


                Once exported, please attach the file as an attachment to your reply.

                I look forward to receiving the export.​
                Gaby V.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Gaby, Attached is an export of the auEMA indicator I'm working with. Thank you for your export instructions.
                  Attached Files

                  Comment


                    #10
                    Hello,

                    The Values[plot index] must be returned by a public Series<double> for the indicator to appear in the Strategy Builder. This indicator is not returning the series in the Properties section.

                    The following code is missing:

                    Code:
                    [Browsable(false)]
                    [XmlIgnore]
                    public Series<double> EMA
                    {
                    get { return Values[0]; }
                    }
                    ​​
                    Gaby V.NinjaTrader Customer Service

                    Comment


                      #11
                      OMG THANK YOU! I added that code in the properties section just below another similar piece of code for Trend.

                      Code:
                      #region Properties
                      [Browsable(false)]
                      [XmlIgnore]
                      public Series<double> Trend
                      {
                      get { return Values[1]; }
                      }
                      
                      [Browsable(false)]
                      [XmlIgnore]
                      public Series<double> EMA
                      {
                      get { return Values[0]; }
                      }​



                      I assume it was added correctly as it compiled without issues, and I CAN SELECT TREND ONLY AS A PLOT!!

                      Click image for larger version  Name:	image.png Views:	2 Size:	4.2 KB ID:	1320497
                      ​​
                      Gaby, you are a SuperModerator. Thank you so much.

                      Mitch
                      Last edited by mmenigma; 10-04-2024, 11:03 AM.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by NasdaqAnalytica, Today, 03:33 PM
                      1 response
                      4 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by Auvrayphil, Today, 03:44 PM
                      0 responses
                      4 views
                      0 likes
                      Last Post Auvrayphil  
                      Started by jamesbhardwaj, Today, 04:41 AM
                      1 response
                      14 views
                      0 likes
                      Last Post NinjaTrader_LuisH  
                      Started by diorfo, Today, 12:48 PM
                      5 responses
                      23 views
                      0 likes
                      Last Post NinjaTrader_ChristopherJ  
                      Started by cp202822, Today, 01:38 PM
                      2 responses
                      14 views
                      0 likes
                      Last Post cp202822  
                      Working...
                      X