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

BarsSinceExit()

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

    BarsSinceExit()

    Hi.
    Any hints on the following would be useful.
    As part of a condition for trade entry, would like to implement following:

    BarsSinceExit() > 1

    However, to have this line of code, it would appear that there is a need to have a reference somewhere else in the strategy that a trade has been executed previously otherwise the above does not work, & if the above line is one of the conditions of entry, no trades are executed. Hope this makes since.

    if use BarsSinceEntry() as a condition of exit, however, it executes as would expect since trade has already been entered!

    Hope you are able to assist here with some general direction.

    thx
    David

    #2
    Like you have noticed if you never entered before then BarsSinceExit() will never be greater than 1. To address this you need to have a separate set of entry conditions for your first entry.

    Code:
    if (BarsSinceEntry() > 0)
    {
       if (BarsSinceExit() > 1)   //All entries after first entry has to be at least 1 bar since last exit
              EnterLong();
    }
    else  //First entry
    {
       EnterLong();
    }
    Attached Files
    Last edited by NinjaTrader_JoshP; 08-16-2007, 03:55 PM.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Hey thx for the response. Greatly appreciated. I also found another way when hunting through the support forum.....this appears to work also.

      BarsSinceExit() > 1 || BarsSinceExit() == -1

      thx. David

      Comment


        #4
        Hello Josh,

        i used your attached samplefile to create my strategy.
        The conditions do work perfect, but i have the problem, that its only working on one day.

        e.g. i use in the data series "day to load" 10 days, then i only get shown the results on the second day of the period, in this case day 2 of 10.
        every following day no trade gets executed.

        Do i have to reset anyting somehow that the strategy does work again on the following day ?

        The code i implemented is:
        protected override void OnBarUpdate()
        if (BarsSinceEntry() > 0)
        if (BarsInProgress == 0 && BarsSinceExit() == 1 && conditons
        else
        if (BarsInProgress == 0 && conditions

        ...do something...

        It would be great if you could give me a hint how i could get it working.
        Thank You !

        Comment


          #5
          Hello nt2010,

          You'll have to verify the values for your conditions, to make sure they're what you expect. Print() all values for your entry conditions so you know what's used.


          You also might want to look at your branching structure. Some basic examples to work from are available here:
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            Hi Ryan,

            thank you for your fast answer. Its less the result of the strategy but more the point that it only shows an effect on one day. I attached a picture and the simple code file for the problem. I dont know what i have to do, that it makes/shows the trades each day.

            It would be great if you could have a look at it.

            Thank you for your help
            NT2010
            Attached Files
            Last edited by nt2010; 01-10-2011, 03:34 PM.

            Comment


              #7
              I took a look at your strategy code. I also gave it a run here and get orders beyond only the second day. I see only one series - is there any reason your strategy checks for specific BarsInProgress? This is typically only used for multiseries strategy.

              The process for identifying strategy behavior still comes down to printing all values, verifying them and tracking any messages related to order submission.

              Your entry condition works with BarsSinceEntry and and BarsSinceSession. These are the properties you'll want to check with print statements.

              Print(BarsSinceEntry());
              Print(Bars.SinceSession);

              Check your branching structure to make sure the code is flowing the way you expect. Add print statements at various points to verify code is executed.

              else
              {
              Print("Else Block Executed");
              if (BarsInProgress == 0 && Bars.BarsSinceSession == 0 )//First entry
              {
              EnterLong();
              Print("if Condition after else block executed");
              }
              }

              You should also consider adding a signal name tag so you can see which order statements are the ones placing order on that day.

              If all your values check out, then look at the flow of order submission with TraceOrders output.
              Ryan M.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Max238, Today, 01:28 AM
              1 response
              22 views
              0 likes
              Last Post CactusMan  
              Started by giulyko00, Yesterday, 12:03 PM
              2 responses
              10 views
              0 likes
              Last Post giulyko00  
              Started by r68cervera, Today, 05:29 AM
              0 responses
              4 views
              0 likes
              Last Post r68cervera  
              Started by geddyisodin, Today, 05:20 AM
              0 responses
              6 views
              0 likes
              Last Post geddyisodin  
              Started by JonesJoker, 04-22-2024, 12:23 PM
              6 responses
              38 views
              0 likes
              Last Post JonesJoker  
              Working...
              X