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

NT8 ChartStyle: different brushes for realtime/historical?

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

    NT8 ChartStyle: different brushes for realtime/historical?

    Hi there,

    I have made a HLC chartsyle with help from Michael here:



    At present I have the last bar only plotting purple all the time when historical AND real-time with no conditions in place.
    However, I wish the last bar to be another brush when the market is live only. See image attached.

    I tried this:

    Code:
    private bool realTime = false;
    
    protected override void OnStateChange()
    {[INDENT]if (State == State.Realtime)
    {
    realTime = true;    
    }
    [/INDENT]}
    
    if (realTime)
    {[INDENT]code here to plot purple. (This I have already).
    [/INDENT]}
    This does not work. I remember reading that "State == State.Realtime" is only checked when initializing and not after. I have managed to get this to work on indicators because I can place this logic under "OnBarUpdate()". But the ChartStyle does not seem to accept "OnBarUpdate()".

    Any solutions?

    Thank you.
    Attached Files

    #2
    Hello Sim22,

    Thanks for your post.

    You can try:

    if (State != State.Historical)
    {
    BarBrush = Brushes.Pink; // Color live bars pink.
    }
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thank you Paul....

      I have tried this. I tested further by printing the values to the output screen. When I use "State == State.Historical" it thinks it is "Live" and when I use "State != State.Historical" it thinks it is not live. So the logic is completely reversed.

      Comment


        #4
        Hello Sim22,

        Thanks for your reply.

        When I apply the code:

        if (State != State.Historical)
        {
        BarBrush = Brushes.Pink; // Color live bars pink.
        }

        As the indicator loads, all of the bar colors are left alone on the historical bars and as soon as the data is 'live" the bar that is forming is painted pink.

        If you add a print statement to the code I provided, you will observe that it will only print when on live bars and will paint the live bars pink (they will remain pink moving forward unless you have other code to color otherwise).
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Paul View Post
          As the indicator loads, all of the bar colors are left alone on the historical bars and as soon as the data is 'live" the bar that is forming is painted pink.

          If you add a print statement to the code I provided, you will observe that it will only print when on live bars and will paint the live bars pink (they will remain pink moving forward unless you have other code to color otherwise).
          Hi Paul,

          Yes, you are correct with the above statement. Either I'm not getting it or I have a valid point

          You mentioned "indicator". This is a ChartStyle.

          I added a "Print(State)" to an indicator of mine in "OnBarUpdate" and it went through the usual.....worked beautifully as you said it would. In fact I have used this logic in another volume indicator to do exactly what I wanted. However the HLC chartstyle will not accept "OnBarUpdate" so placing "Print(State)" within the "OnRender" code or anywhere within the namespace generates only State.Active regardless of whether NT is connected or not.

          I really didn't want to make a separate paint bar, so I want to get this sorted and offer it to the NT community.

          Please find the .cs file attached. The file "VSA_Ninja8_3.jpg" needs to be placed in the directory: "C:\Program Files (x86)\NinjaTrader 8" or it may generate an error.

          Regards,

          Simon.
          Attached Files

          Comment


            #6
            Hello Simon.,

            Thanks for your reply.

            You are correct I was thinking indicator all the way while you were wanting to do this in a chart style, my mistake.

            A chartstyle in unaware of the live/historical states which confirms your observations.

            Thanks for your contribution to the community with this bar type.
            Paul H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Brevo, Today, 01:45 AM
            0 responses
            3 views
            0 likes
            Last Post Brevo
            by Brevo
             
            Started by aussugardefender, Today, 01:07 AM
            0 responses
            3 views
            0 likes
            Last Post aussugardefender  
            Started by pvincent, 06-23-2022, 12:53 PM
            14 responses
            240 views
            0 likes
            Last Post Nyman
            by Nyman
             
            Started by TraderG23, 12-08-2023, 07:56 AM
            9 responses
            384 views
            1 like
            Last Post Gavini
            by Gavini
             
            Started by oviejo, Today, 12:28 AM
            0 responses
            6 views
            0 likes
            Last Post oviejo
            by oviejo
             
            Working...
            X