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

Paint bars - how to?

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

    Paint bars - how to?

    Hi,
    I'm a Tratestation guy and am looking to move over to NT. I have my charts set up so any bar (regular OHLC type bar) closed above the moving average is a green bar, and all bars closed below the moving average is red.

    In TS this is called a Paintbar. What is the terminology for this in NT, and can it be done here?

    Thanks!
    Peter

    #2
    Welcome to the forums PeterGregg! We're happy to hear that you are considering the NinjaTrader platform.

    What you are trying to accomplish can be done with an indicator that checks if the Close is above or below your moving average's plot value, and sets the bar color with BarBrush.

    Documentation on BarBrush can be found here - https://ninjatrader.com/support/help...s/barbrush.htm

    If you have any additional questions, please don't hesitate to ask.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hi Jim,

      You probably think I am a dummy, but I haven't gotten anywhere with this. Can you tell me a little bit more - remember, I am green with this right now.

      Peter

      Comment


        #4
        Hello Peter,

        Sure, I can provide more detail. I put a quick demonstration together explaining.

        Demo - https://drive.google.com/file/d/1Jli...w?usp=drivesdk

        Some more information on how NinjaScripts operate and how to work with Price Series can be referenced below. I may also suggest using the Strategy Builder and using the View Code button as you are create small portions of logic to see how this tool creates its syntax.


        If there is anything else we can do to help, please let us know.
        JimNinjaTrader Customer Service

        Comment


          #5
          Hi Jim,
          Thanks for the video, that was a wow factor!

          I already did exactly as you showed so my problem may be at a more elementary level. Sorry for taking up your time. The good thing is I did better than I thought as my try was exactly like yours - or so I think, but I get an error on the code I paste in. You did yours in MyCustomIndicator8 and I did mine in MyCustomIndicator1

          else if (State == State.Configure)
          {
          }
          }

          protected override void OnBarUpdate()
          {
          // Sets the bar color to yellow
          BarBrush = Brushes.Yellow;

          // Sets the brush used for the bar color to its default color as defined in the chart properties dialog
          BarBrush = null;

          // Sets the bar color to yellow if the 20 SMA is above the 50 SMA and the closing
          // price is above the 20 SMA (see image below)
          if (SMA(20)[0] > SMA(50)[0] && Close[0] > SMA(20)[0])
          BarBrush = Brushes.Yellow;

          }
          }
          }

          #region NinjaScript generated code. Neither change nor remove.

          I am getting this error -
          'OnBarUpdate': member names cannot be the same as their enclosing type
          Line 52 Column 27 Code CS0542

          So I think it is something in basic code creation that I don't know yet.

          Peter

          Comment


            #6
            Hi Jim,

            Played with it over the weekend. I deleted all I had done and started over and it worked. I had a suspicion that a name was being used that shouldn't be using. Your video was awesome FYI - thank you!.

            In applying this indicator I would like to know how to have more than one formula or argument in one indicator. For example, if the bar closes above a SMA it gets painted green and if below it gets painted red.

            For now I made 2 separate indicators, one for the up bar and one for the lower bar. This is in relation to whether the bar is above a moving average verses a bar being below a moving average. I am asking how to make the same argument twice, of course tweaking what needs to change in regards to the argument (above or beneath), but how do I place the 2 arguments together inside of one indicator, can that be done?

            Regards,
            Peter

            Comment


              #7
              Hello PeterGregg,

              This could be done with using if/else statements within the OnBarUpdate() method to set BarBrush under different conditions. NinjaScript is built on C# and any C# resources can be useful for learning the correct NinjaScript syntax. In addition to using the Strategy Builder and clicking "View Code," you may wish to look into our basic programming resources in the NinjaTrader 7 help guide. If you are looking for more more in depth materials, I may suggest looking into education C# materials externally to NinjaTrader.

              As a tip, I may suggest creating some logic in the Strategy Builder for this task and specifically to use "Actions > Drawing > Set bar color." The resulting NinjaScript will then provide some direction for how the code can be modified in other NinjaScripts (including indicators.)

              C# Programming Resources (NT7 Help Guide) - https://ninjatrader.com/support/help...g_concepts.htm

              Please let us know if there is anything else we can do to help.
              JimNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by hurleydood, 09-12-2019, 10:45 AM
              14 responses
              1,096 views
              0 likes
              Last Post Board game geek  
              Started by cre8able, Yesterday, 04:16 PM
              1 response
              16 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by cre8able, Yesterday, 04:22 PM
              1 response
              14 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by stafe, 04-15-2024, 08:34 PM
              5 responses
              28 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by StrongLikeBull, Yesterday, 04:05 PM
              1 response
              12 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Working...
              X