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

Calling value calculated by an indicator (NOT PLOTTED) in a strategy

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

    Calling value calculated by an indicator (NOT PLOTTED) in a strategy

    Dear Support,

    I'm trying to get value from my custom indicator into my strategy.
    I can access to plot value without problem using another indicator (like SMA(), VOL(), ecc), but if I try to access to these variables like below i can't.

    Variables check1, check2, check3 and trendS are public in my custom indicator, so i have not compiling problem.
    but if I Print this values they are wrong., whie in my indicator are correct.

    I think problem is that this 4 variables aren't Plot[] Values in my indicator, this doesn't plot any Values[], just do some calculations and render some line

    How can I access to these variables?

    thank you, best regards


    AndreaConato


    Code:
    namespace NinjaTrader.NinjaScript.Strategies
    {
       public class TestRitracciamento : Strategy
       {
          // Variables
    
          ACRItracciamentoCompleto4 myRitracciamento;
    
          bool controllo1 = false;
          bool controllo2 = false;
          bool controllo3 = false;
    
          int trendLungo = 0;
    
          int RitracciamentoS = 0;
          int RitracciamentoF = 0;
    
         double RiskReward = 0;
         double RitracciamentoMin = 0;
         double RitracciamentoMax = 0;
    
         protected override void OnStateChange()
         {
             if (State == State.SetDefaults)
             {
                 Description = "TestRitracciamento";
                 Name = "TestRitracciamento";
                 Calculate = Calculate.OnPriceChange;
    
                 RitracciamentoS = 10;
                 RitracciamentoF = 5;
                 RiskReward = 2;
                 RitracciamentoMin = 50;
                 RitracciamentoMax = 90;
             }
    
             else if (State == State.DataLoaded)
             {
                  myRitracciamento = ACRItracciamentoCompleto4(RitracciamentoS,Ritracci amentoF,RiskReward,RitracciamentoMin,Ritracciament oMax);
             }
        }
    
    protected override void OnBarUpdate()
    {
        if (CurrentBar < BarsRequiredToTrade)
            return;
    
        controllo1 = myRitracciamento.check1;
        controllo2 = myRitracciamento.check2;
        controllo3 = myRitracciamento.check3;
        trendLungo = myRitracciamento.trendS;
    
        Print("" + controllo1 + controllo2 + controllo3 + trendLungo);
    
    }
    
    
    }
    
    }

    #2
    Hello AndreaBhs,

    Thanks for your post.

    If I understand correctly the issue is not accessing the values but getting the correct values.

    Please see the help guide here: https://ninjatrader.com/support/help...t8/?update.htm

    In your strategy, in the OnBarUpdate() try: myRitracciamento.UpDate();
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Dear PaulH, thanks for your reply.

      Yes, I need to get the correct value in real time.

      If try myRitracciamento.Update(); I haven't compile error, but I have this error:

      Error on calling 'EventHandlerBarsUpdate' method: Object reference not set to an instance of an object.

      What's the problem?

      Comment


        #4
        Hello AndreaBhs,

        Thanks for your reply.

        Please remove that line.

        In your indicator, you will need to modify the public properties as shown in the help guide example in post #2.

        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hello AndreaBhs,

          I had meant to also provide this educational example: https://ninjatrader.com/support/help...alues_that.htm
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Hello Paul H.,

            in my indicator I have:

            Code:
            // Variables 
            
            bool check1 = false;
            
            OnBarUpdate()
            {
               check1 = true;
            }
            
            
            #region Properties
            public bool Check1
            {
               // We need to call the Update() method to ensure our exposed variable is in up-to-date.
               get
               {
               Update();
               return check1;
               }
            }
            #endregion
            in my strategy I deleted the line

            Code:
            myRitracciamento.Update()
            and i have write

            Code:
            Print(myRitracciamento.Check1);
            It compile without any error, but in the Print I have again the previous error:

            Strategy 'TestRitracciamento': Error on calling 'EventHandlerBarsUpdate' method: Object reference not set to an instance of an object.

            I don't know where is the problem

            sorry and thank you for your help


            Comment


              #7
              Hello AndreaBhs,

              Thanks for your reply.

              I would need to see all of your scripts to best assist.

              Can you post the cs files (easier to plug in and test with) for both your strategy and indicator ?

              Alternately, if you prefer confidentiality, please attach your scripts to an e-mail addressed to PlatformSupport[at]NinjaTrader[dot]Com. Mark the subject line Atten:Paul and include Ticket# 2858972. In the body of the e-mail add a link to this thread for reference. For the email replace [at] with @ and [dot] with . (this is done to prevent spambots grabbing legit e-mail addresses).

              Paul H.NinjaTrader Customer Service

              Comment


                #8
                Hello Paul H,
                I sent my indicator and strategy .CS file to the e-mail PlatformSupport[at]NinjaTrader[dot]Com. with the ticket number Ticket# 2858972.

                thank you,best regards

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by algospoke, Today, 06:40 PM
                0 responses
                9 views
                0 likes
                Last Post algospoke  
                Started by maybeimnotrader, Today, 05:46 PM
                0 responses
                7 views
                0 likes
                Last Post maybeimnotrader  
                Started by quantismo, Today, 05:13 PM
                0 responses
                7 views
                0 likes
                Last Post quantismo  
                Started by AttiM, 02-14-2024, 05:20 PM
                8 responses
                168 views
                0 likes
                Last Post jeronymite  
                Started by cre8able, Today, 04:22 PM
                0 responses
                10 views
                0 likes
                Last Post cre8able  
                Working...
                X