Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problems with DrawLine

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

    Problems with DrawLine

    I'm writing a strategy that automates the drawing of trend lines and for whatever reason can't seem to run the strategy successfully. Everything compiles, but when I try to run the program it doesn't let me check the box in the strategy tab. This is on NT7.

    I can't include High[period], with a period of more than 20 bars back, even though there are plenty of bars plotted on the screen. I check that there are enough bars plotted so that shouldn't be the problem.

    DrawLine("trendline", false, 30, High[30], currhbar, High[currhbar], Color.Red, DashStyle.Dash,2);

    Thanks in advance!
    Kevin

    #2
    Hello,

    Thank you for the post.

    When you say that you are unable to enable the strategy, is the box gray or do you check it and then it becomes unchecked?

    Could you check if you are seeing errors by opening the Log tab or the Tools -> Output Window? After doing this, try to enable the strategy and see if you get an error.

    If you are seeing a BarsAgo related error, you likely need a CurrentBar check before this logic:

    Code:
    if(CurrentBar < 30) return;
    I look forward to being of further assistance.

    Comment


      #3
      Hi,

      I've attached the error logs below. I've also added the CurrenBar < 30 condition but that has not made any difference. I am able to see the box but when I check it, it doesn't remain checked. I've also included the code below, when I omit the lines that are commented out, I am able to run the strategy and check the box and it stays checked. If I include those lines, it doesn't work, when I check the box it does not stay checked.


      **NT** Enabling NinjaScript strategy 'Trendline/e552405870ad415fa5c694f37017e646' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True CalculateOnBarClose=True MaxRestarts=4 in 5 minutes
      **NT** Error on calling 'OnBarUpdate' method for strategy 'Trendline/e552405870ad415fa5c694f37017e646': Object reference not set to an instance of an object.

      This is the code:

      if(CurrentBar < 30) return;
      int hbarperiod = 100;
      int currhbar = HighestBar(High, hbarperiod);
      double cslope = Slope(High,currhbar,0);

      int lperiod = 19;



      //DrawLine("trendline", false, 30, High[30], currhbar, High[currhbar], Color.Red, DashStyle.Dash,2);
      random = random + 1;
      //DrawText("hbar" + random, "High Bar: " + High[40] , 0, Close[5]+5, Color.Blue);
      DrawText("currhbar", "Current High Bar: " + currhbar,0, Close[5]+4, Color.Blue);
      DrawText("session", "Bars since session: " + Bars.BarsSinceSession,0, Close[5]+6, Color.Blue);
      DrawText("Current Slope", "Current Slope: " + cslope,0, Close[5]+2, Color.Red);
      DrawText("Current High Slope", "Current High Slope: " + chslope,0, Close[5]-3, Color.Green);
      DrawArrowUp("Arrow Up",true, currhbar, Close[5], Color.Purple);

      Comment


        #4
        Hello,

        Thank you for the reply.

        In this case, this would be a different problem not related to the amount of BarsAgo being used. Object reference not set to an instance of an object would mean that you are trying to use an object before it has a value.

        I am not able to see what syntax is causing this from what you have provided but we can learn the general area of the problem from the error its self.

        It shows that this error stemmed from 'OnBarUpdate'. I could suggest to Comment out all the code in OnBarUpdate and then compile.
        Next apply the strategy and ensure it stays enabled, this is just a check to make sure nothing else is causing a problem.
        After doing this, you could go line by line and uncomment 1 line at a time, then recompile and retest.

        Once you locate the line/lines causing the problem, if you are unsure why that is happening please post the specific syntax you found and we could look at it together.

        I look forward to being of further assistance.

        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