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

Beginner, No data printing to screen, should be easy fix

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

    Beginner, No data printing to screen, should be easy fix

    I have very little experience with C# and almost none with NinjaTrader scripting, but i do have a decent amount of C++ experience.

    I have written this code to plot the well known ichimoku indicator as practice, but seem to be missing something.
    It compiles fine and can be applied to the chart, but there is no output on the chart..
    Could someone please point me in the right direction, I dont see what im missing, everything appears perfect in my code.


    public class Ichimoku : Indicator
    {
    #region Variables
    // Wizard generated variables
    private int tSperiod = 9; // Default setting for TSperiod
    private int kSperiod = 26; // Default setting for KSperiod
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "TS"));
    Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "KS"));
    Add(new Plot(Color.FromKnownColor(KnownColor.DarkViolet), PlotStyle.Line, "SpanA"));
    Displacement = kSperiod;
    Add(new Plot(Color.FromKnownColor(KnownColor.Firebrick), PlotStyle.Line, "SpanB"));
    Displacement = kSperiod;
    Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "CS"));
    Displacement = (kSperiod * (-1));
    CalculateOnBarClose = true;
    Overlay = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.

    double ts1, ks1, spa1, spb1, cs1;

    ts1 = (High[tSperiod] + Low[tSperiod]) / 2;
    ks1 = (High[kSperiod] + Low[kSperiod]) / 2;
    spa1 = (ts1 + ks1) / 2;
    spb1 = (High[(kSperiod * 2)] + Low[(kSperiod * 2)]) / 2;
    cs1 = Close[0];

    TS.Set(ts1);
    KS.Set(ks1);
    SpanA.Set(spa1);
    SpanB.Set(spb1);
    CS.Set(cs1);
    }
    }

    #2
    I have found the error..
    I wasn't calling the correct input price data.
    I changed High[tSperiod] to MAX(High, tSperiod)[0]

    Everything seems to be calculating correctly, but shifting or "displacing" the plot seems to be the new problem.
    All plots are shifted back. I need to know how to specify individual shifts for separate plots

    Comment


      #3
      I've finished searching for a solution, and have come up empty handed. Found a post saying specific line displacements for each plot are not supported. Im sure there's a way around, besides making the indicator 3 separate indicators, but i don't know near enough C# for that. So i will be making this three separate indicators.

      Comment


        #4
        Welcome to the forums here - correct the displacement property in the Initialize() would apply to the full indicator and all its plots, however as you set the Plot value you could setup a custom displacement by indexing / referencing to another value further back.

        Plot0.Set(SMA(Close, 20)[5]);
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by GussJ, 03-04-2020, 03:11 PM
        11 responses
        3,221 views
        0 likes
        Last Post xiinteractive  
        Started by andrewtrades, Today, 04:57 PM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by chbruno, Today, 04:10 PM
        0 responses
        6 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by josh18955, 03-25-2023, 11:16 AM
        6 responses
        436 views
        0 likes
        Last Post Delerium  
        Started by FAQtrader, Today, 03:35 PM
        0 responses
        9 views
        0 likes
        Last Post FAQtrader  
        Working...
        X