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

Problems with Bar.Color

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

    Problems with Bar.Color

    Hi

    I am trying to change the color of the price bars of a chart with the following code

    if(CurrentBar < Period) return;
    if(ValidTradeTime(Time[0]) == true)
    {
    BarColor = Color.Wheat;
    BackColor = Color.White;
    }

    ValidTradeTime is taken from the user defined methods section of the user manual. I am unable to get this code to work to change the color of a price bar. Could one of the moderators etc supply a code example whereby the bar color is changed? I have tried the sample indicator CCI
    Custom in the help guide but that is not working either!

    Thanks


    #2
    MicroAl, everything works fine for me. Please try the attached code. Here is the important part:
    Code:
    protected override void OnBarUpdate()
            {
                if (Rising(ADX(aDXPeriod)) == true ||  ADX(aDXPeriod)[0] > 25)
                {
                    BarColor = Color.Green;
                    BackColor = Color.LightBlue;
                }
                else
                {
                    BarColor = Color.Pink;
                    BackColor = Color.LightPink;
                }
            }
    Attached Files
    AustinNinjaTrader Customer Service

    Comment


      #3
      Problems with Bar.Color

      Austin

      The file changes the bar colors fine on my copy of Ninja - Many thanks

      Now all I have to do is work out what is going wrong

      Comment


        #4
        Great to hear! I have a feeling the issue has to do with the ValidTradeTime() method you're using...
        AustinNinjaTrader Customer Service

        Comment


          #5
          Problems with Bar.Color

          Austin

          You are right there is obviously a problem with my ValidTradeTime Method

          public bool ValidTradeTime(DateTime barTime)
          {
          //If the Current Bar Time is greater than 10 AM and less than 3.46 PM
          if(ToTime(barTime) > ToTime(10,0,0) && ToTime(barTime) < ToTime(3,46,0))
          returntrue;

          returnfalse;
          }

          I placed the method in the userdefinedmethods file (indicator) and then saved it as ValidTradeTime. So I am trying to call this method from another indicator

          All I want to do is to change the bar color depending on the time of day.
          I have tried to place the if statement directly in the indicator script but then I get a message "barTime not recognised"

          Any help would be appreciated

          Comment


            #6
            Problems with Bar.Color

            Hi

            Solved my problem using the following code generated by the condition builder

            if (ToTime(Time[0]) > ToTime(14, 30, 0)
            && ToTime(Time[
            0]) < ToTime(21, 15, 0))

            Is there any way to use the condition builder for indicator development? You can right click in a strategy after typing
            if( to get the condition builder, but this does not work in an indicator script. Perhaps this could be changed in a later version of Ninja.

            Comment


              #7
              Originally posted by MicroAl View Post
              Is there any way to use the condition builder for indicator development?
              There is not, but I'll forward the request.

              My favorite method was to just use the condition builder in a strategy script and just cut and paste the code into the indicator script. The only downside is there are two editor windows open, but it definitely works.
              AustinNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by bmartz, 03-12-2024, 06:12 AM
              5 responses
              32 views
              0 likes
              Last Post NinjaTrader_Zachary  
              Started by Aviram Y, Today, 05:29 AM
              4 responses
              13 views
              0 likes
              Last Post Aviram Y  
              Started by algospoke, 04-17-2024, 06:40 PM
              3 responses
              28 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by gentlebenthebear, Today, 01:30 AM
              1 response
              8 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by cls71, Today, 04:45 AM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Working...
              X