Announcement

Collapse
No announcement yet.

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]);

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        579 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        334 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        554 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        551 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X