Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Modify indicator to Add Color and Sound

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

    Modify indicator to Add Color and Sound

    I am trying to modify TSI standard indicator to change the color of the plot line when the direction changes and also alert with a sound signal. Any help appreciated. Thanks

    I would like to save the final "Value.Set" in the code and then use it for comparing change in direction as follows

    if Value[0] > Value[1] and Value[1] < Value[2]
    then change color of the plot line to Green and give Sound Alert
    else
    if Value[0] < Value[1] and Value[1] > Value[2]
    then change color of the plot line to Red and give Sound Alert.

    [0] represents current bar, [1] = last bar and [2] = 2 bars ago.

    Please see attached image

    Unfortunately, I could not attach the TSI code here due to size limitation.
    Attached Files

    #2
    Hello Stan,

    This will work differently depending on whether you are using version 6.5.

    See here for the multi-color plot sample for version 6.5.

    See here for the sample on this for version 7.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks Ryan,

      I will try and let you know if it works.

      Stan

      Comment


        #4
        Hi Ryan,
        I am using version 6.5.
        Any suggestion on how to convert this value

        Value.Set(fastAbsEma[0] == 0 ? 0 : 100 * fastEma[0] / fastAbsEma[0]);

        to achieve the following

        if Value[0] > Value[1] and Value[1] < Value[2]
        then change color of the plot line to Green and give Sound Alert
        else
        if Value[0] < Value[1] and Value[1] > Value[2]
        then change color of the plot line to Red and give Sound Alert.

        [0] represents current bar, [1] = last bar and [2] = 2 bars ago.

        so I can replicate this in your sample code which is


        // Plot green if the SMA is rising
        // Rising() returns true when the current value is greater than the value of the previous bar.
        if (Rising(SMA(Period)))
        {
        // Connects the rising plot segment with the other plots
        RisingPlot.Set(1, SMA(Period)[1]);

        // Adds the new rising plot line segment to the line
        RisingPlot.Set(SMA(Period)[0]);
        NeutralPlot.Reset();
        FallingPlot.Reset();
        }
        Last edited by Stan01; 07-02-2010, 01:23 PM.

        Comment


          #5
          Hi Stan01,

          Value will typically be the first plot, and you're going to want at least two. What you should do is create a custom data series to set the initial value you'd like to compare. See here for a tutorial on custom data series.

          Code:
          myDataSeries.Set(fastAbsEma[0] == 0 ? 0 : 100 * fastEma[0] / fastAbsEma[0]);
          Your custom indicator will have at least two plots.

          The plots are set conditionally based on the statements you specified, although you're now comparing your custom data series. You assign the colors for these plots either through the indicator wizard or coded in the Initialize method.

          Code:
           
          [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] (myDataSeries[[/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]] > myDataSeries[[/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]] && myDataSeries[[/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]] < myDataSeries[[/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]])[/COLOR][/SIZE][/FONT]
          [SIZE=2][FONT=Courier New]Plot0.Set(myDataSeries[[/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]);[/SIZE][/FONT]
           
          [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (myDataSeries[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]] < myDataSeries[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]] && myDataSeries[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]] > myDataSeries[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]])[/SIZE][/FONT]
          [SIZE=2][FONT=Courier New]Plot1.Set(myDataSeries[[/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]);[/SIZE][/FONT]
          [/SIZE][/FONT]
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            Hi Ryan,

            I tried doing this several different ways and somehow cannot get past the compiling errors. This last attempt, I get 2 errors and the compiler does not seem to recognize the Plot0 and Plot1 statements. Can you please take a look and see what is done incorrectly.

            Appreciate your help.

            Please see attached screen prints.

            Thanks!

            Stan.
            Attached Files

            Comment


              #7
              Stan, it seems you miss these public properties in your 'Properties' section of the code - were you creating the base code from the indicator wizard?

              Code:
               
               
              [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
              [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
              public DataSeries Plot0
              {
              get { return Values[0]; }
              }
              [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
              [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
              public DataSeries Plot1
              {
              get { return Values[1]; }
              }

              Comment


                #8
                Hi Bertrand,

                Thanks for your response. I had created the base from the wizard. I added the public properties statement to the code and it compiled fine. Added the indicator to a chart and do not see anything on the chart. Does it need Live data? I thought it would plot values from history.

                Stan.

                Comment


                  #9
                  You're welcome, yes it should work on historical data as well - any errors seen in your log tab as you run it?

                  Thanks

                  Comment


                    #10
                    I checked the log and surely there are errors. I have attached an image of the log, I am not sure how to fix this. I certainly appreciate your help.

                    Thanks!

                    Stan.
                    Attached Files

                    Comment


                      #11
                      I made this change to the code and I do see a plot only in green. Still needs some tweaking.

                      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.
                      //if (CurrentBar == 0)
                      if (CurrentBar < 2)
                      {
                      Please see attachment.
                      Attached Files
                      Last edited by Stan01; 07-04-2010, 05:12 PM.

                      Comment


                        #12
                        Good progress Stan, you likely only see the Value base plot shown, if you remove your conditions to plot - would then both plots show and become noticable if you hovered over them with the cursor and the regular databox opened?

                        You can also export the code you have now, attach it here and we'll take a further look.

                        Comment


                          #13
                          I have attached MyCustomDataSeries Script. What I am trying to achieve is a single line plot indicating green / red depending on direction change. Example is attached. Also I am trying to set up a field which has a value of 1 or -1 again depending on the direction which I can retrieve in strategies and other indicators.

                          Appreciate your help.

                          Thanks!!!!!!!!!!!!

                          Stan.
                          Attached Files

                          Comment


                            #14
                            Stan, thanks - to replicate the shot you've posted you would need to connect both Plots like in our MultiColored Plot sample here -



                            You can set a custom DataSeries to the values needed according to your conditions (1, -1) and then expose those values so they can be accessed from another script -

                            Comment


                              #15
                              Thanks! Bertrand, I have tried replicating these sample scripts you are suggesting as you can see from the thread and have errors that are beyond my programming capabilities. Looks like the NT language set is so cumbersome and needs expert knowledge to program simple things. I have done a lot of these simple modifications on my own without any help in Easy Language, but bringing it over to Ninja is a nightmare.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              591 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              342 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              103 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              555 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              552 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X