Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Ignoring Trades if multiple conditions already have occurred.

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

    Ignoring Trades if multiple conditions already have occurred.

    Hello,

    I'm trying to write a simple trend following strategy in ninjascript 8. Basically, sma 50 is up and stochs cross from below 15, then buy. However, I only wish to buy on the 1st and 2nd pull backs. How can i set my script to ignore all other pull backs. I'm looking for something that can evaluate the number of pull backs that have occurred since the the price crossed the SMA from below.

    Can anyone point me in the right direction?

    Thank You

    #2
    Hello mikethelen,

    Thanks for your post.

    In terms of counting you can use an integer counter that you set/reset to 0 when you have the first cross condition. Then for each pull back, you can increment the counter. The counter's value can be used as part of the entry criteria, for example, the counter must be less than 3, thus no further entries can occur until you next reset the counter.

    For further clarity, here is a very simplified pseudo-code example:

    if (CrossAbove(Close, SMA(50), 1))
    {
    myCounter = 0; // reset previously declared int myCounter on cross of SMA
    }

    if (my pullback criteria is met)
    {
    myCounter++; // qualified pull back occured, increment counter
    }

    if (my entry conditions && myCounter < 3)
    {
    // entry conditions
    }



    Comment


      #3
      Thank you for your help. It was exactly, what i was looking for.

      I have one more question:

      Is it possible to make the code ignore the setups that happen during various slope degrees on the sma?

      For an example: I want to have a private integer for the slope degree, that i can change for testing.

      How would i code a 50 sma slope degree with the private integer as part of my conditions?

      My code is unlocked in the strategy builder.

      Thank you

      Comment


        #4
        Hello mikethelen,

        Thanks for your reply.

        Please check the help guide for slope(), including the tip shown: https://ninjatrader.com/support/help...-us/?slope.htm

        Comment


          #5
          Hello,

          I took a look at the reference that you've provided. I may be simply not grasping the concept of the code example. Where does this equation go in the slope code ? Math.Atan(Slope) * 180 / Math.PI

          Where would i be able to place my declared degree integer?

          Comment


            #6
            Hello mikethelen,

            Thanks for your reply.

            The help guide link provides an example Slope() usage and you would replace the results of the slope where it shows slope here: Math.Atan(Slope) * 180 / Math.PI

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            558 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            324 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            545 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            547 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X