Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy ATM entry

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

    Strategy ATM entry

    Please could someone who is a programming ninja have a quick look over this and tell me if the code telling the strategy to enter using the ATM is correct?

    Thanks.

    protected override void OnBarUpdate()
    {
    // Will stop the strategy after a loss of $300...
    if (Performance.AllTrades.TradesPerformance.Currency. CumProfit < -300)
    Disable();



    // Condition set 1 norm 10...
    if (GetCurrentBid() >= PRC2(3, 105, 1.62, 2, 34, 34).Sqh[2] + 0 * TickSize)
    if ((CrossBelow(Stochastics(Closes[0],2, 14, 4).K, Stochastics(Closes[0],2, 14, 4).D, 1)))

    if (orderId.Length == 0 && atmStrategyId.Length == 0 && Close[0] > Open[0])
    {
    atmStrategyId = GetAtmStrategyUniqueId();
    orderId = GetAtmStrategyUniqueId();
    AtmStrategyCreate(Cbi.OrderAction.Sell, OrderType.Market, 0, 0, TimeInForce.Day, orderId, "Oil", atmStrategyId);
    }

    // Condition set 2 norm 6...
    if (GetCurrentAsk() < PRC2(3, 105, 1.62, 2, 34, 34).Sql[0] + 0 * TickSize)
    if ((CrossAbove(Stochastics(Closes[0],2, 14, 4).K, Stochastics(Closes[0],2, 14, 4).D, 1)))
    if (orderId.Length == 0 && atmStrategyId.Length == 0 && Close[0] > Open[0])
    {
    atmStrategyId = GetAtmStrategyUniqueId();
    orderId = GetAtmStrategyUniqueId();
    AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Market, 0, 0, TimeInForce.Day, orderId, "Oil", atmStrategyId);
    }
    }

    #2
    Hello mccallum28,
    Your code will enter only once since you have not re-setted the orderId or the atmStrategyId when you are flat.

    To assist you further may I know are you witnessing any specific scenario.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Exactly that, Enters once and then does not enter any more trades once conditions are met, have no idea how to fix the code.

      Comment


        #4
        Hello mccallum28,
        Please reset the atmStraegyId, and other string variables to string.Empty when you are flat so that you can submit new orders.

        Code:
        if (atmStrategyId.Length > 0 && this.GetAtmStrategyMarketPosition(atamStrategyId) == MarketPosition.Flat)
        {
        	atmStategyId = string.Empty;
                //any other string variables
        }
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          So this would be the correct adjustment?

          // Will stop the strategy after a loss of $400...
          if (Performance.AllTrades.TradesPerformance.Currency. CumProfit < -300)
          Disable();


          if (atmStrategyId.Length > 0 && this.GetAtmStrategyMarketPosition("Oil") == MarketPosition.Flat)
          {
          atmStrategyId = string.Empty;
          //any other string variables
          }



          // Condition set 1 norm 10...
          if (GetCurrentBid() >= PRC2(3, 105, 1.62, 2, 34, 34).Sqh[2] + 0 * TickSize)
          if ((CrossBelow(Stochastics(Closes[0],2, 14, 4).K, Stochastics(Closes[0],2, 14, 4).D, 1)))


          {
          atmStrategyId = GetAtmStrategyUniqueId();
          orderId = GetAtmStrategyUniqueId();
          AtmStrategyCreate(Cbi.OrderAction.Sell, OrderType.Market, 0, 0, TimeInForce.Day, orderId, "Oil", atmStrategyId);
          }

          // Condition set 2 norm 6...
          if (GetCurrentAsk() < PRC2(3, 105, 1.62, 2, 34, 34).Sql[0] + 0 * TickSize)
          if ((CrossAbove(Stochastics(Closes[0],2, 14, 4).K, Stochastics(Closes[0],2, 14, 4).D, 1)))

          {
          atmStrategyId = GetAtmStrategyUniqueId();
          orderId = GetAtmStrategyUniqueId();
          AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Market, 0, 0, TimeInForce.Day, orderId, "Oil", atmStrategyId);
          }
          }

          #region

          #endregion
          }
          }

          Comment


            #6
            Hello mccallum28,
            I suppose 'Oil' is the name of the ATM Strategy Template. You need to refer the string variable atmStrategyId to retrieve the market position.

            Code:
            if (atmStrategyId.Length > 0 && this.GetAtmStrategyMarketPosition(atmStrategyId) == MarketPosition.Flat)
            {
            atmStrategyId = string.Empty;
            //any other string variables
            }
            JoydeepNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Hwop38, 05-04-2026, 07:02 PM
            0 responses
            162 views
            0 likes
            Last Post Hwop38
            by Hwop38
             
            Started by CaptainJack, 04-24-2026, 11:07 PM
            0 responses
            313 views
            0 likes
            Last Post CaptainJack  
            Started by Mindset, 04-21-2026, 06:46 AM
            0 responses
            245 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by M4ndoo, 04-20-2026, 05:21 PM
            0 responses
            350 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Started by M4ndoo, 04-19-2026, 05:54 PM
            0 responses
            179 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Working...
            X