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

Accessing previous values

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

    Accessing previous values

    Hello,
    I'm trying to find the moment an range bound indicator (between 0 - 100) value crossed above a previous peak made by that indicator. I can find the most recent without issue, but I'm having a difficult time finding a previous instance.
    Code:
     
    if(indicator_value[1] < indicator_high && indicator_value[0] >  indicator_high){
                    do something
     }
    So if indicator_high had a value of 60 and the above condition was true, and there was a previous peak that was greater than indicator_high, I now want to see if the indicator value will become greater than that previous peak. And there might be additional peaks that I would like to check as well.
    How does one make those past peaks unique? I did create a DataSeries for each peak.
    In addition how might one mark each those conditions in a unique way without using a variety of variables? Thanks.

    #2
    Hello CaptainAmericaXX,

    Thanks for your post.

    If you have created a dataseries and are saving the peak values does that not meet your needs here? (Comparing the current peak to previous peaks?).
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Yes the values are saved. I just can't figure out how to access an instance that meets the condition but is greater than the peak just found and happened an unspecified number of bars ago. So there could be 5 peaks that were lower than the most previous peak. I want to see if there were any greater.Is anyone willing to help me solve this issue? Thanks.

      Comment


        #4
        Hello CaptainAmericaXX,

        Thanks for your reply.

        Perhaps I am not fully understanding, can you post a charted example?

        If you have saved the previous peaks of the indicator and you now want to see if the current peak is higher could you not use MAX() with some lookback period?

        You asked, "Is anyone willing to help me solve this issue? ", as I was already assisting, are you not wanting us to assist here?
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Paul I really do appreciate your help. I wrote that last line because I wasn't sure who would respond. No hard feelings I hope. I'll work with your suggestion. Thanks.

          Comment


            #6
            Hello Paul,
            I'm not sure that MAX() will work so here is an image to help me explain myself.
            The green dots are obviously the peaks. I drew horizontal lines from the peaks to show what I eventually want my chart to look like.
            So at 9:10, as the indicator is greater than the 9:00 peak I want a line to draw.
            At 9:12 as the indicator is greater than the 8:50 peak I want a line to draw.
            At 9:15 as the indicator is greater than the 8:45 peak I want a line to draw.
            I have the peaks stored. I'm using a for loop and can draw the most recent line, but I can't get past that point.
            I'm a pitifully slow programmer so any help I can get is most appreciated.
            Attached Files

            Comment


              #7
              Hello CaptainAmericaXX,

              Thanks for your replies and clarification.

              I recommend that you consider using the swing indicator and use your indicators as the input. With the swing indicator, you can retrieve as many previous occurrences of swing points as needed (within a lookback period) as well as the value of the swing points.

              You could do a loop until Swing returns a -1 indicating no more swings in the lookback period.

              Once you found your condition (value > swinghigh point) you would then have the swing high value and bars ago needed to draw your line.
              Paul H.NinjaTrader Customer Service

              Comment


                #8
                Paul,
                Thanks for the recommendation. This looks exciting. However I am running into an issue with the Swing indicator. There's some bug I can't track down. I hate asking for debugging help, but I can't find this.
                With a swing strength of 3 all the swing peaks are showing at the correct values. Unfortunately the swing valleys are are all printing at 0. My indicator valley dots are printing correctly with the same input I'm giving the Swing. He's my indicator code.
                Code:
                //Find and Mark Peak 
                
                if(Finding_Peaks(Stochastics(Close,7,15,3).K[2],Stochastics(Close,7,15,3).K[1],Stochastics(Close,7,15,3).K[0])){
                    int high_bar = HighestBar(Stochastics(Close,7,15,3).K, 3);
                    double stoch_high = Stochastics(Close,7,15,3).K[high_bar];
                    int curr_high_bar = CurrentBar - high_bar;
                    Stoch_Peak.Set(stoch_high);
                    Stoch_Peak_Bar.Set(curr_high_bar);
                    DrawDot("High" + CurrentBar, true, Stoch_Peak_Bar[0], Stoch_Peak[0], Color.Green);
                  }
                //Find and Mark Valley 
                
                if(Finding_Valleys(Stochastics(Close,7,15,3).K[2],Stochastics(Close,7,15,3).K[1],Stochastics(Close,7,15,3).K[0])){
                   int low_bar = LowestBar(Stochastics(Close,7,15,3).K, 3);
                   double stoch_low = Stochastics(Close,7,15,3).K[low_bar];
                   int curr_low_bar = CurrentBar - low_bar;
                   Stoch_Valley.Set(stoch_low);
                   Stoch_Valley_Bar.Set(low_bar);
                   DrawDot("Low" + CurrentBar, true, Stoch_Valley_Bar[0], Stoch_Valley[0], Color.Red);
                }
                Here's the modified Swing code:
                Code:
                lastHighCache.Add(A1CrossThreshold(7, 15, 3).Stoch_Peak[0]);
                   if (lastHighCache.Count > (2 * strength) + 1)
                                    lastHighCache.RemoveAt(0);
                lastLowCache.Add(A1CrossThreshold(7, 15, 3).Stoch_Valley[0]);
                                Print(CurrentBar);
                                Print(A1CrossThreshold(7, 15, 3).Stoch_Valley[0]);
                   if (lastLowCache.Count > (2 * strength) + 1)
                                    lastLowCache.RemoveAt(0);
                When I printed the A1CrossThreshold(7, 15, 3).Stoch_Valley[0] the values are correct on the appropriate bar.
                What are your thoughts on this? Thanks.
                Attached Files

                Comment


                  #9
                  Hello CaptainAmericaXX,

                  Thanks for your reply.

                  The only difference I see is that for the high side: Stoch_Peak_Bar.Set(curr_high_bar);
                  but on the low side: Stoch_Valley_Bar.Set(low_bar);

                  If that does not resolve the issue I recommend you get down into the print statements to look at all the values being used.
                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    Hello CaptainAmericaXX,

                    I thought of another solution you may be interested in.

                    A while back I converted SwingRays2 from NT7 to NT8 and this indicator seems very similar to what you screenshot shows as the end result. I tested NT8 SwingRays2 and regrettably it only worked with the price data series.

                    I just modified it to work with an indicator as the input series and while I have not thoroughly tested it, it looks pretty good thus far. The attached picture shows it applied to the MACD indicator and retaining the broken lines. It already alerts when a line is broken and that may play into what you are after. I have attached the zipped file for you to try (if interested) and will be updating the forum file sharing indicator later after additional tests. When you apply to the chart, make sure to select your indicator as the input series and make sure you specify the same panel as the indicator as otherwise you will not see the lines.

                    Edit: The indicator option "keep broken lines" is set to false as the default so you will want to set that true to match what you are looking for (I think).
                    Attached Files
                    Paul H.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Perr0Grande, Today, 08:16 PM
                    0 responses
                    2 views
                    0 likes
                    Last Post Perr0Grande  
                    Started by elderan, Today, 08:03 PM
                    0 responses
                    3 views
                    0 likes
                    Last Post elderan
                    by elderan
                     
                    Started by algospoke, Today, 06:40 PM
                    0 responses
                    10 views
                    0 likes
                    Last Post algospoke  
                    Started by maybeimnotrader, Today, 05:46 PM
                    0 responses
                    9 views
                    0 likes
                    Last Post maybeimnotrader  
                    Started by quantismo, Today, 05:13 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post quantismo  
                    Working...
                    X