Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with Print function

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

    Problem with Print function

    Hey, I have the weirdest problem.I have a print function as follows:

    private void PrintStage(string Print_String, int Print_Var)
    {
    if (PrintOutput == true)
    {
    Print(@"LONG STAGE: " + Print_String + ". Bar " + Convert.ToString(Print_Var));
    Print(@"Time: " + Time[0].ToString("HH:mm:ss"));
    Print (@"- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
    }
    }


    Then, whenever I want to call the function. The code is like this, the code is set to run only once per bar only. I've added the "xxxxx" line for testing.

    Print("xxxxxxxxxxxxxxxxxxxxxx");
    PrintStage("RESET", CurrentBars[0]);


    The result I'm getting is to the output window:

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    LONG STAGE: RESET. Bar 20964
    Time: 14:39:35
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    LONG STAGE: RESET. Bar 20964
    Time: 14:39:35
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    xxxxxxxxxxxxxxxxxxxxxx
    MyBar = 20964
    LONG STAGE: RESET. Bar 20964
    Time: 14:39:35
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


    For some reason the function is firing 3 times at the exact same time, on the same bar. You can see the text "xxxxx" only prints once.

    I don't know where to start looking to find the problem, it just seemed to start happening today. Any idea wat the problem could be?


    ​​

    #2
    Hello several,

    Thank you for your post.

    It's not clear from just this code why it is firing more times than expected. I recommend debugging the script to figure out why this is happening more times than you intended it to. For example, what or where exactly is the logic for calling this function? Add a print for that condition to see how it is evaluating.

    If you are using Calculate.OnBarClose, OnBarUpdate() will only update once per bar. If you're using another Calculate method, like OnEachTick or OnPriceChange, and you only want something to happen once per bar use IsFirstTickOfBar.



    Also note that if you have multiple added data series then you will need to specify for which Bars series specifically you would want this to occur once per bar, since OBU will update for all Bars objects.

    Comment


      #3
      I'm using on PriceChange but the Function is called within an IF Statement

      If CurrentBar != MyVar, then inside I set MyVar = CurrentBar.

      Comment


        #4
        Here's an example:


        if (
        (High[0] >= MAX(High,Lookback_NewHigh)[1])
        )
        {
        // Stages
        StageL_NewHigh = 1;

        // Prints
        if (
        (BarNum_NewHigh != CurrentBars[0]) // Prints once per bar
        )
        {
        PrintStage("NEW HIGH", CurrentBars[0]);
        }

        // Store Bar
        BarNum_NewHigh = CurrentBars[0];
        }


        And the result:

        - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        LONG STAGE: NEW HIGH. Bar 20977
        Time: 15:11:02
        - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        LONG STAGE: NEW HIGH. Bar 20977
        Time: 15:11:02
        - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        LONG STAGE: NEW HIGH. Bar 20977
        Time: 15:11:02
        - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -​​

        Comment


          #5
          Hello several,

          I would still recommend creating prints in order to better understand the behavior. Without further information from debugging, it's not possible to say what could be going on. Please debug the script using prints and provide the output so we can assist in analyzing the output.

          Comment


            #6
            Actually, I feel like an idiot. I had some other tabs with the an old version of the indicator loaded in it and they were printing to the same window.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            558 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            324 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            545 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            547 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X