Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Vertical line is not drawn at specified time?

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

    Vertical line is not drawn at specified time?

    Hello there,

    I'm trying to draw a vertical line as specified (e.e. 9:30 AM EST). However it is drawn somewhat earlier than that.

    My code is:
    Code:
           
    PrintCSV(LogWindow, "================================================================================================");
    PrintCSV(LogWindow, "\"Strategy: Trading Opened. DayProfit " + DayProfit.ToString(format) + " Day Profit Target " + DayProfitTarget.ToString(format) + " Day Stop Loss " + DayStopLoss.ToString(format) + " Strategy Profit " + StrategyProfit.ToString(format) + "\"");
    PrintCSV(LogWindow, "================================================================================================");
    Draw.VerticalLine(this, "Trading Open " + CurrentBar.ToString(), 10, Brushes.Lime);​
    As captured in the log the code is executed when current bar is 9:30EST.

    But the line is drawn at 8:47AM EST.

    Many Thanks! Caesar.
    Attached Files

    #2
    Hi Caesar, thanks for writing in. This is happening because OnBarUpdate has ran for the second to last bar (assuming the script is running OnBarClose) Here is a test that draws the line 10 bars ago and also marks the bar where it was drawn:

    Code:
    protected override void OnBarUpdate()
            {
    
                    if(CurrentBar < 10)
                        return;
    
                    Print("Drawing Line 10 bars ago at " + Time[0] + " " + CurrentBar);
                    Draw.Dot(this, "DOT", false, Time[0], High[0], Brushes.Cyan);
                    Draw.VerticalLine(this, "Line", 10, Brushes.Lime);
                ​
            }​
    The alternative is to run the script OnEachTick and run this code on the first tick of the bar:

    Code:
            protected override void OnBarUpdate()
            {
                if(IsFirstTickOfBar)
                {
                    if(CurrentBar < 10)
                        return;
    
                    Print("Drawing Line 10 bars ago at " + Time[0] + " " + CurrentBar);
                    Draw.Dot(this, "DOT", false, Time[0], High[0], Brushes.Cyan);
                    Draw.VerticalLine(this, "Line", 10, Brushes.Lime);
                }​
            }​

    Comment


      #3
      Thank you so much! I will try this out.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      590 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      342 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      555 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      552 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X