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

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 bmartz, 03-12-2024, 06:12 AM
            5 responses
            32 views
            0 likes
            Last Post NinjaTrader_Zachary  
            Started by Aviram Y, Today, 05:29 AM
            4 responses
            13 views
            0 likes
            Last Post Aviram Y  
            Started by algospoke, 04-17-2024, 06:40 PM
            3 responses
            28 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by gentlebenthebear, Today, 01:30 AM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by cls71, Today, 04:45 AM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X