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

Help with simple indicator

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

    Help with simple indicator

    I am trying to program an "indicator" that is just a simple plot of either a red dot or green dot depending on whether the value of an indicator (MACD(8,17,9)) on the current bar [0] is greater than (green dot) or less than (red dot) the value of the same indicator on the previous bar [1]. After trying to compile, I am getting the errors CS1502 and CS1503. This is my first attempt at programming an indicator and was wondering if you could look at what I have done so far. Any suggestions as to how to proceed from here would be much appreciated. This is the code:

    /// Enter the description of your new custom indicator here
    ///</summary>
    [Description("Enter the description of your new custom indicator here")]
    publicclass MACDHILO : Indicator
    {
    Variables

    ///<summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    ///</summary>
    protectedoverridevoid Initialize()
    {
    Add(
    new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Dot, "PlotLo"));
    Add(
    new Plot(Color.FromKnownColor(KnownColor.Lime), PlotStyle.Dot, "PlotHi"));
    CalculateOnBarClose =
    false;
    Overlay =
    false;
    PriceTypeSupported =
    false;
    }
    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()
    {
    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    PlotLo.Set(MACD(8, 17, 9)[0] < MACD(8, 17, 9)[1]);
    PlotHi.Set(MACD(
    8, 17, 9)[0] > MACD(8, 17, 9)[1]);
    }
    Properties


    Thank you
    Jim

    #2
    Link to the error code

    Have a look at the link below for a description of the error code:



    Hope it helps


    Originally posted by JT454 View Post
    I am trying to program an "indicator" that is just a simple plot of either a red dot or green dot depending on whether the value of an indicator (MACD(8,17,9)) on the current bar [0] is greater than (green dot) or less than (red dot) the value of the same indicator on the previous bar [1]. After trying to compile, I am getting the errors CS1502 and CS1503. This is my first attempt at programming an indicator and was wondering if you could look at what I have done so far. Any suggestions as to how to proceed from here would be much appreciated. This is the code:

    /// Enter the description of your new custom indicator here
    ///</summary>
    [Description("Enter the description of your new custom indicator here")]
    publicclass MACDHILO : Indicator
    {
    Variables

    ///<summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    ///</summary>
    protectedoverridevoid Initialize()
    {
    Add(
    new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Dot, "PlotLo"));
    Add(
    new Plot(Color.FromKnownColor(KnownColor.Lime), PlotStyle.Dot, "PlotHi"));
    CalculateOnBarClose =
    false;
    Overlay =
    false;
    PriceTypeSupported =
    false;
    }
    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()
    {
    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    PlotLo.Set(MACD(8, 17, 9)[0] < MACD(8, 17, 9)[1]);
    PlotHi.Set(MACD(
    8, 17, 9)[0] > MACD(8, 17, 9)[1]);
    }
    Properties


    Thank you
    Jim

    Comment


      #3
      JT,

      It would be helpful to show which lines are causing the error.

      I wouldn't (althought I'm not sure if you can or not) set the plots with a condition as you have it here.

      Replace this:
      Code:
      [FONT=Courier New][SIZE=2]PlotLo.Set(MACD([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]8[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]17[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]9[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] < MACD([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]8[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]17[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]9[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]]);
      PlotHi.Set(MACD([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]8[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]17[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]9[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] > MACD([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]8[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]17[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]9[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]]);
      [/SIZE][/FONT]

      With this:
      Code:
      if([FONT=Courier New][SIZE=2]MACD([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]8[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]17[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]9[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] < MACD([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]8[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]17[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]9[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]])
          PlotLow.Set([/SIZE][/FONT][FONT=Courier New][SIZE=2]MACD([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]8[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]17[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]9[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]]);[/SIZE][/FONT]
      [FONT=Courier New][SIZE=2]if([/SIZE][/FONT][FONT=Courier New][SIZE=2]MACD([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]8[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]17[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]9[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] > MACD([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]8[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]17[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]9[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]])[/SIZE][/FONT]
      [FONT=Courier New][SIZE=2]     PlotHi.Set([/SIZE][/FONT][FONT=Courier New][SIZE=2]MACD([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]8[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]17[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]9[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]][/SIZE][/FONT][FONT=Courier New][SIZE=2]);
      [/SIZE][/FONT]


      It can be done in a more efficient manner, but this should get you going from an intuitive straightforward standpoint.

      Any other problems it would be helpful if you could post which lines are causing a compile problem.

      mrLogik
      mrlogik
      NinjaTrader Ecosystem Vendor - Purelogik Trading

      Comment


        #4
        Thanks Verge and mrLogik. MrLogik the code lines that you identify

        PlotLo.Set(MACD(8, 17, 9)[0] < MACD(8, 17, 9)[1]);
        PlotHi.Set(MACD(
        8, 17, 9)[0] > MACD(8, 17, 9)[1]);

        are the ones that are causing the compile errors. I made the change per your advice and now it does compile. The only thing I needed to change was the spelling of Low to Lo.

        Now my problem is it does not plot anything when I add the indicator to a chart. Any ideas? Again thanks very much for your help.

        Jim

        Comment


          #5
          JT,

          If you check the LOG tab of the Control Center, it may indicate the error.

          I think what's going on is you're attempting to do a calculation on data that isn't there yet, so we have to wait until we have more than 17 bars...

          Add this as the first lines within the OnBarUpdate() call

          Code:
          if(CurrentBar <= 17)
              return;
          let me know
          mrlogik
          NinjaTrader Ecosystem Vendor - Purelogik Trading

          Comment


            #6
            Thank you!!!! mrLogik! The log did indicate the error. The indicator is plotting nicely along the MACD line. I was wondering if there is a way to set the plot location along a horizontal line?

            Thanks AGAIN for all your help!

            Jim

            Comment


              #7
              JT,

              I think the closest you can do to get this is just add another plot, and set it to 0 each bar.

              In Initialize()
              Code:
              [FONT=Courier New][SIZE=2]Add([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] Plot(Color.FromKnownColor(KnownColor.White), PlotStyle.Line, [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"HLine"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]));[/SIZE][/FONT]
              In OnBarUpdate()
              Code:
              [FONT=Courier New][/FONT]If(CurrentBar <= 17)
                  return;
              
              HLine.Set(0);
              Is that what you want see?
              mrlogik
              NinjaTrader Ecosystem Vendor - Purelogik Trading

              Comment


                #8
                Thanks again for your help mrLogik. I have been running the indicator since this am live and it works very well for what I need. Plotting it as a straight line horizontal plot would actually be less desirable. Again I appreciate all of your help with this.

                Jim

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by arvidvanstaey, Today, 02:19 PM
                0 responses
                3 views
                0 likes
                Last Post arvidvanstaey  
                Started by mmckinnm, Today, 01:34 PM
                3 responses
                5 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by f.saeidi, Today, 01:32 PM
                2 responses
                6 views
                0 likes
                Last Post f.saeidi  
                Started by alifarahani, 04-19-2024, 09:40 AM
                9 responses
                55 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by Conceptzx, 10-11-2022, 06:38 AM
                3 responses
                60 views
                0 likes
                Last Post NinjaTrader_SeanH  
                Working...
                X