Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

rising/falling source code?

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

    rising/falling source code?

    I'm curious if there is a way to override the rising/falling functions in order to make them more strict.

    But more importantly how can I check that the SMA was rising X bars ago

    when I do

    if( Rising( SMA(20)[5] ))

    It will not compile. (for the obvious reason that sending it a double instead of data series will not work) So how can I send the data series from X bars ago.

    #2
    Use Slope().

    Comment


      #3
      thanks this looks like what I need. Can some one clarify the corelation between the slope and rising/falling? When I run it on 10 bars the SMA I get the following. I'm assuming it only looks at the first 3 decimal places to determine rising/falling b/c the neutral one is rising but not as much. Some clarification on the amount needed would be appreciated. Thank you again.

      0.0860227272727343
      rising
      0.0983333333333349
      rising
      0.110480769230753
      rising
      0.112321428571431
      rising
      0.0995833333333394
      neutral
      0.0996875000000046
      rising
      0.106764705882347
      rising
      0.108888888888896
      rising
      0.106052631578928
      rising

      Comment


        #4
        shazzmoe, the Slope() function will return the rise (change in Y) divided by the run (change in X) for the entire period you've selected. You'll have to specify the number of bars ago you'd like to check but you can just do something like this:
        Code:
        int barsAgoCheck = 5;
        if (Close[barsAgoCheck] > Close[barsAgoCheck + 1])
           // rising 5 bars ago, do something
        AustinNinjaTrader Customer Service

        Comment


          #5
          Indicator dissapearing

          Hello, im starting with Csharp, so this issue may be really silly :P

          Im trying to code the plotting of a green dot wen macd is rissing and a red dot wen is falling

          i been investigating how it gets done in other indicators and i have tried a lot of code combination (learning in the process by trial & error)

          but now im stuck wen, i cant get the both plots to work at the same time, it compiles but wen refresh the indi just disappears.


          if (MACD(fast,slow,smooth)[0] > MACD(fast,slow,smooth)[1] && MACD(fast,slow,smooth)[1] < MACD(fast,slow,smooth)[2])

          // if (Rising(Value) && Value[1] < Value[2])
          {
          DrawDot("Dots_Alerts"+CurrentBar, true, 0, Value[0], macLineUp);
          }

          if (MACD(fast,slow,smooth)[0] < MACD(fast,slow,smooth)[1] && MACD(fast,slow,smooth)[1] > MACD(fast,slow,smooth)[2])
          {
          DrawDot("Dots_Alerts"+CurrentBar, true, 0, Value[0], macLineDown);
          }
          // else RemoveDrawObject("Dots_Alerts2"+CurrentBar);


          Thank you

          Comment


            #6
            Most likely you haven't put in a check for enough bars, you should be getting an error in the log tab of the control center.

            You'll want something like this in OnBarUpdate();
            if (CurrentBar < LookbackPeriod) return;

            LookbackPeriod would be how many bars back you are comparing.

            VT

            Comment


              #7
              hehe, you were right, i added a lookback of 5 bars and that did the trick

              thank you so much

              Comment


                #8
                Macd

                Hi again, i have an other problem that appeared after i did the modifications you sugested,

                now wen i change the bool "ShowSignals" to false the entire indicator dissapears :/

                what i did wrong?



                { // Dots & Triangles
                if( showSignals && CurrentBar < 5) return;
                {
                if (Rising(Value) && Value[1] < Value[2] && mmValue > mmValueLast)
                {
                DrawDot("Dots_Alerts"+CurrentBar, true, 0, Value[0], macLineUp);
                DrawTriangleUp(CurrentBar.ToString(), true, 0, 0 - TickSize, macLineUp);
                }
                else if (Falling(Value) && Value[1] > Value[2] && mmValue < mmValueLast)
                {
                DrawDot("Dots_Alerts"+CurrentBar, true, 0, Value[0], macLineDown);
                DrawTriangleDown(CurrentBar.ToString(), true, 0, 0 + TickSize, macLineDown);
                }
                }

                Comment


                  #9
                  kabott, you would need to separate the bars check from the showSignals bool otherwise you run into the bars issue again - you would likely see a log entry in your Control Center, correct?

                  Comment


                    #10
                    Done , yes that was the problem, i changed the code the way you suggested and now works properly .
                    thank you

                    Comment


                      #11
                      Glad to hear it works!

                      Comment


                        #12
                        Sorry to bother you guys again, does someone can point me to a tutorial on how to call indicators from inside an other indicator?

                        im trying to call regression channel that has 5 lines :

                        -Top Line,
                        -Middle Top Line,
                        -Middle Line,
                        -Middle Bottom Line,
                        -Bottom Line

                        and its a bit too complicated for me to figure out how to properly call those levels

                        for instance wen High>MiddleTopLine && High<TopLine... etc

                        so.. i need a video tutorial or any tutorial, thanks again!

                        Comment


                          #13
                          kabbot,

                          You only need to do something like the following to call indicators :

                          SMA(dataseries_input , period)[index]

                          Or if it has more than one plot inside the indicator, you can use something like :

                          Bollinger(2, 20).Upper[0]

                          If you could tell me what sort of indicators you are trying to call in your indicator I could make a better recommendation.
                          Adam P.NinjaTrader Customer Service

                          Comment


                            #14
                            hi Adam , thanks for the quick reply, the idea is to re -create an indicator i had in an other platform,that has 5 lines values 0,1,2,3,4 respectively each one is the equivalent of the price been inside a level of the regression channel i mentioned before , using the High if its >than the middle level or the low if its < than the middle level.

                            like this:


                            so i have to call the regression channel from inside of what is going to be the "price stage plotting" (second panel) itself
                            and wen i build that indie , it was in easylenguage, C sharp is whole new beast for me.
                            Last edited by kabott; 11-28-2011, 02:35 PM.

                            Comment


                              #15
                              kabbot,

                              Something like this would work.

                              Code:
                              private override void Initialize()
                              {
                                   Add(new Plot(new Pen(Color.Navy, 2), PlotStyle.Bar, "Plot0"));
                                  //whatever else you need here
                              }
                              
                              private override void OnBarUpdate()
                              {
                               
                                 double current_channel = RegressionChannel(period,width).Middle[0];
                                 double standard_deviation = StdDev(period)[0];
                              
                                 //whatever else you need here
                              
                                 if ( Close[0] > current_channel + multiplier2 * standard_deviation)
                                 {
                                       Plot0.Set(2);
                                 }
                                 else if ( Close[0] <= current_channel + multiplier2 * standard_deviation && Close[0] > current_channel + multiplier1 * standard_deviation)
                                 {
                                       Plot0.Set(1);
                                 }
                                 else if( Close[0] <= current_channel + multiplier1 * standard_deviation && Close[0] > current_channel - multiplier1 * standard_deviation)
                                 {
                                       Plot0.Set(0);
                                 }
                                 else if( Close[0] <= current_channel - multiplier1 * standard_deviation && Close[0] > current_channel - multiplier2 * standard_deviation)
                                 {
                                      Plot0.Set(-1);
                                 }
                                 else if( Close[0] <= current_channel - multiplier2 * standard_deviation)
                                 {
                                      Plot0.Set(-2);
                                 }
                              
                              }
                              You will need to setup your Multiplier to be the number of standard deviations for the regression channel. From that image it looks like it may be :

                              double multiplier1 = 1;
                              double multiplier2 = 2;

                              or

                              double multiplier1 = 2;
                              double multiplier2 = 4;

                              It also looks like that indicator may be using High[0] or Low[0] instead, but hopefully that code will get you started.

                              Also, keep in mind that the RegressionChannel indicator doesn't have plots for the outside two channels as shown in your chart (which its possible to add them by coding extra plots for that indicator), but the code I wrote will do something similar to the indicator shown at the bottom of that chart screen shot.

                              If you also want to plot the regression channel, you could just add two instances of this indicator to your chart, with the width set to multiplier 1 for the first one, and multiplier2 for the second one.

                              Please let me know if I may assist further.
                              Last edited by NinjaTrader_AdamP; 11-28-2011, 03:05 PM.
                              Adam P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              648 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              369 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              108 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              572 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              574 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X