Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Builder Checking for Multiple Crossovers at Different Numerical Values

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

    Strategy Builder Checking for Multiple Crossovers at Different Numerical Values

    Hello,

    I'm playing around with a strategy idea where i'm looking at different oscillators for trending crossovers but having a problem building it in strategy builder.

    For example: the stochastic indicator, want to make a entry condition that checks for a bullish crossover at the current bar but then also looks back to check to see if the current bullish crossover is greater/above than the previous bullish crossover. So let say on the stochastic the current bullish crossover occurred at a numerical value of 40 on the indicator and the previous bullish crossover occurred at a numerical value of 20. 40 bull cross > 20 bull cross so entry condition is met.

    Any help would be greatly appreciated.

    Thanks,

    #2
    Hello Cross161,

    Can you be more specific with the logic?

    Do you want the stochastics K plot value 1 bar ago to be less than the stochastics D plot value 1 bar ago and then for the K plot to be greater than the D plot on the current bar?

    Further you want to save the value of the K plot to a variable after the above condition is true. And then later when this is true again, the current value of the K plot must be greater than the saved K plot value, saved the previous time the condition above was true?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Yes so as illustrated in the attached image looking for crosses making a higher high. So each time the K crosses the D I want to record that value and compare the next cross to see if its above the last cross.

      I have lots of experience creating inputs so I can adjust values and play around with optimizing in the strategy analyzer but I could use some help with variables. How do I create a variable that will record say the K value at the moment of crossing? Then how would I reference that in the conditions and actions? I know it would look like X condition in the left pain vs stochastic indicator in the right pain. I just don't know what X would be.


      Click image for larger version  Name:	Capture.JPG Views:	0 Size:	16.7 KB ID:	1142017

      Comment


        #4
        Hello Cross161,

        Declare a class level int variable to store a bar number. Please watch the Strategy Builder 301 and NinjaScript Editor 401 training videos if you are unsure how to declare a variable.


        Code:
        private int lastCrossBar = -1;
        
        // when the occurs set the variable to the current bar number.
        if (CrossAbove(SeriesA, SeriesB, 1))
        {
        lastCrossBar = CurrentBar;
        }
        
        // at any time, print the values of the saved bar that had the last cross occur
        if (lastCrossBar >= 0)
        {
        Print(string.Format("{0} | lastCrossBar: {1}, last cross occurred {2} bars ago, Stochastics(7, 14, 3).K[{2}]: {3}, last cross bar time: {4}", Time[0], lastCrossBar, CurrentBar - lastCrossBar, Stochastics(7, 14, 3).K[CurrentBar - lastCrossBar], Time[CurrentBar - lastCrossBar]));
        }
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks Chelsea!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          62 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          134 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          75 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          45 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          50 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X