• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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
    }



    Paul H.NinjaTrader Customer Service

    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
        Paul H.NinjaTrader Customer Service

        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

            Paul H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by deblanka, Today, 08:56 AM
            0 responses
            3 views
            0 likes
            Last Post deblanka  
            Started by Boonfly8, Yesterday, 12:30 PM
            7 responses
            18 views
            0 likes
            Last Post sledge
            by sledge
             
            Started by Sohal, Today, 05:02 AM
            1 response
            8 views
            0 likes
            Last Post Sohal
            by Sohal
             
            Started by danitralla, Today, 03:33 AM
            0 responses
            5 views
            0 likes
            Last Post danitralla  
            Started by yeshujbp, Today, 12:37 AM
            0 responses
            14 views
            0 likes
            Last Post yeshujbp  
            Working...
            X