Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Cannot Use Custom Indicator in Strategy Builder, code is pasted

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

    Cannot Use Custom Indicator in Strategy Builder, code is pasted

    I coded a basic Elliot Oscillator, I have been at this for about 12hours in various ways, scouring this forum and youtube. I cant make this work. I need to pull the value(double) from this indicator into my strategy. I had another version when I had the drop menus to pick the variable from the indicator in the strategy builder, but I was still missing the data, I get this error message:

    "'ElliotWaveOscilator' tried to load additional data. All data must first be loaded by the hosting NinjaScript in its configure state. Attempted to load HBars Default: 600 Tick Heiken-Ashi"
    itried doing extra data series and all kinds of weird stuff. this code does not even have the drop down menu working in the strategy builder, but is the cleanest version I have working on a chart. For the life of me, I cannot figure out where to pull the plot values form. I even tried doing a transparent plot like another post here said, but still couldnt get those to show up in the drop down menus of the strategy builder so i could use them.

    This is the cleanest version of code that works perfectly on my chart as an indicator. thank you for any help I am exhausted and I am sure I am missing something basic. Feel free to use if useful to you.
    Here is a pic of it working on chart...
    Click image for larger version

Name:	EWO.png
Views:	371
Size:	65.9 KB
ID:	1174995


    Elliot Wave Oscillator Code

    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class ElliotWaveOscilator : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"";
    Name = "ElliotWaveOscilator";
    Calculate = Calculate.OnEachTick;
    IsOverlay = false;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    FastSMA = 5;
    SlowSMA = 35;
    DownColor =Brushes.IndianRed;
    AddLine(Brushes.White, 0, NinjaTrader.Custom.Resource.NinjaScriptIndicatorZe roLine);
    AddLine(Brushes.White, 5, NinjaTrader.Custom.Resource.NinjaScriptIndicatorOv erBoughtLine);
    AddLine(Brushes.White, -5, NinjaTrader.Custom.Resource.NinjaScriptIndicatorOv erSoldLine);
    AddPlot(new Stroke(Brushes.SpringGreen, 2), PlotStyle.Bar, "HBars");
    //bar widths on histogram
    Plots[0].AutoWidth = true;

    }
    else if (State == State.Configure)
    {
    AddDataSeries("HBars");
    }
    }

    protected override void OnBarUpdate()
    {
    Value[0] = (SMA(FastSMA)[0]-SMA(SlowSMA)[0]);
    if (Value[0] < 0)
    PlotBrushes[0][0] = DownColor;

    }

    #region Properties
    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="FastSMA", Order=1, GroupName="Parameters")]
    public int FastSMA
    { get; set; }

    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="SlowSMA", Order=2, GroupName="Parameters")]
    public int SlowSMA
    { get; set; }

    [XmlIgnore]
    [Display(ResourceType = typeof(Custom.Resource), Name = "DownColor", GroupName = "NinjaScriptIndicatorVisualGroup", Order = 1800)]
    public Brush DownColor { get; set; }

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> HBars
    {
    get { return Values[0]; }
    }
    #endregion

    }
    }

    #region NinjaScript generated code. Neither change nor remove.

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
    private ElliotWaveOscilator[] cacheElliotWaveOscilator;
    public ElliotWaveOscilator ElliotWaveOscilator(int fastSMA, int slowSMA)
    {
    return ElliotWaveOscilator(Input, fastSMA, slowSMA);
    }

    public ElliotWaveOscilator ElliotWaveOscilator(ISeries<double> input, int fastSMA, int slowSMA)
    {
    if (cacheElliotWaveOscilator != null)
    for (int idx = 0; idx < cacheElliotWaveOscilator.Length; idx++)
    if (cacheElliotWaveOscilator[idx] != null && cacheElliotWaveOscilator[idx].FastSMA == fastSMA && cacheElliotWaveOscilator[idx].SlowSMA == slowSMA && cacheElliotWaveOscilator[idx].EqualsInput(input))
    return cacheElliotWaveOscilator[idx];
    return CacheIndicator<ElliotWaveOscilator>(new ElliotWaveOscilator(){ FastSMA = fastSMA, SlowSMA = slowSMA }, input, ref cacheElliotWaveOscilator);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
    public Indicators.ElliotWaveOscilator ElliotWaveOscilator(int fastSMA, int slowSMA)
    {
    return indicator.ElliotWaveOscilator(Input, fastSMA, slowSMA);
    }

    public Indicators.ElliotWaveOscilator ElliotWaveOscilator(ISeries<double> input , int fastSMA, int slowSMA)
    {
    return indicator.ElliotWaveOscilator(input, fastSMA, slowSMA);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
    public Indicators.ElliotWaveOscilator ElliotWaveOscilator(int fastSMA, int slowSMA)
    {
    return indicator.ElliotWaveOscilator(Input, fastSMA, slowSMA);
    }

    public Indicators.ElliotWaveOscilator ElliotWaveOscilator(ISeries<double> input , int fastSMA, int slowSMA)
    {
    return indicator.ElliotWaveOscilator(input, fastSMA, slowSMA);
    }
    }
    }

    #endregion

    #2
    Hello HaveGunsWillTravel,

    Thanks for your post.

    The error message, "'ElliotWaveOscilator' tried to load additional data. All data must first be loaded by the hosting NinjaScript in its configure state. Attempted to load HBars Default: 600 Tick Heiken-Ashi"" Is caused when a script requests bars inside of another script. In this case, the indicator is requesting HBars and the Strategy is the host of the indicator and the strategy is required to provide that data. Typical use of AddDataSeries would be to add for example a 1 tick series to the indicator and in that case the strategy must provide that 1 tick series.

    In this case the indicator is generating the HBars so you have a natural conflict here. Please remove the line AddDataSeries("HBars");

    With that removed you should be able to recompile the indicator. When you use the indicator in the Strategy Builder you should be able to get the HBars from the indicator as these are a plot which is what the Strategy Builder needs. When you open the indicators folder in the conditions builder of the strategy builder you should see plot field showing HBars so when the indicator is used it will return the value of HBar. You can always construct a Print statement to show this in the strategy builder in the action section with Misc>Print and then select the indicator.




    Paul H.NinjaTrader Customer Service

    Comment


      #3
      My god it seems to be working, I could cry. Thank you.

      Comment


        #4
        For my learning purposes, what was I doing wrong in terms of referencing data? Was I trying to force a call somewhere weird by inserting that data series add? How and where is it calling the value of the oscillator<double> now, in its working state? thanks again.

        Comment


          #5
          Hello HaveGunsWillTravel,

          Thanks for your reply.

          AddDataSeries would be for adding other bars to your script. The HBars data series was not created until you ran your indicator so it was trying to add something that was not available and it appears to have defaulted to 600 Tick Heiken-Ashi.

          When you select the indicator in the strategy builder and create a condition with it, that is where the indicator is called and it returns the value of the plot HBars. Note: FYI - if you have a multi-plot indicator such as a Bollinger, you would have to select which plot to be used as the "Value Plot" (in that condition).

          Paul H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by inanazsocial, Today, 01:15 AM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_Jason  
          Started by rocketman7, Today, 02:12 AM
          0 responses
          5 views
          0 likes
          Last Post rocketman7  
          Started by dustydbayer, Today, 01:59 AM
          0 responses
          1 view
          0 likes
          Last Post dustydbayer  
          Started by trilliantrader, 04-18-2024, 08:16 AM
          5 responses
          22 views
          0 likes
          Last Post trilliantrader  
          Started by Davidtowleii, Today, 12:15 AM
          0 responses
          3 views
          0 likes
          Last Post Davidtowleii  
          Working...
          X