Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Main strategy with ATM strategy- Problem with ATM close

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

    Main strategy with ATM strategy- Problem with ATM close

    Hi


    I am developing a strategy including ATM strategy. The main strategy calls for ATM staretgy and opens the orders as desired, however it does not close previous orders when it gets new signal from the main script.I have included code for reset of the ATM strategy.

    Can anybody add the code for close of running ATM strategy when a new ATM order is opened by main strategy? I have gone through previous posts but not able to figure out how to close the running ATM strategy on a new opposite signal.

    Here is the code.

    Code:
     
    {
    #region Variables
     
     
    //main strategy variables here
     
    //ATM variables
     
     
    privatestring atmStrategyId = string.Empty;
    privatestring orderId = string.Empty;
     
     
     
    #endregion
     
    ///<summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    ///</summary>
    protectedoverridevoid Initialize()
    {
    CalculateOnBarClose = true;
    TraceOrders = true;
    EntryHandling = EntryHandling.AllEntries; 
    TimeInForce = Cbi.TimeInForce.Day;
     
    Add (main strategy indicators)
    }
    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()
    {
     
     
    // HELP DOCUMENTATION REFERENCE: Please see the Help Guide section "Using ATM Strategies"
    // Make sure this strategy does not execute against historical data
    if (Historical)
    return;
     
    // 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 && main strategy conditions for buy
    {
    atmStrategyId = GetAtmStrategyUniqueId();
    orderId = GetAtmStrategyUniqueId();
    AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Market, 0, 0, TimeInForce.Day, orderId, "AtmStrategyTemplate", atmStrategyId);
     
    }
     
     
    if (orderId.Length == 0 && atmStrategyId.Length == 0 && main strategy conditions for sell
    {
    atmStrategyId = GetAtmStrategyUniqueId();
    orderId = GetAtmStrategyUniqueId();
    AtmStrategyCreate(Cbi.OrderAction.Sell, OrderType.Market, 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
     
    if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == MarketPosition.Flat)
    {
    atmStrategyId = string.Empty;
    orderId = string.Empty;
    }
     
    }

    #2
    woodies, we could unfortunately not code this out for you, but an ATM could be closed via AtmStrategyClose() -



    If you would like to have this professionally created for you, please check into these certified NinjaScript consultants :

    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks for reply.

      I guess Ninjatrader support should release at least one generic strategy version includnig ATM strategy since I could see many requests for the same but not one full template with ATM strategy.

      Comment


        #4
        For a complete running ATM strategy example for getting started please check into the SampleAtmStrategy installed on your NT per default under strategies.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          ATM Strategy

          I am also having the same issue, I have looked at the sampleatmstrategy loaded on NT but when I try to intigrate it into my strategy It does not wor, can you post a full strategy with ATM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by i019945nj, 12-14-2023, 06:41 AM
          3 responses
          60 views
          0 likes
          Last Post i019945nj  
          Started by TraderBCL, Today, 04:38 AM
          2 responses
          17 views
          0 likes
          Last Post TraderBCL  
          Started by martin70, 03-24-2023, 04:58 AM
          14 responses
          106 views
          0 likes
          Last Post martin70  
          Started by Radano, 06-10-2021, 01:40 AM
          19 responses
          610 views
          0 likes
          Last Post Radano
          by Radano
           
          Started by thanajo, 05-04-2021, 02:11 AM
          4 responses
          471 views
          0 likes
          Last Post tradingnasdaqprueba  
          Working...
          X