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

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.
    JesseNinjaTrader Customer Service

    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.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by TraderBCL, Today, 04:38 AM
        2 responses
        16 views
        0 likes
        Last Post TraderBCL  
        Started by martin70, 03-24-2023, 04:58 AM
        14 responses
        106 views
        0 likes
        Last Post martin70  
        Started by Radano, 06-10-2021, 01:40 AM
        19 responses
        609 views
        0 likes
        Last Post Radano
        by Radano
         
        Started by KenneGaray, Today, 03:48 AM
        0 responses
        5 views
        0 likes
        Last Post KenneGaray  
        Started by thanajo, 05-04-2021, 02:11 AM
        4 responses
        471 views
        0 likes
        Last Post tradingnasdaqprueba  
        Working...
        X