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

AtmStrategyCreate() and BarsSinceExit()

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

    AtmStrategyCreate() and BarsSinceExit()

    Hello,

    I'm new to Ninja Trader but am enjoying what I have experienced so far.

    My question -

    Am I able to use the BarsSinceExit() method with the AtmStrategyCreate() method?

    The purpose -

    I am looking to only reenter a trade after a number of bars have passed in order to reduce the amount of trades that are generated during certain conditions.

    If someone would not mind providing an example I would greatly appreciate it.

    #2
    Hello AlienKnowledge,

    Thanks for your post and welcome to the forums!

    Yes you can use BarSinceExit method with AtmStrategyCreate method.

    For example:

    Code:
    if (yourentryconditions && (BarsSinceExit() > 10 || BarsSinceExit() == -1))
    {
    AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0,
                TimeInForce.Day, GetAtmStrategyUniqueId(), "MyTemplate",
                GetAtmStrategyUniqueId()); [COLOR="SeaGreen"] // using example from helpguide here[/COLOR]
    }
    The BarsSinceexit requires two checks, the first one is the number of bars that you specify (10 in the example shown), the second check is -1 indicates that there has been no previous order, so would be for the very first order, otherwise without the -1 check the if statement would never fire.

    Here are the helpguide references for both:

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      NT_Paul - Thank you for providing the examples, I've been working on incorporating them today.

      The Issue - BarsSinceEntry appears to not work as intended

      I am running into an issue where a -1 value is returned for BarsSinceEntry, at least from what I see in the output window and also from manually counting the last exit and the next entered trade. It appears that the BarsSinceEntry is not working as I would like.

      Source Code Currently in Use -

      // LONG ENTRY
      if (orderId.Length == 0 && atmStrategyId.Length == 0 && RSI(14, 3)[0] <= RSIenterLong && (BarsSinceExit() > 10 || BarsSinceExit() == -1))
      {
      atmStrategyId = GetAtmStrategyUniqueId();
      orderId = GetAtmStrategyUniqueId();

      AtmStrategyCreate(Cbi.OrderAction.Buy, Cbi.OrderType.Market,
      0, 0, TimeInForce.Gtc, orderId, "ATM-Test-DRPepper", atmStrategyId);

      //Debugging Info
      Print("---------------------BEGIN TRADE INFO----------------------");
      Print(
      "LONG POSITION -+- ");
      Print(
      "BarsSinceExit Value is: " + BarsSinceExit().ToString());

      }

      Any ideas you could provide to aid my journey

      Comment


        #4
        Hello AlienKnowledge,

        Thanks for your reply.

        The BarsSinceExit() would be -1 if there was no previous exit, so the very first trade of the day would have no previous exit thus the condition of BarsSinceExit() > 10 could never be true so the -1 is used to indicate that there were no previous exits from a trade.

        Are you running this in a multi-series script?
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          NT_Paul,

          Thank you for the explanation regarding BarsSinceExit() -1 status, this I understand.

          With that said, I seem to be running into trouble of getting BarsSinceExit to capture trade exit data. I have placed (BarsSinceExit() > 10 || BarsSinceExit() == -1)) in various parts of the code but to no avail.

          The following screenshot has a green vertical line for trade entry, a light blue line for trade exit, and a purple line for the next trade entry. The next trade should not occur until after 10 bars have passed - yet the trade has executed immediately.

          Click image for larger version

Name:	BarsSinceExit-notworking.png
Views:	1
Size:	42.5 KB
ID:	873567

          Here is the code that I am currently working on: BarsSinceExit.zip
          I have placed //comments within the code to indicate where I tried placing the BarsSinceExit() code snippet.

          Your guidance is much appreciated.


          Note - I am not running a multi-series script as of yet, but plan on doing so as I continue to build this strategy out.
          Last edited by AlienKnowledge; 05-11-2015, 08:02 PM.

          Comment


            #6
            Hello AlienKnowledge,

            Thanks for your reply.

            Regrettably I was incorrect in advising that BarsSinceExit() works with ATMStrategies as it does not.

            Alternatively you can add code to capture the bar number of the exit bar by using GetAtmStrategyStopTargetOrderStatus() to check the status as filled and then saving CurrentBar into an int variable.

            You can then compare (CurrentBar - the saved bar number) against however many bars you wanted to exist between the last exit and your next entry.

            Here is the link for GetAtmStrategyStopTargetOrderStatus(): http://www.ninjatrader.com/support/h...rgetorders.htm
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              No Worries

              NT_Paul,

              Thank you for providing a new direction for me to try, I appreciate it. Glad to know that BarSinceExit does not work with ATM strategies. This should help others in the future.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by TraderBCL, Today, 04:38 AM
              2 responses
              16 views
              0 likes
              Last Post TraderBCL  
              Started by martin70, 03-24-2023, 04:58 AM
              14 responses
              106 views
              0 likes
              Last Post martin70  
              Started by Radano, 06-10-2021, 01:40 AM
              19 responses
              609 views
              0 likes
              Last Post Radano
              by Radano
               
              Started by KenneGaray, Today, 03:48 AM
              0 responses
              5 views
              0 likes
              Last Post KenneGaray  
              Started by thanajo, 05-04-2021, 02:11 AM
              4 responses
              471 views
              0 likes
              Last Post tradingnasdaqprueba  
              Working...
              X