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

Indicator exposing non-plot int series

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

    Indicator exposing non-plot int series

    Hi,

    I would like to expose some non-plot values such as the Signal, the structure Stops & Targets...

    I have some challenges so, I put together a simple example to demo the issue that creates two simple MA cross signals as an example. Attached is a zip with two basic indicators: the one that create the signals (2 types) and draw them as vertical lines (in 2 different patterns), and another indicator that reads the two signals <int> series and plot the value (-1/1 and -2/2).

    There are 2 issues:
    1. Strategy builder only see the <double> output series, but not the <int> output series that the BWATT indicator creates
    2. The BWATTTest indicator only manage to read the second <int> output series, but ignore the first
    Here is the relevant code of the BWATT, which creates the signals:
    Code:
     protected override void OnBarUpdate()
    {
    if (saveCurrentBar != CurrentBar) // only once per bar
    {
    saveCurrentBar = CurrentBar;
    signal = 0;
    signalTrend[0] = 0;
    signalBreak[0] = 0;
    stop1[0] = 0;
    target1[0] = 0;
    stop2[0] = 0;
    target2[0] = 0;
    }
    
    if (CrossAbove(smaFast, smaSlow, 1))
    {
    signal=1;
    signalTrend[0]=signal;
    Draw.VerticalLine(this,"Signal-"+CurrentBar+"-L1",0,Brushes.Green);
    }
    else if (CrossBelow(smaFast, smaSlow, 1))
    {
    signal=-1;
    signalTrend[0]=signal;
    Draw.VerticalLine(this,"Signal-"+CurrentBar+"-S1",0,Brushes.Red);
    }
    else if (CrossAbove(smaFast, smaSlow, 5))
    {
    signal=2;
    signalTrend[0]=signal;
    Draw.VerticalLine(this,"Signal-"+CurrentBar+"-L2",0,Brushes.Green,DashStyleHelper.DashDotDot,1,t rue);
    }
    else if (CrossBelow(smaFast, smaSlow, 5))
    {
    signal=-2;
    signalTrend[0]=signal;
    Draw.VerticalLine(this,"Signal-"+CurrentBar+"-S2",0,Brushes.Red,DashStyleHelper.DashDotDot,1,tru e);
    }
    
    }
    
    #region #### Properties ####
    [Range(1, int.MaxValue), NinjaScriptProperty]
    [Display(ResourceType = typeof(Custom.Resource), Name = "Fast", GroupName = "NinjaScriptStrategyParameters", Order = 0)]
    public int Fast
    { get; set; }
    
    [Range(1, int.MaxValue), NinjaScriptProperty]
    [Display(ResourceType = typeof(Custom.Resource), Name = "Slow", GroupName = "NinjaScriptStrategyParameters", Order = 1)]
    public int Slow
    { get; set; }
    
    [Browsable(false)]
    [XmlIgnore]
    public Series<int> SignalTrend
    {
    get { return signalTrend; }
    }
    
    [Browsable(false)]
    [XmlIgnore]
    public Series<int> SignalBreak
    {
    get { return signalBreak; }
    }
    
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> Stop1
    {
    get { return stop1; }
    }
    
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> Target1
    {
    get { return target1; }
    }
    
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> Stop2
    {
    get { return stop2; }
    }
    
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> Target2
    {
    get { return target2; }
    }
    #endregion
    Here is the second indicator BWATTTest, who reads the signal from BWATT and plot on a panel:
    Code:
     protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;
    
    if (CurrentBars[0] < 0)
    return;
    
    Values[0][0] = BWATT1.SignalTrend[0];
    Values[1][0] = BWATT1.SignalBreak[0];
    }
    This is the output, which shows that the second output is drawn (+2/-2), but the first one is ignored (=0):
    Click image for larger version

Name:	Screen Shot 2022-05-23 at 3.43.57 PM.png
Views:	217
Size:	284.6 KB
ID:	1202587

    #2
    Hello Shai Samuel,

    The Strategy Builder is only able to see plots added with AddPlot() with the Value collection returned as a public double series.

    Below is a link to a forum post that discusses and includes an example.
    I'm trying to expose my variables to the strategy builder so everyone can have better use of the WaveTrend indicator (it has a lot of code). Explain this to me like I am 5 because this isnt the first time I've tried to figure it out and hit a wall. What is Series? I know its like an array that stores bars. Why not just call it


    Anything that is not returned with a public double series and any public double series not added with AddPlot() will not be usable in the Strategy Builder.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you Chelsea, I just did and it works
      Last edited by Shai Samuel; 05-23-2022, 11:07 PM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by bortz, 11-06-2023, 08:04 AM
      47 responses
      1,608 views
      0 likes
      Last Post aligator  
      Started by jaybedreamin, Today, 05:56 PM
      0 responses
      9 views
      0 likes
      Last Post jaybedreamin  
      Started by DJ888, 04-16-2024, 06:09 PM
      6 responses
      19 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by Jon17, Today, 04:33 PM
      0 responses
      6 views
      0 likes
      Last Post Jon17
      by Jon17
       
      Started by Javierw.ok, Today, 04:12 PM
      0 responses
      16 views
      0 likes
      Last Post Javierw.ok  
      Working...
      X