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

Strategy will not put a ATM Strategy in play when order filled

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

    Strategy will not put a ATM Strategy in play when order filled

    Strategy will not put a ATM Strategy in play when order filled. I've seen alot of threads saying look at the SampleATMStrategy for examples. I pretty much took the sample and plugged in my perameters for entry.

    It it will put in a limit order at the correct price but not the ATM Strat.

    Maybe someone sees something I fat fingered in the code?

    //
    // Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
    // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
    //

    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion


    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// Trade Automation
    /// </summary>
    [Description("Trade Automation")]
    public class Autotrade : Strategy
    {
    #region Variables
    private string atmStrategyId = string.Empty;
    private string orderId = string.Empty;
    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {

    // Make sure this strategy does not execute against historical data
    if (Historical)
    return;

    // Condition set 1
    if (orderId.Length == 0 && atmStrategyId.Length == 0 && Close[0] > SampleGetHighLowByTimeRange(6, 50, 6, 20).HighestHigh[0])
    {
    atmStrategyId = GetAtmStrategyUniqueId();
    orderId = GetAtmStrategyUniqueId();
    AtmStrategyCreate(Action.Buy, OrderType.Limit, SampleGetHighLowByTimeRange(6, 50, 6, 20).HighestHigh[0], 0, TimeInForce.Day, orderId, "DTTW", atmStrategyId);
    }

    // Condition set 2
    if (orderId.Length == 0 && atmStrategyId.Length == 0 && Close[0] > SampleGetHighLowByTimeRange(6, 50, 6, 20).LowestLow[0])
    {
    atmStrategyId = GetAtmStrategyUniqueId();
    orderId = GetAtmStrategyUniqueId();
    AtmStrategyCreate(Action.Sell, OrderType.Limit, SampleGetHighLowByTimeRange(6, 50, 6, 20).LowestLow[0], 0, TimeInForce.Day, orderId, "DTTW", 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
    m3power222,

    Please check your Control Center logs for errors. You need to first have an ATM strategy template with the name you are calling in your strategy.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Josh View Post
      m3power222,

      Please check your Control Center logs for errors. You need to first have an ATM strategy template with the name you are calling in your strategy.

      I got it to use my ATM Strategy to work. The issue now is that I have a custom stop strategy but it doesn't work correctly as how I set it up. In the sampleatmstrat near the bottom is:

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

      I've commented it out, removed it but still doesn't work correctly.

      Is there something else in the sampleatmstrat that puts a different Stop Strategy in play?

      Comment


        #4
        m3power222, no I don't believe so. Which issues do you have with the custom stop strategy? Does the ATM stop strategy work well by itself if you test this out on the DOM using the Simulated Data Feed?

        BertrandNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Bertrand View Post
          m3power222, no I don't believe so. Which issues do you have with the custom stop strategy? Does the ATM stop strategy work well by itself if you test this out on the DOM using the Simulated Data Feed?

          http://www.ninjatrader-support.com/H...dDataFeed.html

          I've tested the autotrade strategy with Simulated Data Feed and Market Reply but what is in the custom stop strategy does not work.

          When in a live trade, sim data feed and mkt reply manually entering a trade my atm/stop strat works perfect.

          Basically the autotrade strat I put together is combining the SampleAtmStrategy in ninjatrader and this:



          All I'm doing is playing breakouts for a particular range each day. Pretty simple strategy.

          Attached is the export of the autotrade and screenshot of atm/stop strat. Maybe someone has time to look at it more in depth? Run the tests above and you'll see that the autotrade makes the 1 Target Stop Strat behave differently then manually entering a trade. When auto it brings up the stop way too soon before it is defined in the stop strat for auto breakeven.

          Thanks in advance.
          Last edited by m3power222; 06-09-2009, 01:14 PM.

          Comment


            #6
            Your code is modifying stop/targets:

            if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat)
            AtmStrategyChangeStopTarget(0, Low[0] - 3 * TickSize, "STOP1", atmStrategyId);

            Once that occurs your stop strategy may not be applicable anymore.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Josh View Post
              Your code is modifying stop/targets:

              if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat)
              AtmStrategyChangeStopTarget(0, Low[0] - 3 * TickSize, "STOP1", atmStrategyId);

              Once that occurs your stop strategy may not be applicable anymore.

              Josh,

              I removed it and still the same issue. I threw it back in when up loading the export here.

              Could it be a caching issue?

              Even tried commenting out that code and no dice.

              Comment


                #8
                Please ensure you are on a fresh instance of the strategy. Remove it from the chart and add it back after you compile your new code.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Josh View Post
                  Please ensure you are on a fresh instance of the strategy. Remove it from the chart and add it back after you compile your new code.
                  Do I leave what is above it in?

                  if (atmStrategyId.Length > 0)
                  {

                  Comment


                    #10
                    Originally posted by NinjaTrader_Josh View Post
                    Please ensure you are on a fresh instance of the strategy. Remove it from the chart and add it back after you compile your new code.

                    Josh thank you, I didn't compile. Works great now!

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by GussJ, 03-04-2020, 03:11 PM
                    11 responses
                    3,228 views
                    0 likes
                    Last Post xiinteractive  
                    Started by andrewtrades, Today, 04:57 PM
                    1 response
                    13 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by chbruno, Today, 04:10 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post chbruno
                    by chbruno
                     
                    Started by josh18955, 03-25-2023, 11:16 AM
                    6 responses
                    440 views
                    0 likes
                    Last Post Delerium  
                    Started by FAQtrader, Today, 03:35 PM
                    0 responses
                    12 views
                    0 likes
                    Last Post FAQtrader  
                    Working...
                    X