• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 jertrade, Today, 06:57 PM
        0 responses
        1 view
        0 likes
        Last Post jertrade  
        Started by Emma1, Today, 02:42 PM
        1 response
        17 views
        0 likes
        Last Post NinjaTrader_DrewO  
        Started by fx.practic, Today, 03:10 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by jertrade, Today, 02:50 PM
        2 responses
        12 views
        0 likes
        Last Post jertrade  
        Started by RedDuke, Today, 01:59 PM
        1 response
        20 views
        0 likes
        Last Post NinjaTrader_Kate  
        Working...
        X