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

Problem with DrawLine

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

    Problem with DrawLine

    I have logic in my strategy to draw a set of lines above pivots if the trend is up and below the pivots if the trend is down:-

    if(BarsInProgress == 0) // draw pivots on primary bars in progress
    {
    if(this.indPivAverage.ExtrnTrend[0] == 1)
    {
    DrawLine("r2l" + sessionCount, false, Bars.BarsSinceSession, Math.Max(r2 + entryAllowance * TickSize, r2 + (r3 - r2)*0.25) , 0 , Math.Max(r2 + entryAllowance * TickSize, r2 + (r3 - r2)*0.25) ,Color.Orange,DashStyle.DashDotDot,1);
    DrawLine("r1l" + sessionCount, false, Bars.BarsSinceSession, Math.Max(r1 + entryAllowance * TickSize, r1 + (r2 - r1)*0.25) , 0 , Math.Max(r1 + entryAllowance * TickSize, r1 + (r2 - r1)*0.25) ,Color.Orange,DashStyle.DashDotDot,1);
    DrawLine("ppl" + sessionCount, false, Bars.BarsSinceSession, Math.Max(pp + entryAllowance * TickSize, pp + (r1 - pp)*0.25) , 0 , Math.Max(pp + entryAllowance * TickSize, pp + (r1 - pp)*0.25) ,Color.Orange,DashStyle.DashDotDot,1);
    DrawLine("s1l" + sessionCount, false, Bars.BarsSinceSession, Math.Max(s1 + entryAllowance * TickSize, s1 + (pp - s1)*0.25) , 0 , Math.Max(s1 + entryAllowance * TickSize, s1 + (pp - s1)*0.25) ,Color.Orange,DashStyle.DashDotDot,1);
    DrawLine("s2l" + sessionCount, false, Bars.BarsSinceSession, Math.Max(s2 + entryAllowance * TickSize, s2 + (s1 - s2)*0.25) , 0 , Math.Max(s2 + entryAllowance * TickSize, s2 + (s1 - s2)*0.25) ,Color.Orange,DashStyle.DashDotDot,1);
    DrawLine("s3l" + sessionCount, false, Bars.BarsSinceSession, Math.Max(s3 + entryAllowance * TickSize, s3 + (s2 - s3)*0.25) , 0 , Math.Max(s3 + entryAllowance * TickSize, s3 + (s2 - s3)*0.25) ,Color.Orange,DashStyle.DashDotDot,1);
    }

    if(this.indPivAverage.ExtrnTrend[0] == -1)
    {

    DrawLine("r3s" + sessionCount, false, Bars.BarsSinceSession, Math.Min(r3 - entryAllowance * TickSize, r3 - (r3 - r2)*0.25) , 0 , Math.Min(r3 - entryAllowance * TickSize, r3 - (r3 - r2)*0.25) ,Color.Orange,DashStyle.DashDotDot,1);
    DrawLine("r2s" + sessionCount, false, Bars.BarsSinceSession, Math.Min(r2 - entryAllowance * TickSize, r2 - (r2 - r1)*0.25) , 0 , Math.Min(r2 - entryAllowance * TickSize, r2 - (r2 - r1)*0.25) ,Color.Orange,DashStyle.DashDotDot,1);
    DrawLine("r1s" + sessionCount, false, Bars.BarsSinceSession, Math.Min(r1 - entryAllowance * TickSize, r1 - (r1 - pp)*0.25) , 0 , Math.Min(r1 - entryAllowance * TickSize, r1 - (r1 - pp)*0.25) ,Color.Orange,DashStyle.DashDotDot,1);
    DrawLine("pps" + sessionCount, false, Bars.BarsSinceSession, Math.Min(pp - entryAllowance * TickSize, pp - (pp - s1)*0.25) , 0 , Math.Min(pp - entryAllowance * TickSize, pp - (pp - s1)*0.25) ,Color.Orange,DashStyle.DashDotDot,1);
    DrawLine("s1s" + sessionCount, false, Bars.BarsSinceSession, Math.Min(s1 - entryAllowance * TickSize, s1 - (s1 - s2)*0.25) , 0 , Math.Min(s1 - entryAllowance * TickSize, s1 - (s1 - s2)*0.25) ,Color.Orange,DashStyle.DashDotDot,1);
    DrawLine("s2s" + sessionCount, false, Bars.BarsSinceSession, Math.Min(s2 - entryAllowance * TickSize, s2 - (s2 - s3)*0.25) , 0 , Math.Min(s2 - entryAllowance * TickSize, s2 - (s2 - s3)*0.25) ,Color.Orange,DashStyle.DashDotDot,1);
    }
    }


    however on somedays it is plotting both above and below the pivots and some days not plotting at all.I have gone though a debug with visual studio and it is processing as I expected, so im not sure why this is happening?


    When I eliminate all other draw items it still wont draw?
    Last edited by GKonheiser; 07-25-2014, 04:34 AM.

    #2
    GKonheiser, then you would need to continue to strip it / isolate even further - first thing would be the condition you use to draw the lines and decide which trend direction to use, does that trigger as you expect? Just print the values you would use for the drawing. That would give the most direct feedback how your code is processed.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      I am trying to use this print statement to pin point the issue but am getting an error with it:-

      Print(Time[0] + this.indPivAverage.ExtrnTrend[0] );

      I cant see what is wrong with it??

      Comment


        #4
        What error do you exactly get?
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Operator '+' cannot be applied to operands of type 'System.DateTime' and 'double'

          Comment


            #6
            I see, ok. Would try adding a space in there, which would be beneficial on top for reading formatting -

            Print(Time[0] + " " + this.indPivAverage.ExtrnTrend[0] );
            BertrandNinjaTrader Customer Service

            Comment


              #7
              ya your right worked perfectly.

              Comment


                #8
                Found the problem, it is switching the value of this.indPivAverage.ExtrnTrend[0] at 22.00, still in session, and then of course printing back the whole session. Thanks for your help. : )

                Comment


                  #9
                  So if I want to exclude a particular time what is the formatting,

                  This isn't working,

                  if(this.indPivAverage.ExtrnTrend[0] == -1 && Time[0].TimeOfDay != 22:00:00);

                  Comment


                    #10
                    TimeOfDay would be given you a TimeSpan so you want to compare to one for your condition, too -

                    .... != new TimeSpan(22, 0, 0)
                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      if i just want to use Time[0], why would this not work?

                      ....&& Time[0] != 2200);

                      Comment


                        #12
                        Time[0] is giving you a DateTime return, which your int 2200 would not be and the compiler would not know how to translate between the two. You can work though with feeding the datetime into ToTime to arrive at an integer representation.

                        ToTime(Time[0]) != 220000
                        BertrandNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by MacDad, 02-25-2024, 11:48 PM
                        7 responses
                        157 views
                        0 likes
                        Last Post loganjarosz123  
                        Started by Belfortbucks, Today, 09:29 PM
                        0 responses
                        6 views
                        0 likes
                        Last Post Belfortbucks  
                        Started by zstheorist, Today, 07:52 PM
                        0 responses
                        7 views
                        0 likes
                        Last Post zstheorist  
                        Started by pmachiraju, 11-01-2023, 04:46 AM
                        8 responses
                        151 views
                        0 likes
                        Last Post rehmans
                        by rehmans
                         
                        Started by mattbsea, Today, 05:44 PM
                        0 responses
                        6 views
                        0 likes
                        Last Post mattbsea  
                        Working...
                        X