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

Example of how ot use an ATM Strategy in NT8 strategy...

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

    Example of how ot use an ATM Strategy in NT8 strategy...

    Do you have an example of how to include and use an ATM strategy in C# strategy?

    #2
    Have a look at “unmanaged approach” and “AddOn-Development”.

    Comment


      #3
      Hello morrnel,

      Thanks for your post.

      Yes, included with the platform is the strategy SampleAtmStrategy which demonstrates calling an ATM template that is applied when the strategy entry has been filled, Please review the strategy in the Ninjascript editor as the code has been well commented to help clarify the requirements for running the example as well as how the methods and properties work. Once the ATM is active, you can manually move the profit and stop if you wish. Once the stop or profit is hit, the strategy will reset and perform the next entry. The example strategy will only place long orders based on this simple entry condition: Close[0] > Open[0].

      A Ninjascript strategy that works with ATM uses special methods and properties, these can be found here: https://ninjatrader.com/support/help...gy_methods.htm

      You can find a further example of using ATMs in a Ninjascript strategy in the NT user apps NinjaTrader8 Strategy section, here is a link to the example for your convenience: https://ninjatraderecosystem.com/use...tegy-reversal/ Please note: The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
      Paul H.NinjaTrader Customer Service

      Comment


        #4
        hello
        can i ask for help here or do i need to create my own post

        Comment


          #5
          Hello jhontorres,

          Thanks for your post and welcome to the NinjaTrader forums!

          You are welcome to post here if your questions directly relate specifically to the thread topic, "Example of how to use an ATM Strategy in NT8 strategy...".

          If they don't then please do start a new topic. To start a new topic you would need to navigate back to "forum" page here: https://ninjatrader.com/support/forum/forum the click on the particular forum that would best relate such as NinjaTrader 8 strategy or NinjaTrader 8 indicator. The forum will then show all of the topics in that forum. To create a new topic in that forum, click the light blue "topic button. I've attached an example of that.

          Click image for larger version

Name:	ForumnewTopic.PNG
Views:	606
Size:	59.2 KB
ID:	1112001
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            yes so what happened is that i created a strategy with the atm example strategy and for some type of reason is only place buy order

            Comment


              #7
              Hello jhontorres,

              Thanks for your reply.

              The reason that it places only buy orders is that is what it was programmed to do, so it is operating as expected. The entry condition is simply if the position is flat to then place a buy order based on Close[0] > Open[0]. This is an example strategy to demonstrate the capability of using an ATM template with a Ninjascript strategy. It is not intended to be a useable/profitable strategy. In the code of the strategy, it explains how the special methods used work. You can read more about them here: https://ninjatrader.com/support/help...gy_methods.htm

              Paul H.NinjaTrader Customer Service

              Comment


                #8
                okay and thank you sir

                Comment


                  #9
                  Hello, I hope I can post my ATM issue here.

                  I developed a strategy based on the SampleATMReversal example. The strategy has two types of entries. The second type (TYPE 2) entry should only enter orders if the TYPE 1 entry status is FLAT, so only one order is active.

                  ISSUE: Sometimes the entries are made as expected (Type 2 after Type 1 is flat), and other times both entries are made in sequence, as shown in the attached screenshot. Again, TYPE 2 entry should only be activated if TYPE 1 is FLAT.

                  I've tried everything but cannot find the cause of the problem. May I please ask for your insight and help?

                  Thank you. BobPerez

                  Code:
                              #region SHORT TYPE 1 REVERSAL entry
                                  bool sepCortoOk = some condition) ;
                  
                                  double diffC = some condition;
                  
                                  // If Entry Conditions Are Met
                                  if ((sepCortoOk && EmaPos == -1 && Close[0] < Open[0] && conDireccionC
                                      && EstadoC == 1 && condicion_Standard)
                                       )
                                  {
                  
                                      Draw.ArrowDown(this,"largo"+CurrentBar,false,0,High[0]+2*TickSize,Brushes.Yellow);
                                      Print(Convert.ToString(Times[0][0]) + "Diferencia corto: " + Convert.ToString((SMA1[0])-EMA1[0]  ));
                                      EstadoC = 2;
                  
                                      // Set variable to true to enter order  
                                      condicion_C_Rev = true;  
                                  }
                                  #endregion
                  
                                  #region SHORT Continuation TYPE 2 entry
                  
                                  shortFlat = (shortOrderId.Length == 0 && shortAtmId.Length == 0 && !isShortAtmStrategyCreated) ? true : false;
                  
                                  /// I TRIED ALL THIS BUT DOES NOT SEEM TO RECOGNIZE THE FLAT STATUS OF TYPE 1 ENTRY
                                  //shortFlat = false;
                                  //if(shortAtmId.Length != 0)    
                                  //{    
                                     //if (GetAtmStrategyMarketPosition(shortAtmId) == Cbi.MarketPosition.Flat)
                                      //if(!isShortAtmStrategyCreated)
                                      //     shortFlat = true;
                                  //}
                  
                                  //if (GetAtmStrategyMarketPosition("shortAtmId") == Cbi.MarketPosition.Flat)
                                  //    Print("ATM Strategy position shortATMId is currently flat");
                  
                                  //if (isShortAtmStrategyCreated)
                                  //    Print("isShortAtmStrategyCreated");
                  
                                  // Entry Conditions
                                  bool okCon = tradesCorto > 0   && Close[0] < Open[0]  && Close[0] < Close[1]
                                      && conDireccionC && EmaPos ==-1
                                      && EstadoC == 2 && isFlat && !condicion_C_Rev
                                      && ContCounterC == 0
                                      && !isShortAtmStrategyCreated
                                      && shortFlat
                                      //&& GetAtmStrategyMarketPosition(shortAtmId) == Cbi.MarketPosition.Flat (GENERATES ERROR)
                                      && condicion_Standard;
                  
                                  if (okCon
                                      && shortOrderId.Length == 0
                                      && shortAtmId.Length == 0  
                                      && !isShortAtmStrategyCreated
                                      //&& shortOrderId.Length == 0 && shortAtmId.Length == 0  && !isShortAtmStrategyCreated) //&& sepCortoOk (DOES NOT WORK)
                                      )
                                  {
                                      //condicion_C_Con = GetAtmStrategyMarketPosition(shortAtmId) == Cbi.MarketPosition.Flat ? true: false ;
                  
                                      // Set entry variable to true 
                                      condicion_C_Con = true;
                                      Draw.ArrowDown(this,"largo"+CurrentBar,false,0,High[0]+2*TickSize,Brushes.Aquamarine);
                                      //EstadoC = 0;
                                  }    
                              //}    
                                      Print(Convert.ToString(Times[0][0]) + "condicion_C_Con " + condicion_C_Con );
                              #endregion
                  
                              // Enter short ( BASED ON SAMPLEATMREVERSAL)
                              #region Enter short
                  
                              // Enter if entry conditions were met 
                              if(condicion_C_Rev || condicion_C_Czy || condicion_C_Con )
                  
                              {
                              //    Print("Short condition at " + Time[0]);
                                  // If there is a long ATM Strategy running close it.
                                  if(longAtmId.Length != 0  && isLongAtmStrategyCreated )
                                  {
                                      AtmStrategyClose(longAtmId);
                                      isLongAtmStrategyCreated = false;
                                  }
                                  /*if(shortAtmId.Length != 0 && isShortAtmStrategyCreated && condicion_C_Rev)
                                  {
                                      AtmStrategyClose(shortAtmId);
                                      isShortAtmStrategyCreated = false;
                                  }
                                  */
                                  // Ensure no other short ATM Strategy is running.
                                  if(shortOrderId.Length == 0 && shortAtmId.Length == 0  && !isShortAtmStrategyCreated)
                                  {
                                      Print(Convert.ToString(Times[0][0]) + "11111condicion_C_Con " + condicion_C_Con );
                                      shortOrderId = GetAtmStrategyUniqueId();
                                      shortAtmId = GetAtmStrategyUniqueId();
                                      AtmStrategyCreate(OrderAction.SellShort, OrderType.Market, 0, 0, TimeInForce.Day, shortOrderId, "AtmStrategyTemplate", shortAtmId, (atmCallbackErrorCode, atmCallBackId) => {
                                          //check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
                                          if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == shortAtmId)
                                          {    
                                              isShortAtmStrategyCreated = true;
                  
                                              // (these variables were inserted by me and are ok)
                                              tradeCounter++;
                                              tradesCorto ++;
                                              if(condicion_C_Czy) CzyCounterC++;
                                              if(condicion_C_Con) ContCounterC++;
                                      Print(Convert.ToString(Times[0][0]) + "tradesCorto " + tradesCorto );
                                          }    
                                      });
                                  }
                              }
                              #endregion
                              // End entries.
                      ​
                  Click image for larger version  Name:	ATMStratIssue.png Views:	0 Size:	35.6 KB ID:	1224382
                  Last edited by bobperez; 11-19-2022, 06:21 PM.

                  Comment


                    #10
                    Hello bobperez,

                    Thanks for your note.

                    When you say TYPE 1 should be flat, do you mean that the shortFlat bool evaluates to false?

                    If the condition to place the order is sometimes submitting when expected and not submitting the other other times, this means the condition to place that order is not becoming true.

                    To understand how the script is processing logic, you would need to add prints on the line above the condition(s) to place the order that prints out each variable used to place that order. This will allow you to compare the prints to see if the condition to place the order is evaluating as true or false and why that is.

                    Also, enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.

                    Below is a link to a forum post that demonstrates how to use prints to understand behavior.

                    https://ninjatrader.com/support/foru...121#post791121

                    Let us know if we may assist further.​
                    Brandon H.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks, Brandon, I'll try that.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by nandhumca, Yesterday, 03:41 PM
                      1 response
                      12 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by The_Sec, Yesterday, 03:37 PM
                      1 response
                      11 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by vecnopus, Today, 06:15 AM
                      0 responses
                      1 view
                      0 likes
                      Last Post vecnopus  
                      Started by Aviram Y, Today, 05:29 AM
                      0 responses
                      5 views
                      0 likes
                      Last Post Aviram Y  
                      Started by quantismo, 04-17-2024, 05:13 PM
                      3 responses
                      27 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Working...
                      X