• 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

Converting the Sample ATM Strategy

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

    Converting the Sample ATM Strategy

    I've been able to adapt the Sample ATM strategy to one of my existing strategies but I'm having some problems with multiple entries. The SampleATM strategy only shows an entry in one direction. If I want to adapt it for both long or short entries do I need to duplicate everything after the entry for both directions:

    (See example below)

    If this isn't necessary perhaps you could point to what could be combined and what would need to be changed. When I adapted it, I was actually getting orders, the ATM was managing them, IT WAS REALLY COOL, but I started getting too many orders pumped out, and it appeared that entry limits which weren't hit, persisted. I think I need to add a method to remove entry orders if they didn't fill after one bar.

    Sorry for the long post.
    daven


    example:

    .....ENTER LONG
    atmStrategyId = GetAtmStrategyUniqueId();
    orderId = GetAtmStrategyUniqueId();
    AtmStrategyCreate(Action.Buy, OrderType.Limit, Low[0], 0, TimeInForce.Day, orderId, "AtmStrategyTemplate", atmStrategyId);
    }


    // Check for a pending entry order
    if (orderId.Length > 0)
    {
    string[] status = GetAtmStrategyEntryOrderStatus(orderId);

    // If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
    if (status.GetLength(0) > 0)
    {
    // Print out some information about the order to the output window
    Print("The entry order average fill price is: " + status[0]);
    Print("The entry order filled amount is: " + status[1]);
    Print("The entry order order state is: " + status[2]);

    // If the order state is terminal, reset the order id value
    if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
    orderId = string.Empty;
    }
    } // If the strategy has terminated reset the strategy id
    else if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
    atmStrategyId = string.Empty;


    if (atmStrategyId.Length > 0)
    {
    // You can change the stop price
    if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat)
    AtmStrategyChangeStopTarget(0, Low[0] - 3 * TickSize, "STOP1", atmStrategyId);

    // Print some information about the strategy to the output window
    Print("The current ATM Strategy market position is: " + GetAtmStrategyMarketPosition(atmStrategyId));
    Print("The current ATM Strategy position quantity is: " + GetAtmStrategyPositionQuantity(atmStrategyId));
    Print("The current ATM Strategy average price is: " + GetAtmStrategyPositionAveragePrice(atmStrategyId)) ;
    Print("The current ATM Strategy Unrealized PnL is: " + GetAtmStrategyUnrealizedProfitLoss(atmStrategyId)) ;
    #region Properties
    #endregion


    .....ENTER SHORT
    atmStrategyId = GetAtmStrategyUniqueId();
    orderId = GetAtmStrategyUniqueId();
    AtmStrategyCreate(Action.Buy, OrderType.Limit, Low[0], 0, TimeInForce.Day, orderId, "AtmStrategyTemplate", atmStrategyId);
    }


    // Check for a pending entry order
    if (orderId.Length > 0)
    {
    string[] status = GetAtmStrategyEntryOrderStatus(orderId);

    // If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
    if (status.GetLength(0) > 0)
    {
    // Print out some information about the order to the output window
    Print("The entry order average fill price is: " + status[0]);
    Print("The entry order filled amount is: " + status[1]);
    Print("The entry order order state is: " + status[2]);

    // If the order state is terminal, reset the order id value
    if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
    orderId = string.Empty;
    }
    } // If the strategy has terminated reset the strategy id
    else if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
    atmStrategyId = string.Empty;


    if (atmStrategyId.Length > 0)
    {
    // You can change the stop price
    if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat)
    AtmStrategyChangeStopTarget(0, Low[0] - 3 * TickSize, "STOP1", atmStrategyId);

    // Print some information about the strategy to the output window
    Print("The current ATM Strategy market position is: " + GetAtmStrategyMarketPosition(atmStrategyId));
    Print("The current ATM Strategy position quantity is: " + GetAtmStrategyPositionQuantity(atmStrategyId));
    Print("The current ATM Strategy average price is: " + GetAtmStrategyPositionAveragePrice(atmStrategyId)) ;
    Print("The current ATM Strategy Unrealized PnL is: " + GetAtmStrategyUnrealizedProfitLoss(atmStrategyId)) ;
    #region Properties
    #endregion

    #2
    In your ENTER SHORT you did another buy order instead of a sell short order. Generally speaking you would need to copy the AtmStrategyCreate() part along with the several state resets after it. Use a unique variable for your atmStrategyId and orderId so it doesn't get confused which ATM order you are referring to. I just use atmStrategyId2, orderId2, etc.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Adapting the Sample ATM Strategy

      Originally posted by Josh View Post
      In your ENTER SHORT you did another buy order instead of a sell short order. Generally speaking you would need to copy the AtmStrategyCreate() part along with the several state resets after it. Use a unique variable for your atmStrategyId and orderId so it doesn't get confused which ATM order you are referring to. I just use atmStrategyId2, orderId2, etc.

      Thanks for the advice. I went through, renamed the two order entry strategies (atmStrategyID1 and atmStrategyID2, (same for orderID's). I then went carefully through the strategy, counted {}, counted (), and made sure they all agreed with the SampleATM strategy, and it worked. It's running now on EMD and ER2 and its working. I am stoked. THANK YOU SO MUCH FOR YOUR HELP!

      Now, after all that enthusiasm I still have a problem with the entry order enduring for more than one bar. I could change it to a market order, but frankly, the base strategy tests better when it is a limit order on the previous bar close. Is it possible to include the whole strategy for consideration? It might be helpful to others as well. If so, how could I do that, and can you suggest a method to close the open limit order after n bars, ('n' being an integer variable).

      Thanks again Josh, I feel like I've had a real breakthrough, and I have to tell you, learning C# is a lot like hacking through a nasty swamp. Hopefully the end is worth the trip.

      daven

      Comment


        #4
        Adapting Sample ATMStrategy

        I've noticed that while running the strategy, my positions aren't showing up on the chart. This isn't a big problem but I'm wondering, are there any plans to change this in the future or is it a fundamental platform issue (like Tradestation not being able to plot and execute orders in the same strategy)?
        daven

        Comment


          #5
          ATM strategies do not plot on the chart like a native NinjaScript strategy. Executions themselves will plot on a chart --> Make sure you have this set correctly in the chart properties dialog window.
          RayNinjaTrader Customer Service

          Comment


            #6
            ATM Strategies

            I have the chart properties set to show text and markers but I'm getting no executions on the chart. It is the right instrument, the right sim account, and I know the strategy on the chart is the one I'm testing. Is there some other setting I should have changed.
            daven

            Comment


              #7
              Take a look at the executions tab of the Control Center window. If there are execution in there, open a new chart for the specific instrument ensuring that execution times are withing the session start/end time of the chart and ensuring plot executions are enabled. You will then see executions plotted on the chart.
              RayNinjaTrader Customer Service

              Comment


                #8
                Strategy Executions on Chart

                Originally posted by NinjaTrader_Ray View Post
                Take a look at the executions tab of the Control Center window. If there are execution in there, open a new chart for the specific instrument ensuring that execution times are withing the session start/end time of the chart and ensuring plot executions are enabled. You will then see executions plotted on the chart.
                I see this, so just keep an extra chart open for the same instrument with no strategy on it, and I'll be able to monitor executions on the chart? A little funky as a work around but it tells me what I need to know.
                Thanks

                Comment


                  #9
                  Originally posted by daven View Post

                  Now, after all that enthusiasm I still have a problem with the entry order enduring for more than one bar. I could change it to a market order, but frankly, the base strategy tests better when it is a limit order on the previous bar close. Is it possible to include the whole strategy for consideration? It might be helpful to others as well. If so, how could I do that, and can you suggest a method to close the open limit order after n bars, ('n' being an integer variable).

                  daven

                  I think the question above was missed because the post was so long. The Stategy/ATM strategy is working, but it leaves behind limit orders when conditions change. Is there a function I could use to cancel all existing limit orders on the close of the bar the orders occurred on? I get too many fills and it looks like I have stops and limits in both directions on the DOM.
                  daven

                  Comment


                    #10
                    You have to take programmatic responsibility for all entry orders generated by AtmStrategyCreate().

                    Use AtmStrategyCancelEntryOrder().

                    http://www.ninjatrader-support.com/H...egyActive.html
                    RayNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Sh00tHerMcGavin, Today, 07:39 PM
                    0 responses
                    3 views
                    0 likes
                    Last Post Sh00tHerMcGavin  
                    Started by Mberg, Today, 05:13 PM
                    0 responses
                    1 view
                    0 likes
                    Last Post Mberg
                    by Mberg
                     
                    Started by Barry Milan, Today, 01:33 PM
                    2 responses
                    10 views
                    0 likes
                    Last Post marcus2300  
                    Started by NW Trader, Today, 03:42 PM
                    2 responses
                    8 views
                    0 likes
                    Last Post NW Trader  
                    Started by ralett, Today, 01:42 PM
                    1 response
                    5 views
                    0 likes
                    Last Post NinjaTrader_ShawnB  
                    Working...
                    X