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

How do you do this?

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

    How do you do this?

    I cannot get this to work, could someone point me in the right direction? I'm simply trying to draw on the 1min chart that the indicator is loaded on when the current 5min close is > close from 1 5min bar ago.


    Code:
    protected override void Initialize()
    {
                Overlay    = false;
                Add(PeriodType.Minute, 5);
    }
    
    protected override void OnBarUpdate()
    {
       if (BarsInProgress == 0)
       {
             if (Closes[1][0] > Closes[1][1])
             {
                   DrawLine("LongLine" + CurrentBars[0], true, 0, 24.5, 0, 24.25, Color.LightGreen, DashStyle.Dash, 1);
              }
         }
    }


    Thanks

    #2
    LookOutBelow,

    Thank you for your post.

    You may want to set the DrawOnPricePanel to false to be able to do this as well.
    In the Initialize() section -
    Code:
    DrawOnPricePanel = false;
    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by lookOutBelow View Post
      I cannot get this to work, could someone point me in the right direction? I'm simply trying to draw on the 1min chart that the indicator is loaded on when the current 5min close is > close from 1 5min bar ago.


      Code:
      protected override void Initialize()
      {
                  Overlay    = false;
                  Add(PeriodType.Minute, 5);
      }
      
      protected override void OnBarUpdate()
      {
         if (BarsInProgress == 0)
         {
               if (Closes[1][0] > Closes[1][1])
               {
                     DrawLine("LongLine" + CurrentBars[0], true, 0, 24.5, 0, 24.25, Color.LightGreen, DashStyle.Dash, 1);
                }
           }
      }
      Thanks
      What is the error in your log?

      Comment


        #4
        Thanks for the response. Unfortunately this does not work. It still will not draw on the chart unless the OnBarUpdate() looks like this:

        Code:
        if (BarsInProgress == 0)
        {
           DrawLine("LongLine" + CurrentBars[0], true, 0, 24.25, 0, 24, Color.Red, DashStyle.Dash, 3 );
        }
        As soon as I put in an IF statement, it doesn't draw.. And yes, the condition is happening.


        Code:
        if (Close[0] > Close[1])
             DrawLine("LongLine" + CurrentBars[0], true, 0, 24.25, 0, 24, Color.Red, DashStyle.Dash, 3 );

        Comment


          #5
          lookOutBelow,

          The reason for this is because there will not be a bar ago, essentially there is not enough data at bar 0 to calculate to look a bar ago.

          The script will start from the far left of the chart at the very beginning where the CurrentBar will equal 0 and then start working to the right, calling each bar for OnBarUpdate();

          What you would nee to do instead is wait for after the first bar to be built from both data series and then run your if check for closes, to ensure that you have enough data.

          Code:
          if(CurrentBars[0] < 1 || CurrentBars[1] < 1) return;
          
          if(Closes[1][0] > Closes[1][1])
          {
               DrawLine();
          }
          Let me know if I can be of further assistance.
          Cal H.NinjaTrader Customer Service

          Comment


            #6
            Thanks Cal.

            I haven't had an opportunity to try this, but will as soon as I can.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by GussJ, 03-04-2020, 03:11 PM
            11 responses
            3,221 views
            0 likes
            Last Post xiinteractive  
            Started by andrewtrades, Today, 04:57 PM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by chbruno, Today, 04:10 PM
            0 responses
            6 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Started by josh18955, 03-25-2023, 11:16 AM
            6 responses
            437 views
            0 likes
            Last Post Delerium  
            Started by FAQtrader, Today, 03:35 PM
            0 responses
            9 views
            0 likes
            Last Post FAQtrader  
            Working...
            X