I was wondering if somebody can help modify below code to get bar count from last fired signal,
def var = fired==1;
. I was wondering if somebody can help modify below code to get bar count from last fired signal, reset bar count when new signal is up/dn. For example in image below, arrow under bubble show uptrend, is it possible to count bar from that point on until trend reverses, once trend reverses, reset count and count again for next trend. Watchlist below give me color for the trend but wonder if bar count could be integrate for the trend direction.
okay, i'll try. below is a screenshot with the cumulative count as the last study. here's the code i've been using as well. chart is of a mutual fund JASVX, set for one month. i'm trying to get the label to show the number of bars on the screen that are either green or no change, along w/ the total number of bars. the current example should show 18 bars either up or the same, out of 22 total. Instead, it's showing 20 out of 22.
i think the problem is that, for some reason, the count is always starting at 3, which i have circled. that throws everything off. it should start at one. Got any idea how I can sort this out? thanks!
Code:declare lower; #( CUMULATIVE ) COUNT OF THE TOTAL NUMBER OF GREEN BARS (CLOSE>OPEN) # ON THE ENTIRE CHART WITHIN SPECIFIED TIMEFRAME # By XeoNoX via Usethinkscript.com input startTime = 0930; input endTime = 1600; def Active = SecondsFromTime(startTime) >= 0 and SecondsTillTime(endTime) >= 0; def var = close>=close[1]; #close>open; def cumulative = if Active and !Active[1] then var else if Active then cumulative[1] + var else cumulative[1]; plot scan = cumulative; addLabel(1, "Count = " + scan, color.dark_green); AddLabel(yes, "total bars: " + BarNumber());
edited picture to show desired count:
CLOSE >=CLOSE[1] DOES NOT MEAN ITS A BULLISH BAR OR GREEN FOR THAT MATTER. TOOK ME 20 MINTUES TO FIGURE OUT WHY THIS CODE WAS PRODUCING AND INACCURATE COUNT.......THE REST OF THE CODE DID HELP THOUGH SO THANK YOU FOR THE OTHER PORTIONbeautiful, perfect. i changed the color and added the total sum and yup thanks again.
Code:declare lower; #( CUMULATIVE ) COUNT OF THE TOTAL NUMBER OF GREEN BARS (CLOSE>OPEN) # ON THE ENTIRE CHART # By XeoNoX via Usethinkscript.com def var =close>=close[1]; def count = totalsum(var); AddLabel (yes, "COUNT " + (count), color.dark_green ); plot scan =count; AddLabel(yes, "total bars: " + BarNumber());
declare lower;
# CUMULATIVE COUNT OF THE TOTAL NUMBER OF GREEN BARS (CLOSE>OPEN)
def Active_1 = GetDay() >= (GetLastDay()-5); #The previous five days
def var_1 = !isNan(close(period=aggregationperiod.fifTEEN_MIN));
def cumulativeA = if Active_1 and !Active_1[1] then var_1 else if Active_1 then cumulativeA[1] + var_1 else cumulativeA[1];
AddLabel (yes, "COUNT " + (cumulativeA), color.dark_green );
Hi, can someone help to write code using this as first part of code. This code counts total amount of green bars on the entire chart, but i wanna know what will be average "spike" (high - open) in percent of all these counted green bars.CUMULATIVE COUNT OF THE TOTAL NUMBER OF GREEN BARS (CLOSE>OPEN) ON THE ENTIRE CHART
Code:declare lower; #( CUMULATIVE ) COUNT OF THE TOTAL NUMBER OF GREEN BARS (CLOSE>OPEN) # ON THE ENTIRE CHART # By XeoNoX via Usethinkscript.com def var =close>open; def count = totalsum(var); plot scan = count; AddLabel (yes, "COUNT " + (count) );
Hi, can someone help to write code using this as first part of code. This code counts total amount of green bars on the entire chart, but i wanna know what will be average "spike" (high - open) in percent of all these counted green bars.
declare lower;
#( CUMULATIVE ) COUNT OF THE TOTAL NUMBER OF GREEN BARS (CLOSE>OPEN)
# ON THE ENTIRE CHART
# By XeoNoX via Usethinkscript.com
def var = close>open;
def spike = high - open;
def spikeper = if var then spike / open * 100 else 0;
def spikepercount = totalsum(spikeper);
def count = totalsum(var);
def avgspikeper = spikepercount / count;
plot averagespikepercentage = avgspikeper;
AddLabel (yes, "AvgSpike " + (avgspikeper) );
def var = if var1 then var1 else
if var2 then var2 else
if var3 then var3 else
double.nan;
def varCount = TotalSum(var);
AddLabel(if varCount > 0 then yes else no,"varCount: "+varCount,color.yellow);
"def var = var1;"
if var1 ==1 then var1 else.....
@XeoNoX - Thanks for the counting info!!! I'm running into a little challenge that seems like it should exist.
The varCount result with this block of CODE comes back as "N/A".
Code:def var = if var1 then var1 else if var2 then var2 else if var3 then var3 else double.nan; def varCount = TotalSum(var); AddLabel(if varCount > 0 then yes else no,"varCount: "+varCount,color.yellow);
When i simply input one of the variables, as in,
Code:"def var = var1;"
The count comes up fine. The basics are that I'm trying to get a counter to "respond" to a market event. Since I have used this technique with labels, I thought it would be easy peezy, but, it doesn't seem that straightforward. I've tried many variants in the variable list like,
Code:if var1 ==1 then var1 else.....
to NO avail!!
Any ideas why?
THANKS!!
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Start a new thread and receive assistance from our community.
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.
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.