Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

First Indicator in Ninja 9 BUT basic Plot not working

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

    First Indicator in Ninja 9 BUT basic Plot not working

    **Ninja 8 not 9

    I have coded a few indicators in TOS (thinkscript/thinkorswim) - not a Developer - and I am trying to transfer them over to Ninjatrader. I am doing the transfer step by step and checking along the way. The problem I have run into is the inability to plot an custom indicator (even if it is a standard one). I can change colors of bars....I can draw lines/texts but I cannot get a simple indicator code to draw. I need to figure this out to move on to the more complicated stuff.

    I am getting no coding errors....it compiles. Trying to simply draw this just to start before I move on.....I want to plot this:

    PriceH[0] = EMA(High, 4)[0];
    PriceL[0] = EMA(Low, 4)[0];


    My Code has the following:

    public class BigT_FT_DayTrade_V2 : Indicator
    {
    private Series<double> trend;
    private Series<double> PriceH;
    private Series<double> PriceL;

    and

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)

    {
    .......(standard stuff here).....

    IsSuspendedWhileInactive = true;
    BarsRequiredToPlot = 20;
    Period = 20;

    MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
    AddPlot(new Stroke(Brushes.Yellow), PlotStyle.HLine, "PriceH");
    AddPlot(new Stroke(Brushes.Orange), PlotStyle.HLine, "PriceL");


    and

    else if (State == State.DataLoaded)
    {
    trend = new Series<double>(this, MaximumBarsLookBack.Infinite);
    PriceH = new Series<double>(this, MaximumBarsLookBack.Infinite);
    PriceL = new Series<double>(this, MaximumBarsLookBack.Infinite);

    and

    protected override void OnBarUpdate()
    {
    if (CurrentBar < Period)
    return;


    and farther down.....

    trend[0] = 0;
    PriceH[0] = EMA(High, 4)[0];
    PriceL[0] = EMA(Low, 4)[0];
    Last edited by BigT4X; 03-09-2022, 02:03 PM.

    #2
    Hello BigT4X,

    Thank you for your note.

    It looks like you have plots set up but are also setting up Series<double> variables with the same name, which could definitely cause an issue.

    I've created a very simple example script that assigns the values of the two EMAs to plots. You don't need to assign the values to a series first, AddPlot will automatically create a series for you for the plot values. You can then simply assign values to that series.

    Please let us know if we may be of further assistance to you.
    Attached Files
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Your example works when I loaded it. BUT copying your code changes and removing the Series logic for those two fields (I have other Series logic for other fields) and removing the Downloaded logic for those two fields and trying to draw HLine instead of a regular line causes the CS0103 error: "The name 'PriceH' (or 'PriceL') does not exist in the current context"


      public class BigT_FT_DayTrade_V2 : Indicator
      {
      private Series<double> trend;
      (PriceH and PriceL series removed)

      and

      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {

      IsSuspendedWhileInactive = true;
      BarsRequiredToPlot = 10;
      Period = 10;
      MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
      AddPlot(new Stroke(Brushes.Yellow), PlotStyle.HLine, "PriceH");
      AddPlot(new Stroke(Brushes.Orange), PlotStyle.HLine, "PriceL");
      }
      else if (State == State.Configure)
      {
      }
      else if (State == State.DataLoaded)
      {
      trend = new Series<double>(this, MaximumBarsLookBack.Infinite);
      (PriceH and PriceL series removed)

      and

      protected override void OnBarUpdate()
      {
      if (CurrentBar < Period)
      return;

      PriceH[0] = EMA(High, 4)[0];
      PriceL[0] = EMA(Low, 4)[0];


      I do not have this code....this might be the problem?? maybe? I do not think it is the problem.
      #region Properties

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

      [Browsable(false)]
      [XmlIgnore]
      public Series<double> PriceL
      {
      get { return Values[1]; }
      }
      #endregion
      Last edited by BigT4X; 03-09-2022, 02:56 PM.

      Comment


        #4
        Hello BigT4X,

        Thank you for your reply.

        You would need to have the #region Properties code just like in the example script - not having that is what's causing the error. That's the part that creates the plot series (these would be automatically added when setting up a plot if you add them using the indicator wizard so you wouldn't have to add that yourself, as a tip).

        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          The region code worked so Thank you!!

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

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> PriceL
          {
          get { return Values[1]; }
          }

          2 follow up questions and that should do it for now:

          1) If I have to draw another indicator....would it become "return Values[2]" and another would be "return Values[3] etc?

          2) Once my code is complete.....If I remove the "addplot" in the end - because in the end I only want to show Up/Down Signals on the chart and not all the underline code/drawings - would I still have to keep the region Properties? and just remove "AddPlot'?

          I need the data not the drawing.......Basically I am using PriceH and PriceL (and other things) to drive a whole lot else.....

          Thank you for your patience on this.

          Comment


            #6
            Hello BigT4X,

            Thank you for your reply.

            That's correct, if you added a third plot you would need to add code to #region Properties for that plot and yes, it would be "return Values[2]" within the get.

            If you remove the AddPlot statement for a plot you can also remove the associated property from the properties section, yes.

            If you're just needing the data to be saved for each bar and not necessarily plotted on the chart itself, that's when you'd use a Series<t> variable instead of a plot:



            Please let us know if we may be of further assistance to you.
            Kate W.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by rhyminkevin, Today, 04:58 PM
            3 responses
            50 views
            0 likes
            Last Post Anfedport  
            Started by iceman2018, Today, 05:07 PM
            0 responses
            5 views
            0 likes
            Last Post iceman2018  
            Started by lightsun47, Today, 03:51 PM
            0 responses
            7 views
            0 likes
            Last Post lightsun47  
            Started by 00nevest, Today, 02:27 PM
            1 response
            14 views
            0 likes
            Last Post 00nevest  
            Started by futtrader, 04-21-2024, 01:50 AM
            4 responses
            50 views
            0 likes
            Last Post futtrader  
            Working...
            X