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

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.
    Brandon H.NinjaTrader Customer Service

    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.
        Brandon H.NinjaTrader Customer Service

        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
            Brandon H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Haiasi, Today, 06:53 PM
            1 response
            3 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by ScottWalsh, Today, 06:52 PM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by ScottW, Today, 06:09 PM
            1 response
            4 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by ftsc2022, 10-25-2022, 12:03 PM
            5 responses
            256 views
            0 likes
            Last Post KeyonMatthews  
            Started by Board game geek, 10-29-2023, 12:00 PM
            14 responses
            244 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Working...
            X