Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Print() changes results..?

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

    Print() changes results..?

    Hello, i copied the RSI indicator, and i added 4 lines.
    Because of "Print(smaUp[0]);" the indicator changes values. Which is, nonsense..
    Whats going on?

    Code:
    protected override void OnBarUpdate()
            {
                Print("--------");
                Print(CurrentBar);
                Print(smaUp[0]);                                                   // this line changes the graphic and the values to negative
                if (CurrentBar == 0)
                {
                    down[0]        = 0;
                    up[0]        = 0;
    
                    if (Period < 3)
                        Avg[0] = 50;
    
                    return;
                }
    
                double input0    = Input[0];
                double input1    = Input[1];
    
                down[0]            = Math.Max(input1 - input0, 0);
                up[0]            = Math.Max(input0 - input1, 0);
                Print(smaUp[0]);                                                   // this line doesn't change a thing
    
                if (CurrentBar + 1 < Period)
                {
                    if (CurrentBar + 1 == Period - 1)
                        Avg[0] = 50;
                    return;
                }
    
                if ((CurrentBar + 1) == Period)
                {
                    // First averages
                    avgDown[0]    = smaDown[0];
                    avgUp[0]    = smaUp[0];
                }
                else
                {
                    // Rest of averages are smoothed
                    avgDown[0]    = (avgDown[1] * constant3 + down[0]) / Period;
                    avgUp[0]    = (avgUp[1] * constant3 + up[0]) / Period;
                }
    
                double avgDown0    = avgDown[0];
                double value0    = avgDown0 == 0 ? 100 : 100 - 100 / (1 + avgUp[0] / avgDown0);
                Default[0]        = value0;
                Avg[0]            = constant1 * value0 + constant2 * Avg[1];
            }
    Attached Files

    #2
    Hi Fernand0, thanks for your question.

    I made the same thing on my end and I get the same results. Try my version and see what you get compared to the original RSI. If they are the same, there must be something in your edit causing the problem.

    I look forward to hearing from you.
    Attached Files

    Comment


      #3
      i didn't change a thing, are you checking the beggining of the chart?
      how a Print can change the values?
      Attached Files
      Last edited by Fernand0; 04-26-2020, 05:18 PM.

      Comment


        #4
        Hi Fernand0, thanks for your reply.

        A Print can not change the logic of a a script unless it interferes with a statement like so:

        if(<condition>)
        Print("");
        {// code for condition}

        Do you get this same problem when you copy the SMA indicator? Also, try this with the latest MNQ contract if possible, MNQ 06-20.

        I look forward to hearing from you.

        Comment


          #5
          I think i caught it..

          Code:
          if (CurrentBar > 0)
          {
              Print(smaUp[0]);
          }
          it changes the values a lot

          Code:
          if (CurrentBar > Period)
          {
              Print(smaUp[0]);
          }
          it changes the values a little bit

          Code:
          if (CurrentBar > Period - 1)
          {
              Print(smaUp[0]);
          }
          it doesn't change the values

          I assume smaUp doesn't have any value to return at: CurrentBar < Period. Despite the error it doesn't throw an exception and it works(with wrong values, but it works)

          I tried a couple of indicators, RSI was the only one with this problem. I tried MNQ 06-20, still has the same value.
          But i tried Simulated Data Feed, and there are no errors
          Attached Files

          Comment


            #6
            Hello Fernand0,

            This is Jim, responding on behalf of Chris who is out of the office at this time.

            smaUp and smaDown are dependent on the "up" and "down" series which get calculated in OnBarUpdate. If we print out the SMA value before those dependencies are calculated, we can expect the SMA to be calculated without those dependencies. This creates the divergence.

            When I test with a print after these dependencies are calculated, I see the results we would expect.

            Code:
            double input0    = Input[0];
            double input1    = Input[1];
            down[0]            = Math.Max(input1 - input0, 0);
            up[0]            = Math.Max(input0 - input1, 0);
            
            if (CurrentBar > 0)
            {
                Print(smaUp[0]);
            }
            I look forward to assisting.
            Attached Files

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            673 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            379 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            111 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            577 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            582 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X