Announcement

Collapse
No announcement yet.

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 cjanau, Today, 11:07 AM
                0 responses
                5 views
                0 likes
                Last Post cjanau
                by cjanau
                 
                Started by TrendFollowingCapital, Today, 05:53 AM
                0 responses
                10 views
                0 likes
                Last Post TrendFollowingCapital  
                Started by TrendFollowingCapital, Today, 05:38 AM
                0 responses
                7 views
                0 likes
                Last Post TrendFollowingCapital  
                Started by John Bogui, Today, 03:57 AM
                2 responses
                41 views
                0 likes
                Last Post John Bogui  
                Started by Dolfan, 12-30-2020, 12:04 PM
                9 responses
                71 views
                0 likes
                Last Post timko
                by timko
                 
                Working...
                X