Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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);
                }​
            }​
    Chris L.NinjaTrader Customer Service

    Comment


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

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by RubenCazorla, 08-30-2022, 06:36 AM
      3 responses
      77 views
      0 likes
      Last Post PaulMohn  
      Started by f.saeidi, Yesterday, 12:14 PM
      9 responses
      23 views
      0 likes
      Last Post f.saeidi  
      Started by Tim-c, Today, 03:54 AM
      0 responses
      3 views
      0 likes
      Last Post Tim-c
      by Tim-c
       
      Started by FrancisMorro, Today, 03:24 AM
      0 responses
      4 views
      0 likes
      Last Post FrancisMorro  
      Started by Segwin, 05-07-2018, 02:15 PM
      10 responses
      1,772 views
      0 likes
      Last Post Leafcutter  
      Working...
      X