only print a bar once a condition is met

tatl

Member
can i make a lower histogram bar chart only print a bar if a certain condition is met ( like say, one minute has elapsed )

rather than print a bar with every new chart candle in pace with the minimum aggregation period of the chart??
 
can i make a lower histogram bar chart only print a bar if a certain condition is met ( like say, one minute has elapsed )

rather than print a bar with every new chart candle in pace with the minimum aggregation period of the chart??

yes , if condition then 0 . and no bar will be drawn.

your example doesn't make sense. if the a chart is 1 minute time, after every minute , another histogram bar will be drawn...
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

yes , if condition then 0 . and no bar will be drawn.

your example doesn't make sense. if the a chart is 1 minute time, after every minute , another histogram bar will be drawn...
sorry in my example it would be a tick chart. so the condition would be that 1 minute has elapsed, using some timing code

and if that condition is met, then another histogram bar would be printed (say of cumulative volume within that minute)

so a simple way to put the question: "how can i see a minute volume histogram on a tick chart?"

i dont just want the bar to "not be drawn, leaving an empty space" if condition is 0, i want there to be no space at all. i want to control the frequency with which bars (or empty spaces) appear.
 
Last edited:
sorry in my example it would be a tick chart. so the condition would be that 1 minute has elapsed, using some timing code

and if that condition is met, then another histogram bar would be printed (say of cumulative volume within that minute)

so a simple way to put the question: "how can i see a minute volume histogram on a tick chart?"

i dont just want the bar to "not be drawn, leaving an empty space" if condition is 0, i want there to be no space at all. i want to control the frequency with which bars (or empty spaces) appear.
It's not normally possible to do minutes on a tick chart. But it can be fudged. What you're looking at is volume in gray overlayed (in the volume subgraph but on the left axis really) for 10 minute aggregations of volume over 100 ticks on the /MES chart. It looks better than I thought it might, but of course, your mileage may vary. It skips a bar of plot so that the volume "histogram" isn't all connected with strange angled cloud lines, and as such, occasionally it won't draw a cloud at all but the volume line still shows up. I wouldn't try running it on 1 min, but you may of course try. I looked at it on 5 and 10 minute aggregations over the 100 tick chart. If your "histogram" has angley bits on the left, you need to increase the long-winded and hand-coded candle_width def statement to be longer (I don't deal with things so fast that there should be more than 40 bars in a 5 or 10 minute block, but this is where you can acomodate runs of more candles than that in the given agg time/

P.S. I didn't whip this up just now. I've been toying with time aggregation on tick charts for more than three or four years now.

-mashume


b9LAx3Y.png


Code:
declare lower;
declare zerobase;

def trade_time_s = SecondsFromTime(0000);
def delta_t_s = trade_time_s - trade_time_s[1];
def delta_t_m = delta_t_s / 60;
input minutes = 10;

def trades = tick_count();
# def trades = Volume;
def trades_per_minute = trades / delta_t_m;

def average = SimpleMovingAvg(trades_per_minute, 5);

# def five_min = if (trade_time_s % 300) == 0 then 1 else 0;
def min_blocks = trade_time_s % (60 * minutes);

def time_boundary = if min_blocks[1] > min_blocks then 1 else 0;
# addVerticalLine(time_boundary == 1, text="5m", color.black);

def time_open = if time_boundary == 1 then open else time_open[1];
def time_volume = if time_boundary == 1 then VOLUME else time_volume[1] + VOLUME;

# plot o = time_open;
# o.SetPaintingStrategy(paintingStrategy.HORIZONTAL);


def candle_width = if min_blocks[0] > min_blocks[-1] then 1
    else if min_blocks[-1] > min_blocks[-2] then 2
    else if min_blocks[-2] > min_blocks[-3] then 3
    else if min_blocks[-3] > min_blocks[-4] then 4
    else if min_blocks[-4] > min_blocks[-5] then 5
    else if min_blocks[-5] > min_blocks[-6] then 6
    else if min_blocks[-6] > min_blocks[-7] then 7
    else if min_blocks[-7] > min_blocks[-8] then 8
    else if min_blocks[-8] > min_blocks[-9] then 9
    else if min_blocks[-9] > min_blocks[-10] then 10
    else if min_blocks[-10] > min_blocks[-11] then 11
    else if min_blocks[-11] > min_blocks[-12] then 12
    else if min_blocks[-12] > min_blocks[-13] then 13
    else if min_blocks[-13] > min_blocks[-14] then 14
    else if min_blocks[-14] > min_blocks[-15] then 15
    else if min_blocks[-15] > min_blocks[-16] then 16
    else if min_blocks[-16] > min_blocks[-17] then 17
    else if min_blocks[-17] > min_blocks[-18] then 18
    else if min_blocks[-18] > min_blocks[-19] then 19
    else if min_blocks[-19] > min_blocks[-20] then 20  
    else if min_blocks[-20] > min_blocks[-21] then 21
    else if min_blocks[-21] > min_blocks[-22] then 22
    else if min_blocks[-22] > min_blocks[-23] then 23
    else if min_blocks[-23] > min_blocks[-24] then 24
    else if min_blocks[-24] > min_blocks[-25] then 25
    else if min_blocks[-25] > min_blocks[-26] then 26
    else if min_blocks[-26] > min_blocks[-27] then 27
    else if min_blocks[-27] > min_blocks[-28] then 28
    else if min_blocks[-28] > min_blocks[-29] then 29
    else if min_blocks[-29] > min_blocks[-30] then 30
else 41;

def final_volume = getValue(time_volume, -(candle_width) + 1);
plot v = if time_boundary[0] != 1 then final_volume else double.nan;
v.SetPaintingStrategy(paintingStrategy.HORIZONTAL);

AddCloud(0, v, color.gray, color.gray);
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
371 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top