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

Call ATM in Strategy - working (simple) example needed

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

    Call ATM in Strategy - working (simple) example needed

    Hi,

    I have designed some quite basic strategies with the Strategy Builder. Now I would like to implement an "ATM template" (that has trailing stop and take profit defined) into a strategy.

    I though have no clue howto call the ATM in a strategy that I have built. Could anyone kindly show me an working example with an strategy that uses an ATM inside?

    Thanks in advance!

    br,
    Christian

    #2
    Hello Christian,

    Thanks for your post.

    The strategy builder does not contain an interface to work with ATM strategies.

    To work with an ATM template within a strategy you would need to work directly in Ninjascript code. Here is a link to the methods that are available in Ninjascript for working directly with an ATM template: http://ninjatrader.com/support/helpG...gy_methods.htm

    To further assist, in your NinjaTrader platform is an example strategy that demonstrates the coding needed to use an ATM strategy template. The strategy is named SampleATMstrategy. The sample is documented in the code section to clarify how it all works. To use the example strategy you would need to create a an ATM template called "AtmStrategyTemplate" with profit and stop targets you define. The example only enters long orders and is intended as an example only.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi,

      Thanks for the reply!

      I had a look at the sample last week but I could not understand based on what it will take on a long entry?

      For example, if I had an simple MA cross over strategy, that is takin long position when price crosses over a moving average, how would such a strategy with an ATM look like?

      br,
      Christian

      [EDIT] Found an example here: http://ninjatrader.com/support/helpG...gy_methods.htm

      [EDIT2] I guess the code below will enter long when price cross above MA20 and then use MyTemplate ATM for managing the position?

      Code:
      private string atmStrategyId;
      private string atmStrategyOrderId;
      private bool   isAtmStrategyCreated = false;
       
      protected override void OnBarUpdate()
      {
        if (State < State.Realtime)
            return;
       
        if (Close[0] > SMA(20)[0])
        {
            atmStrategyId = GetAtmStrategyUniqueId();
            atmStrategyOrderId = GetAtmStrategyUniqueId();
       
            AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0, TimeInForce.Day,
                atmStrategyOrderId, "MyTemplate", atmStrategyId, (atmCallbackErrorCode, atmCallbackId) => {
       
                // checks that the call back is returned for the current atmStrategyId stored
                if (atmCallbackId == atmStrategyId)
                {
                    // check the atm call back for any error codes
                    if (atmCallbackErrorCode == Cbi.ErrorCode.NoError)
                    {
                        // if no error, set private bool to true to indicate the atm strategy is created
                        isAtmStrategyCreated = true;
                    }
                }
            });
        }
       
        if(isAtmStrategyCreated)
        {
            // atm logic
        }
       
        else if(!isAtmStrategyCreated)
        {
            // custom handling for a failed atm Strategy
        }
      }
      Last edited by suroot; 04-10-2017, 07:28 AM.

      Comment


        #4
        Hello Christian,

        Thanks for your reply.

        In the SampleATMStrategy the entry in this condition: if (orderId.Length == 0 && atmStrategyId.Length == 0 && Close[0] > Open[0]) Where it is verifying that any previous order has been reset to 0 and that the entry condition is if the Close is greater than the open, so basically on any upbar. You could replace Close[0] > Open[0] with your specific entry conditions.

        Regarding your edits, yes crossabove SMA(20) is the entry condition and yes it would need an ATM template called MyTemplate to manage the exits.
        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CortexZenUSA, Today, 12:53 AM
        0 responses
        1 view
        0 likes
        Last Post CortexZenUSA  
        Started by CortexZenUSA, Today, 12:46 AM
        0 responses
        1 view
        0 likes
        Last Post CortexZenUSA  
        Started by usazencortex, Today, 12:43 AM
        0 responses
        2 views
        0 likes
        Last Post usazencortex  
        Started by sidlercom80, 10-28-2023, 08:49 AM
        168 responses
        2,264 views
        0 likes
        Last Post sidlercom80  
        Started by Barry Milan, Yesterday, 10:35 PM
        3 responses
        11 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X