Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to use SampleATMstrategy?

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

    how to use SampleATMstrategy?

    I know just enough NinjaScript to get myself in trouble, but usually I can manage. However, I am lost on how to build on the SampleATMstrategy script. I can't 'see' what the sample does.

    Is it possible to show a very simple example of how one might use the SampleATMstrategy script? For example, using an MA cross to trigger an ATM long/short?

    Thanks.

    #2
    Hello,

    Thanks for the forum post.

    Basically you are going to create a copy of the ATM code and use that as your template for your new strategy. The only part you are woried about changing is as follows:

    Code:
    // Submits an entry limit order at the current low price to initiate an ATM Strategy if both order id and strategy id are in a reset state
                // **** YOU MUST HAVE AN ATM STRATEGY TEMPLATE NAMED 'AtmStrategyTemplate' CREATED IN NINJATRADER (SUPERDOM FOR EXAMPLE) FOR THIS TO WORK ****
                if (orderId.Length == 0 && atmStrategyId.Length == 0 && Close[0] > Open[0])
                {
                    atmStrategyId = GetAtmStrategyUniqueId();
                    orderId = GetAtmStrategyUniqueId();
                    AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, Low[0], 0, TimeInForce.Day, orderId, "AtmStrategyTemplate", atmStrategyId);
                }
    It is this bar you change for your order processing and submission logic,

    For the crossover strategy you would take the SampleMACrossOver Strategy code inside of OnBarUpdate() and replace the EnterLong() and EnterShort() call. With this.

    Code:
        atmStrategyId = GetAtmStrategyUniqueId();
                    orderId = GetAtmStrategyUniqueId();
                    AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Market, 0, 0, TimeInForce.Day, orderId, "AtmStrategyTemplate",  atmStrategyId);
    There are some extra items you need to think about for example what to do when you want to reverse as right now this wont let you reverse unless you are out of a trade. Which may be what you want.

    -Brett

    Comment


      #3
      OK, I am going to show my ingnorance here. I will try to describe my understanding of your response to see if I am even close:

      1. if (orderId.Length == 0 && atmStrategyId.Length == 0 && Close[0] > Open[0])
      It appears to me that this line checks if orderid and atmStrategyid are in reset mode.
      And also if the close of the current bar was greater than the open. Correct?

      2. Are the orderid.Length and atmStrategyid.Length the number of bars back to when ATM was initiated? If correct, how does it get reset to 0?

      3. So in the above example, everytime the bar closes higher than it opens, and the orderid and strategyid are in reset, it will trigger the ATM strategy via limit order set to Buy limit at the Low of current (triggering) bar. Is this correct?

      4. In your second code example, this is simply the mechanics of calling the ATM strategy, which in this case is set for a market order?

      If I am correct so far, I have a question about the parameters of this line:
      AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Market, 0, 0, TimeInForce.Day, orderId, "AtmStrategyTemplate", atmStrategyId);
      5. Cbi.OrderAction.Buy....I assume this can be Buy or Sell for long/short?
      6. In the previous example, the order type line was OrderType.Limit, Low[0],0, ..... it looks like the Low[0] was used to set the price for the limit order? What is the second zero for?
      7. What are the 0,0, in the case of the Market order for this line?

      Thanks for your help.
      Last edited by billr; 11-22-2011, 05:03 PM.

      Comment


        #4
        1. if (orderId.Length == 0 && atmStrategyId.Length == 0 && Close[0] > Open[0])
        It appears to me that this line checks if orderid and atmStrategyid are in reset mode.
        And also if the close of the current bar was greater than the open. Correct?

        [Brett] - Correct

        2. Are the orderid.Length and atmStrategyid.Length the number of bars back to when ATM was initiated? If correct, how does it get reset to 0?

        [Brett] - There is code inside the sample that does the reset back to zero located near the bottom of OnBarUpdate().

        3. So in the above example, everytime the bar closes higher than it opens, and the orderid and strategyid are in reset, it will trigger the ATM strategy via limit order set to Buy limit at the Low of current (triggering) bar. Is this correct?

        [Brett] - Correct

        4. In your second code example, this is simply the mechanics of calling the ATM strategy, which in this case is set for a market order?

        [Brett] - Correct

        If I am correct so far, I have a question about the parameters of this line:
        AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Market, 0, 0, TimeInForce.Day, orderId, "AtmStrategyTemplate", atmStrategyId);
        5. Cbi.OrderAction.Buy....I assume this can be Buy or Sell for long/short?

        [Brett] - Correct

        6. In the previous example, the order type line was OrderType.Limit, Low[0],0, ..... it looks like the Low[0] was used to set the price for the limit order? What is the second zero for?

        [Brett] - http://www.ninjatrader.com/support/h...tegycreate.htm

        This is stop price if you are submitting a stop order. Set to 0 if you are not.

        7. What are the 0,0, in the case of the Market order for this line?

        [Brett] - Please see the above link for all parameter definitions.

        -Brett

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by TraderBCL, Today, 04:38 AM
        0 responses
        2 views
        0 likes
        Last Post TraderBCL  
        Started by Radano, 06-10-2021, 01:40 AM
        19 responses
        606 views
        0 likes
        Last Post Radano
        by Radano
         
        Started by KenneGaray, Today, 03:48 AM
        0 responses
        4 views
        0 likes
        Last Post KenneGaray  
        Started by thanajo, 05-04-2021, 02:11 AM
        4 responses
        470 views
        0 likes
        Last Post tradingnasdaqprueba  
        Started by aa731, Today, 02:54 AM
        0 responses
        5 views
        0 likes
        Last Post aa731
        by aa731
         
        Working...
        X