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 SalmaTrader, 07-07-2026, 10:26 PM
      0 responses
      54 views
      0 likes
      Last Post SalmaTrader  
      Started by CarlTrading, 07-05-2026, 01:16 PM
      0 responses
      25 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 06-17-2026, 10:32 AM
      0 responses
      17 views
      0 likes
      Last Post CaptainJack  
      Started by kinfxhk, 06-17-2026, 04:15 AM
      0 responses
      23 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Started by kinfxhk, 06-17-2026, 04:06 AM
      0 responses
      24 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Working...
      X