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 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 FrancisMorro, Today, 03:24 AM
            0 responses
            1 view
            0 likes
            Last Post FrancisMorro  
            Started by Segwin, 05-07-2018, 02:15 PM
            10 responses
            1,770 views
            0 likes
            Last Post Leafcutter  
            Started by Rapine Heihei, 04-23-2024, 07:51 PM
            2 responses
            31 views
            0 likes
            Last Post Max238
            by Max238
             
            Started by Shansen, 08-30-2019, 10:18 PM
            24 responses
            944 views
            0 likes
            Last Post spwizard  
            Started by Max238, Today, 01:28 AM
            0 responses
            11 views
            0 likes
            Last Post Max238
            by Max238
             
            Working...
            X