Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

strategy entering too many times

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

    strategy entering too many times

    I have a strategy that I have coded which is set to enter only one time for each direction. Once I added an ATM strategy code to manage stops and targets in live trading it began to enter multiple times rather than only once.

    Here is a snapshot of my entry code conditions. Is there something else I need to code to insure I only enter once? My "enter only once per direction" is defined in the strategy parameters setup screen and not in code.

    Code:
                    if (Position.MarketPosition == MarketPosition.Flat &&
                           Falling(CUMRSI(BarsArray[1],periodRsi,3)) &&
                        CUMRSI(BarsArray[2],periodRsi,3)[0] > upper &&
                        CUMRSI(BarsArray[0],rPeriod,3)[0] > upper)
                    {
                        AtmStrategyCreate(OrderAction.SellShort, OrderType.Market, 0, 0,
                        TimeInForce.Day, GetAtmStrategyUniqueId(), "STOCKATM2LOT",
                        GetAtmStrategyUniqueId());
    //                  EnterShort(200);
                    }
    note: This code is within BarsInProgress == 0 if statement

    #2
    Hello ShruggedAtlas,

    Thank you for your inquiry. Strategy set up parameters such as EntriesPerDirection, EntryHandling, ExitOnClose do not apply when calling the AtmStrategyCreate() method. You will need to manually adjust your code to check for entries per direction.

    An example of this can be found in our "SampleATMStrategy" method, which can be opened by going to: Tools -> Edit NinjaScript -> Strategy -> SampleATMStrategy

    Additional information on the differences between ATM strategies and NinjaScript strategies can be found in our help guide here: http://www.ninjatrader.com/support/h...strategies.htm

    If we can be of further assistance, please let us know.
    Michael M.NinjaTrader Quality Assurance

    Comment


      #3
      In the sample code, AtmStrategyCreate() function specifies "Cbi.OrderAction.Buy" What does Cbi mean? I don't see any reference to it anywhere.

      Comment


        #4
        Hello ShruggedAtlas,

        The "Cbi." prefix is just a more specific path to the library that OrderAction resides in. The more libraries that you use in a script, the more likely it becomes that various object and method names will overlap between libraries. When that happens it is both best practice and at many times required to specify which library an object or method is being called from. By default, NinjaTrader will find "OrderAction.Buy" in the "Cbi" library which is why there is no documentation on it. Unless you use another library which contains an "OrderAction" object, then
        Code:
        OrderAction.Buy
        is the same as
        Code:
        Cbi.OrderAction.Buy
        If you have any further questions, please let us know.
        Michael M.NinjaTrader Quality Assurance

        Comment


          #5
          Multi-timeframe

          Does this code need to change in any fundamental way when using a multitimeframe strategy? I'm assuming i apply these if statements within BarInProgress conditions. is that correct?

          ie:

          if(BarsinProgress == 0)
          If(historical)
          return;
          if(orderId.Length ==0........
          .........
          .........
          etc

          Comment


            #6
            Hello ShruggedAtlas,

            You are correct. You can distinguish between which data series is calling OnBarUpdate() using BarsInProgress so you know what data you are working with.

            More information on multi time frame strategies can be found in our help guide here: http://www.ninjatrader.com/support/h...nstruments.htm

            Please let us know if we can be of additional assistance.
            Michael M.NinjaTrader Quality Assurance

            Comment


              #7
              I have examined the atmstrategy sample and I do not see anything obvious that has to do with limiting the stategy to only one order per direction. That was my original problem.

              I can see the code (if statements) that help determine if my strategy has been cancelled or interrupted and resets but can someone point out the code that addresses my original issue of too many entries occurring per direction?

              Where is the code that limits the number of orders to only one per direction and/or limits the strategy to one and no more if I'm already in a trade?

              Comment


                #8
                Probably - if that is the code - You are missing {} which allows for multiple statements.
                Without - ONLY and ONLY the next logic is executed.

                So your BarsInProgress==0 check only belows to if (historical) return;

                It does NOT apply to if (orderId.....)

                so if (orderId....) and any following logic is run for EVERY BarsInProgress (if that is your intention).. given that you are having problems - I'm not so sure.




                Originally posted by ShruggedAtlas View Post
                Does this code need to change in any fundamental way when using a multitimeframe strategy? I'm assuming i apply these if statements within BarsInProgress conditions. is that correct?

                ie:

                if(BarsinProgress == 0)
                If(historical)
                return;
                if(orderId.Length ==0........
                .........
                .........
                etc

                Comment


                  #9
                  Thanks for looking at this sledge. I am actually using the {} brackets.

                  here is one of the conditions:

                  Code:
                              if( BarsInProgress == 0 )
                              {            
                                  // Condition set 1
                                  if (orderId.Length == 0 && atmStrategyId.Length == 0 &&
                                         Falling(CUMRSI(BarsArray[1],periodRsi,3)) &&
                                      CUMRSI(BarsArray[2],periodRsi,3)[0] > upper &&
                                      CUMRSI(BarsArray[0],rPeriod,3)[0] > upper)
                                  {
                                      atmStrategyId = GetAtmStrategyUniqueId();
                                      orderId = GetAtmStrategyUniqueId();
                                      
                                      AtmStrategyCreate(OrderAction.SellShort, OrderType.Market, 0, 0,
                                      TimeInForce.Day, orderId, "EURUSD",atmStrategyId);
                  //                  EnterShort(200);
                                  }
                  I've not changed the code much and although I haven't experimented yet, I'm assuming the revised strategy will still give multiple entries since I don't see anything in the sample code that was recommended to me that solves my problem.
                  Last edited by ShruggedAtlas; 05-27-2015, 07:17 PM.

                  Comment


                    #10
                    I don't use Atm Strategies ... I found this in the help guide... I'm guessing you've seen this.

                    So if you're using NT's EntriesPerDirection you are out of luck.

                    Maybe that is what your logic here is doing:

                    if (orderId.Length == 0 && atmStrategyId.Length == 0 &&




                    NinjaScript > Educational Resources > Developing Strategies >
                    Using ATM Strategies
                    Print this Topic Previous pageReturn to chapter overviewNext page
                    You can create an automated strategy that generates a trade signal that executes a NinjaTrader ATM Strategy.

                    • ATM Strategies operate in real-time only and will not execute on historical data thus they can't be backtested
                    • Executions resulting from an ATM Strategy that is created from within a NinjaScript automated strategy will not plot on a chart during real-time operation
                    Strategy set up parameters such as EntriesPerDirection, EntryHandling, ExitOnClose do not apply when calling the AtmStrategyCreate() method

                    There is a Clear Line...
                    There is a clear line between a NinjaScript Strategy and an ATM Strategy. The use model for creating an ATM Strategy within a NinjaScript Strategy is when you want to programmatically monitor and generate an entry signal and then manualy manage the resulting open position via an ATM Strategy in one of NinjaTrader's order entry windows.

                    !!! IMPORTANT: Manually Closing an ATM Strategy from an Order Entry Window such as the SuperDOM
                    It is crucial that when running ATM Strategies created by a NinjaScript strategy that you understand how to properly manually close the ATM Strategy from any of the order entry windows.

                    • If the order entry window ATM Strategy Selection Mode is NOT in "DisplaySelectedATMStrategyOnly" click on the "CLOSE" button via your middle mouse button (scroll wheel)
                    • If the order entry window ATM Strategy Selection Mode is in "DisplaySelectedATMStrategyOnly" you can click on the "CLOSE" button with your left mouse button to close the selected active ATM strategy

                    Following the approaches above will internally close the ATM Strategy. Not following the approach will close the account/instrument position, terminate all strategies and cancel all orders. The result is that your NinjaScript strategy will be terminated.

                    Comment


                      #11
                      So basically you're saying sludge that if those variables are 0 and my conditions are met the atm strategy kicks in but once an atm strategy is active they become > 0 and my entry conditions are ignored. I think I see now.

                      Comment


                        #12
                        I'm not sure I'm saying that. I think I'm saying I'm in over my head on this one.

                        I would use the output window and judicious use of Print statements of those variables to see what's exactly going on.

                        Print('orderId.Length ==' + orderId.Length + " atmStrategyId.Length=' + atmStrategyId.Length );

                        Comment


                          #13
                          I actually think you are right. I have made a small tweek to the code and am now running it at this very moment on a forex trade. So far so good. the atm strategy has kicked in and I'm monitoring to see if it only makes the one trade or if it continues to enter multiple times. I'm confident that it is working.

                          Comment


                            #14
                            Hello ShruggedAtlas,

                            I apologize for the delay. I am pleased to hear that everything is now working so far as intended. If you run into any additional issues, please let us know and we will be happy to assist.

                            Thanks!
                            Michael M.NinjaTrader Quality Assurance

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by philmg, Today, 01:17 PM
                            0 responses
                            1 view
                            0 likes
                            Last Post philmg
                            by philmg
                             
                            Started by cre8able, Today, 01:01 PM
                            1 response
                            4 views
                            0 likes
                            Last Post NinjaTrader_ChelseaB  
                            Started by manitshah915, Today, 12:59 PM
                            1 response
                            3 views
                            0 likes
                            Last Post NinjaTrader_Erick  
                            Started by ursavent, Today, 12:54 PM
                            1 response
                            4 views
                            0 likes
                            Last Post NinjaTrader_Jesse  
                            Started by Mizzouman1, Today, 07:35 AM
                            3 responses
                            17 views
                            0 likes
                            Last Post NinjaTrader_Gaby  
                            Working...
                            X