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 fx.practic, 10-15-2013, 12:53 AM
            5 responses
            5,403 views
            0 likes
            Last Post Bidder
            by Bidder
             
            Started by Shai Samuel, 07-02-2022, 02:46 PM
            4 responses
            94 views
            0 likes
            Last Post Bidder
            by Bidder
             
            Started by DJ888, Yesterday, 10:57 PM
            0 responses
            6 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by MacDad, 02-25-2024, 11:48 PM
            7 responses
            158 views
            0 likes
            Last Post loganjarosz123  
            Started by Belfortbucks, Yesterday, 09:29 PM
            0 responses
            8 views
            0 likes
            Last Post Belfortbucks  
            Working...
            X