Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How can I retrieve the bar color within a strategy

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

    How can I retrieve the bar color within a strategy

    Hi,

    I have a simple indicator which changes the bar color on certain conditions. The indicator is my own and it works absolutley fine.

    However, I want to be able to find out what the current bar color is from within a strategy and just can't find the correct way to do this.

    From within my strategy I want to do something like...

    MyIndicator.BarColor == Color.Blue

    I'm trying to use the same structure within the indicator used for passing back/forth information to the indicator setup dialog and the strategy wizard "plot" parameter. I can see how to do this for a plot but as the bar color is just a property rather than a data series I can't see how to do it, or find any examples!!

    The only other thing I can think of is to create a public variable within the indicator and access this directly, not sure this will work but that's my next step. Alternatively I could merge the indicator within the strategy which I'd rather not do.

    Hope this makes sense to anyone! If you can point me in the direction of an indicator which does this sort of thing I can use as a model that woudl be great!!

    Thanks

    Oz

    #2
    Hi oz-dog,

    Please see the below sample that details the process of exposes a series or object to a strategy:
    TimNinjaTrader Customer Service

    Comment


      #3
      Hi Tim,

      Fantastic, just what I was looking for!

      Thanks for the super fast response, really appreciated.

      Oz.

      Comment


        #4
        Hi Tim,

        Hmmm... not sure why but I can't get this to work properly.

        I've modelled the example and both the indicator and the strategy compile but the values (bool in this case) do not appear to be passed back to the strategy.

        I've put Print statements in both the indicator and strategy at the points that the bool values are set and the indicator is correctly setting its "bull and bear" variables. However the values returned from the call to this indicator in the strategy are always false.

        I also noticed that in the output window first all of the "strategy" output is printed followed by all of the "indicator" output, not sure if this means anything probably just buffering but thought I'd mention it!

        I've looked over both examples again and can't see any obvious differences, I've even used the same variable names so that I could copy and paste to avoid typos.

        Any ideas?

        Thanks again for your help.

        Oz

        Comment


          #5
          Hi oz-dog,

          Are you getting any errors in the Log tab?
          Can you try importing the samples to see if they work as expected, from the native code, by changing it suit your needs, then transferring it (copying it to) your code?
          Last edited by NinjaTrader_Tim; 11-24-2010, 01:05 PM.
          TimNinjaTrader Customer Service

          Comment


            #6
            Hi Tim,

            Thanks, I always forget to look at the log!

            It has a repeated entry of the type:

            "Error on calling the 'OnBarUpdate' method for indicator 'MyImpulseSystem' on bar 20: Object reference not set to an instance of an object"

            This also appears this morning before I even started looking at the passing back of results so I assume this is highlighting a bug in my indicator? The indicator works fine though - any suggestions on what type of problem this might be to help me narrow the field?

            Thanks

            Oz

            Comment


              #7
              Hi Tim,

              Bug found, all sorted.

              Thanks again for all your help.

              Oz

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              566 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              330 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              101 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              547 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              548 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X