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

Strategy Getting Bar Color from Indicator

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

    Strategy Getting Bar Color from Indicator

    I have an Indicator which paints a bar color on a simple condition. I add the Indicator into the strategy. When I run the strategy, the bars paints colors as expected. However, if I attempt to test for a bar color from within the strategy code using the BarColorSeries[0] by printing to the Output Window "Print("Bar Color = " + BarColorSeries[0])" , the result is always Color[Empty].

    Is there a way to access the ColorSeries from the indicator? How can I expose this information for use within the Strategy?

    Thanks,

    Jeff


    This is the Initialize section of the Strategy.
    Code:
    protected override void Initialize()
            {
    			Add(SimplePaintBar());
            }
    This is the Indicator Code for SimplePaintBar()
    Code:
    protected override void OnBarUpdate()
            {
    			if(CurrentBar < BarsRequired)
    				return;
    			
    			if(High[0] > High[1] && Low[0] > Low[1])
    			{
    				BarColorSeries[0] = Color.Blue;
    				BarColorSeries.Set(0,Color.Blue);
    			}
    			else if(High[0] < High[1] && Low[0] < Low[1])
    			{
    				BarColorSeries[0] = Color.Red;
    				BarColorSeries.Set(0,Color.Red);
    			}
    			else
    			{
    				BarColorSeries[0] =Color.Gray;
    				BarColorSeries.Set(0,Color.Gray);
    			}
            }

    #2
    Hello jfalbert19,
    I can get the bar color for realtime bars using the below code.

    in OnBarUpdate
    Code:
    Print(SimplePaintBar().BarColorSeries[0].ToString());

    Please make sure to add the indicator in the initialize section of the strategy code.
    Code:
    protected override void Initialize()
    {
    	Add(SimplePaintBar());
    }
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      I have that exact code in my Strategy. And as I indicated in my original post, I add the indicator as noted in the Initialize section.

      Code:
      Print(Time[0] + "Bar Color = " + SimplePaintBar().BarColorSeries[0].ToString());
      And this is the output I get.
      .....
      9/12/2012 3:10:00 PMBar Color = Color [Empty]
      9/12/2012 3:15:00 PMBar Color = Color [Empty]
      9/12/2012 3:20:00 PMBar Color = Color [Empty]
      9/12/2012 3:25:00 PMBar Color = Color [Empty]
      9/12/2012 3:30:00 PMBar Color = Color [Empty]

      Any suggestions on how to get the results you are seeing? I really doesn't do me any good to simply tell me that it works for you.

      Thanks,

      Jeff

      Comment


        #4
        Additionally, my apologies regarding the response about simply telling me that it works for you. I thought the Print statement code you provided was the same code that I had posted in the original post (I had tried so many including the one you suggested), but it was not. I have however re-tried the Print statement as formatted as you showed, and the results that I get are correctly reflected in Post #3.

        Comment


          #5
          Thanks for letting us know you were able to print this property.
          MatthewNinjaTrader Product Management

          Comment


            #6
            Matthew,

            I think this is where people's frustration with NT tech support comes from, because it is clear you did not read the full thread. My follow up post #4 was NOT to notify you that it worked, but merely to clarify that Ii had retried the suggested format and that as shown in Post #3, the output was still giving me the Color [Empty].

            I am STILL looking for some suggestion on how to resolve this problem. Please provide some direction on how to resolve my issue with the BarColorSeries.

            THank you,

            Jeff

            Comment


              #7
              Hello Jeff,
              You will be only getting the color information for realtime bars and not historical bars.

              Can you confirm are you receiving Color.Empty for realtime bars too?
              JoydeepNinjaTrader Customer Service

              Comment


                #8
                Confirmed. I am getting color empty for both realtime and historical bars.

                Comment


                  #9
                  Hello jfalbert19,
                  If you try the attached strategy then are you getting the right color prints.

                  Please note, only realtime colors will be available.
                  Attached Files
                  JoydeepNinjaTrader Customer Service

                  Comment


                    #10
                    John

                    Maybe this will help explain.

                    NinjaScript > Language Reference > Drawing >
                    BarColorSeries


                    Definition
                    A collection of historical bar colors.

                    Property Value
                    A color series type object. Accessing this property via an index value [int barsAgo] returns a color structure representing the referenced bar's color.

                    Note: This will only return the color of a bar in which an explicit color overwrite was used. Otherwise it will return Color [Empty].

                    Syntax
                    BarColorSeries
                    BarColorSeries[int barsAgo]


                    Examples
                    // Sets the color of the current bar to blue.
                    BarColorSeries[0] = Color.Blue;

                    // Sets the color of the previous bar to orange.
                    BarColorSeries[1] = Color.Orange;

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Shansen, 08-30-2019, 10:18 PM
                    24 responses
                    939 views
                    0 likes
                    Last Post spwizard  
                    Started by Max238, Today, 01:28 AM
                    0 responses
                    7 views
                    0 likes
                    Last Post Max238
                    by Max238
                     
                    Started by rocketman7, Today, 01:00 AM
                    0 responses
                    4 views
                    0 likes
                    Last Post rocketman7  
                    Started by wzgy0920, 04-20-2024, 06:09 PM
                    2 responses
                    28 views
                    0 likes
                    Last Post wzgy0920  
                    Started by wzgy0920, 02-22-2024, 01:11 AM
                    5 responses
                    33 views
                    0 likes
                    Last Post wzgy0920  
                    Working...
                    X