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

adding script not working

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

    adding script not working

    I am trying to draw a box around certain bar patterns. My code works and a box is draw, but only when I code for one pattern. When I try to add patterns using the "IF" statement the boxes vanish. For example Pattern #1 works independently. Patern #2 works independently. Pattern #1 and #2 combined in same indicator do not work.

    What am I missing here?

    here is my code:

    protectedoverridevoid OnBarUpdate()
    {
    if (CurrentBar < 1) return;

    // Trying to draw box on certain patterns

    // Pattern #1
    if ( Criteria )

    { Draw Rectangle }

    // Pattern #2
    if ( Criteria )
    {Draw Rectangle}
    }

    #2
    You are most likely using the same string name for your rectangles. If they share the same name the latest call to the Draw() method will override the old rectangle.

    You want unique rectangle names. Try this as a technique:
    "Rectangle" + CurrentBar
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      thanks for responding, I tried your suggestion but no luck.

      here is a sample bit of code. Each pattern will display on their own, but together, I get nothing.

      any ideas?

      protectedoverridevoid OnBarUpdate()
      {
      if (CurrentBar < 1) return;

      // Put Patterns below here:
      // Pattern #1
      if (
      High[
      0] > High[1] &&
      High[
      1] > High[2] &&
      High[
      2] > High[3]
      )

      {
      DrawRectangle(
      "MyRectangle"+ CurrentBar, 4, MIN(Low, 4)[0] - TickSize, 0, MAX(High,4)[0] + TickSize , Color.Blue, Color.Yellow,2);
      }

      //Pattern #2
      if (High[0] > High[3])
      {
      DrawRectangle(
      "rectwo"+CurrentBar, 4, MIN(Low, 4)[0] - TickSize, 0, MAX(High,4)[0] + TickSize , Color.Blue, Color.Yellow,2);
      }

      }

      Comment


        #4
        Please check your error logs for any messages. You might be running into this: http://www.ninjatrader-support.com/v...ead.php?t=3170

        Also, you seem to be drawing over in the same spot for both patterns. To confirm you may want to draw in different areas and not rely on colors/transparencies to tell if it is drawing or not.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Josh,

          I figured out the problem. However I want to make sure I understand what I did.

          I changed the code from:

          if (CurrentBar < 1)
          return;


          to

          if (CurrentBar < 5)
          return;



          Does this mean my indicator needs 5 bars to plot instead of 1 ?

          So by using "1", I did not have enough bars to plot?

          Comment


            #6
            Correct. Judging from the code you provided earlier you were using index values up to 3. This means you need at least 3 bars to work with beforehand and so you would need at least an if-statement with CurrentBar < 3.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              got it, thank you

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by r68cervera, Today, 05:29 AM
              0 responses
              2 views
              0 likes
              Last Post r68cervera  
              Started by geddyisodin, Today, 05:20 AM
              0 responses
              3 views
              0 likes
              Last Post geddyisodin  
              Started by JonesJoker, 04-22-2024, 12:23 PM
              6 responses
              35 views
              0 likes
              Last Post JonesJoker  
              Started by GussJ, 03-04-2020, 03:11 PM
              12 responses
              3,239 views
              0 likes
              Last Post Leafcutter  
              Started by AveryFlynn, Today, 04:57 AM
              0 responses
              6 views
              0 likes
              Last Post AveryFlynn  
              Working...
              X