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

Vetoing Trading When Market Inactive

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

    Vetoing Trading When Market Inactive

    Hello there

    I've been trying to add a filter that acheives the following.

    If in 2 consecutive minutes the high is equal to the low, then don't put a trade on in the next "X" minutes. The idea being that the market is too quiet to have generated genuine signals, and therfore any signals should be ignored.

    I'm OK with the bit about locating the minutes in which the range is zero, but i'm not aware of a way of preveting the strategy from trading for a set number of minutes.

    Any suggestions greatly appreciated.

    Tks

    Ben Heaton

    BTW - tks for the new Beta, lots of great new features.

    #2
    Ben,

    I assume you are using minute bars on a liquid market? If so, then its just a bar counting excercise. For example, try something like this:

    Code:
    if (FilterConditionTrue)
       BarsUntilTrade = 2;
    else
       BarsUntilTrade = 0;
    
    if (BarsUntilTrade == 0)
    {
       // Do setup and order placement logic
    }
    else
    {
       BarsUntilTrade--  // decrement variable each bar
    }
    HTH

    Whitmark
    whitmark
    NinjaTrader Ecosystem Vendor - Whitmark Development

    Comment


      #3
      Hi there Whitlock - Yes am using liquid market and minute data - I spoke too soon in saying i understood the idea u kindly posted, as when I tried to apply it i came upon problems.

      What I cant get my head round is that in the first "else" statement you assign "BarsUntilTrade=0".

      Doesn't this effectively mean that the decrement line used later on never comes into effect, since as soon as a new bar arrives, and the condition is no longer met, BarsUntilTrade is set to zero?

      Thanks again for your input on this!
      Ben
      Last edited by BenHeaton; 03-07-2008, 12:34 PM.

      Comment


        #4
        Hi Ben,

        The logic works like this:

        1. Filter condition is met so the counter is set to 2.
        2. Then it checks BarsUntilTrade to be 0 but since it isnt zero it will decrement it to 1
        3. Next bar
        4. Filter condition true again then 2
        5. if not true then 0
        6. if 0 then execute order logic
        7. if not zero decrement by 1 again but since it was reset to 2 you may want to revisit the logic in the code sample
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Thanks Josh. Ben, let me know if this logic does not meet your needs or feel free to PM me if you like.

          Regards,

          Whitmark
          whitmark
          NinjaTrader Ecosystem Vendor - Whitmark Development

          Comment


            #6
            Hi Josh/Whitmark

            Thanks v much for the comments.

            Regarding the logic below, i'm really sorry if i'm being thick, but I have a problem with Point 5.

            I'm looking to avoid trading for "X" minutes after the occurrence of two consecutive minutes in which the High equals the Low.

            Working through an example, lets say X=20, at 9:15AM two consecutive minutes occur 9:15AM & 9:16AM) where the High equals the low, so BarsUntilTrade is set to 20.

            At 9:17 the high is greater than the low. As i understand it, according to the logic below, BarsUntilTrade would be then set to "0" - allowing the strategy to start executing trades. Wheras my objective would be for no trades to be exceuted for 20 minutes after BarsUntilTrade was initially set to 20 back at 9:16AM.

            Once again, thanks for your support here.

            Ben
            Originally posted by Josh View Post
            Hi Ben,

            The logic works like this:

            1. Filter condition is met so the counter is set to 2.
            2. Then it checks BarsUntilTrade to be 0 but since it isnt zero it will decrement it to 1
            3. Next bar
            4. Filter condition true again then 2
            5. if not true then 0
            6. if 0 then execute order logic
            7. if not zero decrement by 1 again but since it was reset to 2 you may want to revisit the logic in the code sample
            Last edited by BenHeaton; 03-08-2008, 03:00 PM.

            Comment


              #7
              Right. Which is why I said the actual code needs to be revisited. I believe Whitmark just threw up some quick pseudo code as a starting point.

              In your case just do something along those lines:
              1. when condition true barsUntilTrade=20
              2. at each next bar after condition became true decrement barsUntilTrade
              3. when barsUntilTrade hits 0 it is a greenlight so start trading
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Hi Josh

                All clear. Thanks for that. I snag I have. Is it possible to refer to an undeclared variable?

                Since, if BarsUntilTrade is yet to be declared in the bar, if I try and decrement it , an error is generated.

                Ben
                I've tried to do as u suggest, but when
                Originally posted by Josh View Post
                Right. Which is why I said the actual code needs to be revisited. I believe Whitmark just threw up some quick pseudo code as a starting point.

                In your case just do something along those lines:
                1. when condition true barsUntilTrade=20
                2. at each next bar after condition became true decrement barsUntilTrade
                3. when barsUntilTrade hits 0 it is a greenlight so start trading

                Comment


                  #9
                  Just declare it in the Variables section of your code.
                  private int barsUntilTrade = -1; or something like that.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Tks Josh - got it working - much appreciated - Ben

                    Originally posted by Josh View Post
                    Just declare it in the Variables section of your code.
                    private int barsUntilTrade = -1; or something like that.

                    Comment


                      #11
                      Ben, glad to see you wrestled to the ground the the approach I first posted about . . . sorry I was "unplugged" and away from the forum for a few days while on vacation. Thanks Josh for stepping in to clarify.

                      Regards,

                      Whitmark
                      whitmark
                      NinjaTrader Ecosystem Vendor - Whitmark Development

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by RaddiFX, Today, 10:15 AM
                      2 responses
                      14 views
                      0 likes
                      Last Post RaddiFX
                      by RaddiFX
                       
                      Started by patrickmlee007, Today, 09:33 AM
                      2 responses
                      17 views
                      0 likes
                      Last Post patrickmlee007  
                      Started by magnatauren, 08-15-2020, 02:12 PM
                      5 responses
                      206 views
                      0 likes
                      Last Post RaddiFX
                      by RaddiFX
                       
                      Started by rene69851, 05-02-2024, 03:25 PM
                      1 response
                      22 views
                      0 likes
                      Last Post rene69851  
                      Started by ETFVoyageur, Yesterday, 07:05 PM
                      5 responses
                      45 views
                      0 likes
                      Last Post ETFVoyageur  
                      Working...
                      X