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

Show block if a condition is true

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

    Show block if a condition is true

    Hey guys !

    I'm got an indicator which plot a line. I just would like to plot blocks (or dash or whatever) only when the value changes. Is there any easy way to do this ?

    Thanks !
    Attached Files

    #2
    Hello After,


    You could do this by comparing the current value of your indicators current bar value to the previous bar value. I have included our Help Guides on Developing Indicators to assist you further in getting familiar with building indicators.
    I have included an example below of what this would look like.
    Code:
    [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2][/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000FF]protected[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]override[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]void[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]OnBarUpdate()[/SIZE][/FONT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
    [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2]      {[/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
    [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2][COLOR=#0000FF]     if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]/*Replace SMA your Indicator name, Replace myInput0 with your period*/[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]SMA(myInput0)[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] != SMA(myInput0)[[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]])[/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
    [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2]     {PlaySound([/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800000]@"Alert1.wav"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
    [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2]     DrawArrowDown(CurrentBar.ToString(),[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2], Close[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] + TickSize, Color.Blue);} [/SIZE][/FONT][FONT=Courier New]}[/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
    [FONT=Courier New][SIZE=2][/SIZE][/FONT]
    [/LEFT][/FONT][/COLOR]
    Shawn B.NinjaTrader Customer Service

    Comment


      #3
      Great it works thanks !

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by andrewtrades, Today, 04:57 PM
      1 response
      9 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
      436 views
      0 likes
      Last Post Delerium  
      Started by FAQtrader, Today, 03:35 PM
      0 responses
      8 views
      0 likes
      Last Post FAQtrader  
      Started by rocketman7, Today, 09:41 AM
      5 responses
      19 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X