Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Reading indicator values from chart

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

    Reading indicator values from chart

    Hi ,
    I am pring indicatior values as below and it is printing as expected :

    double lstop = Instrument.MasterInstrument.RoundToTickSize(this.L ong_Stop[0]);
    double sstop = Instrument.MasterInstrument.RoundToTickSize(this.S hort_Stop[0]);
    // Print(string.Format("{0};{1};{2};{3}{4};", "STVV1NEWIND=>"+Time[0],lstop,sstop));


    Print(string.Format("{0};{1};{2};{3}", Time[0],lstop,sstop,"STVV1NEWIND11"));


    But if i read the same values in strategy via below code it prints very diferent values ? How can access actual values of indicator in strategy:

    if(ChartControl != null)
    {
    foreach (NinjaTrader.Gui.NinjaScript.IndicatorRenderBase indicator in ChartControl.Indicators)
    {
    if(indicator.GetType() == typeof(STV1NEWIND11))
    {
    STV1NEWIND11 stv1 = indicator as STV1NEWIND11;
    if(stv1 != null)
    {
    Print("STV1Strategy=Time[0]: " + Time[0]+"Lstop=="+stv1.Long_Stop[0]+"Sstop="+stv1.Short_Stop[0]);
    }
    }
    }
    }

    it allways prints same number indicator Can u please help me read right values?

    STV1Strategy=Time[0]: 02/03/2021 17:39:00Lstop==3872.875Sstop=0
    02/03/2021 17:40:00;3891;0;STVV1NEWIND11
    STV1Strategy=Time[0]: 02/03/2021 17:40:00Lstop==3872.875Sstop=0
    02/03/2021 17:41:00;3891;0;STVV1NEWIND11
    STV1Strategy=Time[0]: 02/03/2021 17:41:00Lstop==3872.875Sstop=0
    02/03/2021 17:42:00;3891;0;STVV1NEWIND11
    STV1Strategy=Time[0]: 02/03/2021 17:42:00Lstop==3872.875Sstop=0
    02/03/2021 17:43:00;3891;0;STVV1NEWIND11
    STV1Strategy=Time[0]: 02/03/2021 17:43:00Lstop==3872.875Sstop=0
    02/03/2021 17:44:00;3891;0;STVV1NEWIND11
    STV1Strategy=Time[0]: 02/03/2021 17:44:00Lstop==3872.875Sstop=0

    #2
    Hello shankar.deshapande,

    Thank you for your post.

    I see that you are trying to access indicators from a chart in your strategy. Instead, indicators should be accessed from the strategy itself.

    Something you could do is use the Strategy Builder to create a strategy that prints out information about indicators. Then, you could click the 'View code' button in the Strategy Builder to see how those indicators are used in the strategy.

    See the help guide documentation below for more information.
    Condition Builder - https://ninjatrader.com/support/help...on_builder.htm
    Actions - https://ninjatrader.com/support/help...t8/actions.htm

    Let us know if we may assist further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Hi,

      Thanks for help. Now it is working fine. I want to place limit order by using ATM strategy but below code is not placing any limit order . Can u please tell me what mistake i am making


      if((lstop==0) && (sstop<=GetCurrentAsk())){ Print("BUY");
      EnterLong(Convert.ToInt32(DefaultQuantity), "myLongEntryOrder");
      }
      if((sstop==0) &&( lstop>=GetCurrentAsk() )){ Print("SELL");
      EnterLong(Convert.ToInt32(DefaultQuantity), "myShortEntryOrder");
      }

      Comment


        #4
        Hello shankar.deshapande.

        Thank you for your note.

        To clarify, are you trying to use an ATM strategy template in your NinjaScript strategy?

        If so, this would not be possible using the Strategy Builder. You would need to use to 'Unlock code' button in the Strategy Builder to unlock the code and manually code this into your strategy. Please see the SampleAtmStrategy script that comes default with NinjaTrader for an example of working with ATM strategy templates in a NinjaScript. To view the script, open a New > NinjaScript Editor window, double-click the Strategies folder to open it, then select the SampleAtmStrategy script to view the code.

        See this help guide link for more information.
        Atrm strategy methods - https://ninjatrader.com/support/help...gy_methods.htm
        Using ATM strategies in NinjaScript - https://ninjatrader.com/support/help...strategies.htm

        If you would simply like to create a stop loss and profit target order when your limit order is submitted, you would first need to create an order entry condition in the Conditions section. Next, you would need to call an action of EnterLongLimit() in your script. Then, you would use the Stops and Targets section of the Strategy Builder to create a stop loss and profit target.

        See the help guide links below for more information.
        Enter a market position - https://ninjatrader.com/support/help...MarketPosition
        Stops and Targets screen - https://ninjatrader.com/support/help...dTargetsScreen

        Also, see the publicly available 'Strategy Builder 301' and 'NinjaScript Editor 401' training videos below for a demonstration of working with the Strategy Builder and NinjaScript Editor.
        Strategy Builder 301 — https://www.youtube.com/watch?v=_KQF2Sv27oE&t=13s
        NinjaScript Editor 401 - https://youtu.be/H7aDpWoWUQs?list=PL...We0Nf&index=14

        Let us know if we may assist further.
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          I have defined ATM Strategy and tested for profit trigger and trailing stop loss from chart trader it is working as expected but if use same in strategy it is not moving Profit trigger and trailng stoploss.

          and also if market reverses it is not placing reverse order .How to place buy and sell:

          if (orderId.Length == 0 && atmStrategyId.Length == 0 && lstop==0)

          {Print("SELL");
          isAtmStrategyCreated = false; // reset atm strategy created check to false
          atmStrategyId = GetAtmStrategyUniqueId();
          orderId = GetAtmStrategyUniqueId();
          AtmStrategyCreate(OrderAction.Sell, OrderType.Limit, Low[0], 0, TimeInForce.Day, orderId, ATM_TemplateName, atmStrategyId, (atmCallbackErrorCode, atmCallBackId) => {
          //check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
          if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == atmStrategyId)
          isAtmStrategyCreated = true;
          });
          }

          if (orderId.Length == 0 && atmStrategyId.Length == 0 && sstop==0)
          {Print("BUY");
          isAtmStrategyCreated = false; // reset atm strategy created check to false
          atmStrategyId = GetAtmStrategyUniqueId();
          orderId = GetAtmStrategyUniqueId();
          AtmStrategyCreate(OrderAction.Buy, OrderType.Limit, Low[0], 0, TimeInForce.Day, orderId, ATM_TemplateName, atmStrategyId, (atmCallbackErrorCode, atmCallBackId) => {
          //check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
          if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == atmStrategyId)
          isAtmStrategyCreated = true;
          });
          }

          Comment


            #6
            Hello shankar.deshapande,

            Thank you for that information.

            Is ATM_TemplateName a variable that is being assigned the strategyTemplateName string? Or is this the actual name of your ATM strategy template?

            The 'string strategyTemplateName' property should use a string value of the exact name of the ATM strategy template being used.

            See the attached modified SampleAtmStrategy script that demonstrates using an ATM strategy template named "AtmStrategyTemplate" that contains a Stop Strategy within a NinjaScript. I have also attached screenshots of the settings used in the AtmStrategyTemplate.

            First, create an ATM strategy template named AtmStrategyTemplate and use the setting provided in the screenshots. Then, import and test the ModifiedSampleAtmStrategy script. When an up bar occurs, a buy limit order is placed. Once that limit order is filled, the strategy will place a stop loss and profit target based on the ATM strategy template, and a trailing stop will occur based on our ATM strategy template Stop Strategy parameters.

            Please let me know if I may further assist.
            Attached Files
            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Yesterday, 05:17 AM
            0 responses
            66 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            141 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            75 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            46 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            51 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X