Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarBrush Current(forming) bar

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

    BarBrush Current(forming) bar

    Hi NT bods,

    Just testing some code, and based on the current realtime price is higher or lower than the previous high or low I want to colour the forming bar (not bar[1]) but, it doesn't seem to work, what am I missing ?



    //snippets of code

    if (State == State.SetDefaults)
    {
    Description = "test";
    Name = "test";
    Calculate = Calculate.OnEachTick;
    }

    //add additional data sources
    else if (State == State.Configure)
    {
    AddDataSeries(Instrument.FullName, BarsPeriodType.Day, 1); /// not used in this example,
    AddDataSeries(Instrument.FullName, BarsPeriodType.Tick, 1); /// tick data for realtime prices
    }

    protected override void OnBarUpdate()
    {
    if(BarsInProgress == 2){
    if( Closes[2][0]<Lows[0][1] ) BarBrushes[0] = Brushes.Magenta;
    if( Closes[2][0]>Highs[0][1] ) BarBrushes[0] = Brushes.Lime;
    }
    }
    Last edited by 12tkram; 09-27-2019, 12:24 PM.

    #2
    Hello 12tkram,

    Thank you for your post.

    Do you see any errors in your log when you try to run this? If you're not checking to make sure there's enough bars on the chart before processing starts you'll hit an error - in this case you can't access the low of one bar back of the main series if this tries to run on the very first bar, so you need to make sure it's not processing until there's enough. You can add this to the beginning of OnBarUpdate to avoid this:

    if (CurrentBars[0] < 2)
    return;

    If you add this do you see the bars being painted properly?

    Please let us know if we may be of further assistance to you.

    Comment


      #3
      Hi Kate, thanks for the response, I have that already in my code, I didnt post it as I didnt think it was relevant.


      if(CurrentBars[0] < 2 ) return;
      if(CurrentBars[1] < 2 ) return;
      if(CurrentBars[2] < 2 ) return;

      TBH, it looks like it colours Bar[1] while Bar[0] is forming
      Last edited by 12tkram; 09-27-2019, 12:59 PM.

      Comment


        #4
        Yeah, BarBrush and BarBrushes[0] both change Bar[1], not Bar[0] (the current bar) .. I modded to code just to change the colour each tick ..

        is there any way to change the colour for the current forming bar ? Bar[0]

        Comment


          #5
          Hello 12tkram,

          Thank you for your reply.

          Attached is the little example I made to test this, which does color the bar as it's forming. Perhaps comparing this with your code may be of assistance to you.

          Please let us know if we may be of further assistance to you.
          Attached Files

          Comment


            #6
            cool, thanks, I bet I have missed something really simple

            Comment


              #7
              brilliant lol .. I can't even spot the difference I have gone cross eyed .. cut and pasted your code over mine and it works like a charm XD many thanks!!!!!

              Comment

              Latest Posts

              Collapse

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