Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Hot to limit the "opens" on short-term strategy?

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

    Hot to limit the "opens" on short-term strategy?

    Thats just another silly question from me....

    My actuall strategy is little bit bigger then the example above, but anyway, if we have such kind of strategy:

    Bars trend scalping: (on 1min bars ofc).
    If: Bar3Close < Bar2Close < Bar1Close
    To do: OpenShort.
    Target: 2 ticks.

    So.. everything works just fine, but, how to do that when he open that "short" and then close it with "profittarget" or "stopploss".... how to disable the strategy till the next bar creation?

    Because what i have here is looking like some king of OpenShort-ClosePosition spam. The strategy open "Short" right in a next second after the previous was "closed". So, strategy spam these "OpenShort" till the next bar creation.

    Then it does wait for the next bar when settlet "rules" will play and start that OrdersSpam avalanche again.


    So, how to make an RULE which will limits the strategy to open 1 position on each (for example) 2 bars. Not often!


    I bet this is a very easy task, but after searchin that forim and a NT "help", i still didnt realize how to do that.

    Same goes even for a "long-term" strategyes of mine.
    For example, if i have an MFI/RSI oversold/overbought 60min strategy.
    How to limit it to not to make more then 2 entryes onto market (lets say) often then the each 5 hours ?


    Thanks!
    Last edited by Imbah; 10-17-2008, 10:07 AM.

    #2
    Hello,


    You will want to use a condition like this to only trade when one bar has closed since your exit:
    if(BarsSinceExit("mySignal") >= 1)

    This link will help:
    DenNinjaTrader Customer Service

    Comment


      #3
      Is it possible to do that via Strategy Wizard, ors that action require manual coding?
      Im just aking that because i cant fint such paramenters in the Wizards "Sets".

      All i can do, is:

      // Condition set 1
      if (BarsSinceExit() > 2
      ============

      And there is nowhere i can find there to get the key "LongTrade/ShortTrade" (they r my signals in my strategy). So i just can setup a rule like you mention:
      "if(BarsSinceExit("mySignal") >= 1)". Just because when i choose "BarsSinseExit" menu on the left screen, there is noooway where i can choose any of my "Signals" ((( And all i can do is put ">1-2-3 etc Bars ago".



      But in that case my strategy dont do a single trade in a whole year.
      (Everything is fine, if i just remove that rule, so that just basicly meants that the OpenShort/OpenLong conditions are fine themselfs and the problem is in that exact rule (BarsSinceExit). Any clues?

      Comment


        #4
        Hello,

        Yes, "if (BarsSinceExit() > 2" will work. It just is not signal specific.

        You will find the opistion status under Strategy>Long, etc.
        DenNinjaTrader Customer Service

        Comment


          #5
          /cry


          Still....

          // Condition set 1
          if (High[0] > High[1]

          {
          EnterLong(DefaultQuantity, "");
          }

          WORKS!

          and...


          // Condition set 1
          if (High[0] > High[1]
          && BarsSinceExit() > 1)
          {
          EnterLong(DefaultQuantity, "");
          }

          Dont work.

          And thats the only one Set atm at the whole strategy. Any ideas why?

          Comment


            #6
            Hello,

            That is because you will need an initial exit in order for your second condition to evaluate to true.

            Build two conditions. One that is used for the first trade and sets a User Variable to true when that first trade is made.

            Then second condition is for all other trades that includes a condition something like this && UserVariable0 == true then add the reset of the condition you posted.

            I suggest attending one of our NinjaScript Development webinars that are offered here roughly every other week:
            DenNinjaTrader Customer Service

            Comment


              #7
              Hello once again!

              I`ve tryed to follow your adivice about "UserDefefines", but... seems so i still lose some point in it.

              Here is like my code looks now:

              protected override void Initialize()
              {
              SetStopLoss("", CalculationMode.Ticks, 8, false);
              SetProfitTarget("", CalculationMode.Ticks, 2);

              CalculateOnBarClose = false;
              }

              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
              // Condition set 1
              if (CrossBelow(TEMA(14), HMA(21), 1))
              {
              EnterShort(DefaultQuantity, "");
              Variable0 = 0;
              }

              // Condition set 2
              if (CrossBelow(TEMA(14), HMA(21), 1)
              && BarsSinceExit() >= 3)
              {
              EnterShort(DefaultQuantity, "");
              }

              // Condition set 3
              if (CrossBelow(HMA(21), TEMA(14), 1)
              && BarsSinceExit() >= 3)
              {
              EnterLong(DefaultQuantity, "");
              ======================================



              Here is how it looked like after "Backtest:




              Not a perfect strategy, but it works at least.
              And here is what kind of mess we got, when i try to run that Strategy onto "live":





              And still cant catch these points:
              1)Why strategy seems workin correctly on "backtest", but realy messup on "live" runup? Why its make an endless Entryes on market, when it have a rule "&& BarsSinceExit() >= 3)" ?



              2) You`ve said that:
              "Build two conditions. One that is used for the first trade and sets a User Variable to true when that first trade is made."

              Should i put "Variable0 == True" on the Set1 (for the first trade) as you reccomend to me? But if i do that, it looks like that then: (and i`ll receive an error message in the end (ERROR ON GENERATING STRATEGY).

              // Condition set 1
              if (CrossBelow(TEMA(14), HMA(21), 1)
              && Variable0 == true) - ERROR.
              {
              EnterShort(DefaultQuantity, "");
              Variable0 = 0;

              -----------------



              3)And therd thought about that same topic, which just visit my mind.

              We do have a rule && BarsSinceExit() >= 3).

              But my strategy only suppose to have Entryes Point (a.k.a. OpenLong/OpenShort). So maybe the problem is that, since i close my position only via "TakeProfit/StopLoss". Maybe to make it workin properly, instead of make these "takeprofit-stoplose" riles, i need to create such rule:

              // Condition set 10
              if (Performance.AllTrades.TradesPerformance.Points.Cu mProfit >= 2)
              {
              ExitShort("", "");
              ExitLong("", "");

              Comment


                #8
                Hello,


                1- Could it be that your first condition/entry is being executed over and over? Try addinng && Variable0 != 0 for your first entry.

                2- Use zero. If you use true/false you will need to change the variable type which is not supported in the Strategy Wizard for User Defined Variables.

                3- This will evaluate to true on every single tick of any bar great than 3, so you will need to limit it down to one trade like you did in #1 above.
                DenNinjaTrader Customer Service

                Comment


                  #9


                  I`ve read tha "Help" of NT 6,5.. the page about "UserVariables", and with usefull suggestions from your last reply i`ve remarked my code.

                  Now it looks like that:

                  protected override void Initialize()
                  {
                  SetStopLoss("", CalculationMode.Ticks, 4, false);
                  SetProfitTarget("", CalculationMode.Ticks, 2);

                  CalculateOnBarClose = false;
                  }

                  /// <summary>
                  /// Called on each bar update event (incoming tick)
                  /// </summary>
                  protected override void OnBarUpdate()
                  {
                  // Condition set 1
                  if (CrossBelow(TEMA(14), HMA(21), 1)
                  && Variable0 != 0)
                  {
                  EnterShort(DefaultQuantity, "");
                  }

                  // Condition set 2
                  if (CrossBelow(TEMA(14), HMA(21), 1)
                  && BarsSinceExit() >= 3)
                  {
                  EnterShort(DefaultQuantity, "");
                  }




                  The wizard dont show an "Error" to me no more now, but the strategy dont work at all. Neither on the "Backtest" neither on "Live".

                  If i understand everything correctly,the FIRST trade must be acomplished mannualy, so the "strategy" then may start to workin on its own.

                  So its look like that:

                  We create a 1min chart, add my Strategy onto "active list". (NT starts to show, that that stratery is runnin). When we make 1st trade... Open - TakeProfit.... then... then nothing happens, strategy dont make any orders even when "3 bars from exit" passed + when the "if (CrossBelow(TEMA(14), HMA(21), 1)" rule triggerin on next few bars.... automat just keep full silence and dont do anything.


                  PS: Meh... i thought that im not such a "blondy" style person.... i have a strategy created on that "NT Wizard" which based on 9 different rules (Sets) to open a position and its works quite fine.

                  But that "scalpin" strategy creation with 2 rules in it just blows my mind.

                  Comment


                    #10
                    Hello,

                    You took out an entry so I am not sure what you are trying to do exactly. I'm going to change this a little bit to make it easier for you.

                    Whichever entry you want to only happen once should have && Variable0 != 1 in the condition, then after your entry include Variable0 = 1;

                    Then in whichever entries you want to happen only after the entry described above include && Variable0 == 1 in the conditions.
                    DenNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by ETFVoyageur, Today, 07:05 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post ETFVoyageur  
                    Started by Orion815, 05-02-2024, 08:39 AM
                    2 responses
                    18 views
                    0 likes
                    Last Post Orion815  
                    Started by suroot, 02-25-2017, 04:43 AM
                    11 responses
                    2,552 views
                    0 likes
                    Last Post Zilvercat  
                    Started by Rogers101, 05-05-2024, 11:30 AM
                    16 responses
                    50 views
                    0 likes
                    Last Post Rogers101  
                    Started by ninza33, Today, 12:31 PM
                    2 responses
                    12 views
                    0 likes
                    Last Post ninza33
                    by ninza33
                     
                    Working...
                    X