Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ATM Strategy settings in Automated Strategy

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

    ATM Strategy settings in Automated Strategy

    If I have ATM strategy setting that I like how can I integrate them into my Automated Strategy so that it will trade in the same fashion? I found it most interesting that there is no selection for ATM strategy selection in the wizard so that known ATM strategies can be incorporated straightforwardly into an automated strategy.

    Any help or code example would GREATLY be appreciated, my knowledge of the method to accomplish this is zero.

    #2
    TxChristopher,

    There is a reference sample that comes with NinjaTrader. It is in Tools > Edit NinjaScript > Strategy > SampleATMStrategy. This shows you an example on how to incorporate ATM's into a auto-strategy.

    Here is our help guide entry on this : http://www.ninjatrader.com/support/h...gy_methods.htm
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Ok I found the example and I get that to make use of my existing ATM strategy I need to replace "AtmStrategyTemplate" with the the actual name of the ATM strategy template that I had previously created, but where in the code would the sample then go?

      I created a simple EMA cross Automated Strategy like this:


      ///</summary>
      protectedoverridevoid Initialize()
      {
      Add(ZeroLagEMA(FastEMA));
      Add(ZeroLagEMA(SlowEMA));
      Add(ZeroLagEMA(SlowEMA));
      Add(ZeroLagEMA(FastEMA));
      SetProfitTarget(
      "", CalculationMode.Ticks, ProfitTarget);
      SetStopLoss(
      "", CalculationMode.Ticks, StopLoss, false);
      CalculateOnBarClose =
      true;
      }
      ///<summary>
      /// Called on each bar update event (incoming tick)
      ///</summary>
      protectedoverridevoid OnBarUpdate()
      {
      // Condition set 1
      if (CrossAbove(ZeroLagEMA(FastEMA).ZLEMA, ZeroLagEMA(SlowEMA).ZLEMA, 1))
      {
      EnterLong(DefaultQuantity,
      "");
      }
      // Condition set 2
      if (CrossAbove(ZeroLagEMA(SlowEMA).ZLEMA, ZeroLagEMA(FastEMA).ZLEMA, 1))
      {
      EnterShort(DefaultQuantity,
      "");
      }
      }


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

      So do I then replace the section of the order entry with the ATM code? In other words bye bye "EnterShort(DefaultQuantity, "");" and instead the ATM code?

      It is not clear to me how the Automated Strategy "hands off the order control" to the ATM strategy.

      Comment


        #4
        Tx,

        You need to use AtmStrategyCreate() instead of EnterLong() or EnterShort(). The ATM Strategy mode is totally different than the managed mode you show here. ATMStrategyCreate() will enter an order for you.

        You can replace "AtmStrategyTemplate" with the name you gave your ATM strategy when you created it.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Ok I think I understand. When using this method of AtmStrategyCreate() will it still function the same when it comes time to reverse? As in if you are doing MA crosses and it is in a long and the cross switches will it close and go short like the original does?

          Comment


            #6
            Also can it be tested against Market Replay data?

            Comment


              #7
              TxChristopher,

              With ATM strategies you would want to cancel the previous running ATM strategy first.

              As far as market replay, this is the only way to backtest a strategy that uses ATM strategies currently as it won't work in the Strategy Analyzer.

              Please let me know if I may assist further.
              Adam P.NinjaTrader Customer Service

              Comment


                #8
                AdamP,

                I added in the code AtmStrategyCreate() when the conditions are met (simple EMA cross) but when I run the strategy in sim mode it does not behave properly. It enters orders and sets a stop loss and the profit target but it never moves the stops according to the stop strategy associated with the ATM strategy and the order types are not the same as the ATM strategy that is called to handle the order flow. Can you see an error in the code?
                Attached Files

                Comment


                  #9
                  TxChristopher, first of all why are you setting a limit price to submit it for a market order? This is something you would not need for market orders, they are filled at the best next price possible.

                  Next, you would need to include a check in your ATM strategy create as well to create a new atm only if the order id and strategy id are in a reset state.

                  To see exactly how this would be done, please refer to the example we preinstall with NinjaTrader called 'SampleAtmStrategy'.
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Not sure how I can reference the supplied example ATM Strategy code any more than I did when I copied the sample code of the 'SampleAtmStrategy' verbatim and inserted into the base simple cross strategy above, replacing the EnterLong() and EnterShort(). The types of orders were determined by that not by me.

                    I am learning this as much as I can as I go if there is an error then point it out please and i will try to correct it.

                    Comment


                      #11
                      You would not reference the sample, but use it as a base for making your own, it contains code comments as well that outline the general approach needed - for example you miss those checks in your entry logic -

                      if (orderId.Length == 0 && atmStrategyId.Length == 0 && yourConditionHere)
                      {
                      do AtmStrategyCreate()...
                      }
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        Hmmm ok so there are more checks needed in the initial assessment on whether to enter or not I will try to make these changes.

                        I took out the low[0] and high[0] parts of the order and replaced them with 0's I guess that would fix the limit order problem.
                        Last edited by TxChristopher; 07-20-2012, 08:17 AM.

                        Comment


                          #13
                          Correct, those checks are needed to ensure you're not continuously creating new entries / ATM's. The ATM strategy methods are not governed by the order handling rules of the managed approach that would seek to prevent such scenarios, however at the expense of this it does provide you with more flexibility then.
                          BertrandNinjaTrader Customer Service

                          Comment


                            #14
                            I am running into problems when cresting a strategy with the wizard, when I get to the end and click "finish" it will make the failure sound and show errors from a different strategy. It also does this if i try to compile any strategy, it will come up saying there are errors in a totally different strategy. Ideas?

                            Comment


                              #15
                              The problem is generating from the if (orderId.Length == 0" portion I added for the check, the error is "The name 'orderId' does not exist in the current context"

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Kaledus, Today, 01:29 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post Kaledus
                              by Kaledus
                               
                              Started by PaulMohn, Today, 12:36 PM
                              1 response
                              16 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by yertle, Yesterday, 08:38 AM
                              8 responses
                              37 views
                              0 likes
                              Last Post ryjoga
                              by ryjoga
                               
                              Started by rdtdale, Today, 01:02 PM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Started by alifarahani, Today, 09:40 AM
                              3 responses
                              19 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X