Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator call

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

    Indicator call

    Easy question. I made a simple indicator (trying to cut down on the strategy code) that I want to call from a strategy. But when I try to call the inidicator I always get the value of 0

    The indicator plots when I add it to a chart and the value changes from -5,- +5 all the time, like it is supposed to. Is there something I am missing in the indicator development that I need to set in order to be able to call values from a strategy.

    Indicator code

    PHP Code:
            protected override void Initialize()
            {
                Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                Overlay                = false;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
    
                
                         three_day_h = DonchianChannel(9).Upper[1];
                         five_day_h = DonchianChannel(15).Upper[1];
                         three_day_l = DonchianChannel(9).Lower[1];
                         five_day_l = DonchianChannel(15).Lower[1];
                                         if (High[0] > five_day_h)
                             {
                                 y = 5;
                                 is_con = is_con + 1;
                                 Print("High greater than 5 day high" + Time[0] + " of " + five_day_h.ToString());
    
                             }
                             else if (High[0] < five_day_h && High[0] > three_day_h)
                             {
                                 y = 3;
                                 is_con = is_con + 1;
                                 Print("High greater than 3 day high" + Time[0]);
                             }
                             if (Low[0] < five_day_l)
                             {
                                 y = -5;
                                 is_con = is_con + 1;
                                 Print("5 day low is " + five_day_l.ToString()+ " and current low is " + Low[0].ToString() + " at " + Time[0]);
                             }
                             else if (Low[0] > five_day_l && Low[0] < three_day_l)
                             {
                                 y = -3;
                                 is_con = is_con + 1;
                                 Print(" 3 day low is " + three_day_l.ToString() + " " + Time[0]);
                             }
                             if (is_con > 1)
                             {
                                 Print("We have a problem nasa " + Time[0]);
    
                             }
    
                
                Plot0.Set(y);
                Value.Set(y);
            } 
    

    #2
    How are you calling the indicator?

    Comment


      #3
      good point. I should have included that earlier. my bad

      In the strategy is where I had the problems.

      1) Add the indicator to the Initialize routine.

      Add(donchainplot(0)); // I am not sure why I had to add a 0 value, but I couldnt add the indicator without a value

      2) onBarUpdate

      Print(" indicator value = " + donchainplot(0).Value ); // I also tried adding the ToString() property and nothing changed
      always prints 0


      or I tried without the value property Print(" indicator value = " + donchainplot(0) );
      and I got " donchainplot(ES 09-11 (1 Min),1)"

      I just want to get the indicator value that I set it as.

      Comment


        #4
        Looks to me like you have an indicator named "donchainplot" that is expecting an input (whether it's used or not). From your indicator above it looks like you've hard coded the input values for 2 DonchianChannel indicators that you use to make your indicator. So even if you don't use the input parameter in your indicator logic, you have to include it in the call (or remove it from the indicator).

        Assuming you leave the input in the indicator, to access the current bars Plot0 value which you set to "y" in your indicator. In the print statement try:

        donchainplot(1).Plot0[0]

        VT

        Comment


          #5
          Thanks. I forgot about the [0] after the Plot.

          So much time wasted on that. wow. But I really appreciate it!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          633 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          364 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          105 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          567 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          568 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X