Hey @Svanoy thank you for following up with me & thank you @halcyonguy for chiming in to help out.
I am only a few weeks in on learning thinkscript so excuse me on the confusion I may have caused. I truly appreciate the help & guidance.
as for the script I believe i got it to work with fold. It now seems to sum the correct amount when I change the period input & time frame aggregation input. I attached what i have completed any input on if of if not correct would be appreciated.
Ruby:#Short Term Candle Body Sentiment input ShortTermSentiment = aggregationPeriod.fivE_MIN; input ShortTermSumPeriods = 6; def ST_O = open(period = ShortTermSentiment); def ST_C = close(period = ShortTermSentiment); def ST_bodyHeight =...
input agg = aggregationPeriod.fIFTEEN_MIN;
input Count = 2;
def green_Candle_NAME = Green;
def o = open(period = agg);
def c = close(period = agg);
def bodyHeight = (AbsValue(o-c));
def sumBH = fold i = 1 to count with green_Candle_NAME_Counter = 0 do if GetValue(green_Candle_NAME,i)==1 then green_Candle_NAME_Counter+GetValue(BodyHeight,i) else green_Candle_NAME_Counter ;
addlabel(1, " Sum Body Height " + SumBH + "|Periods = " + count , color.white);
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
def sumBH = fold i = 1 to count with green_Candle_NAME_Counter = 0 do if GetValue(green_Candle_NAME,i)==1 then green_Candle_NAME_Counter+GetValue(BodyHeight,i) else green_Candle_NAME_Counter ;
def sumBH = fold i = 1 to count with green_Candle_NAME_Counter = 0 do if GetValue(green_Candle_NAME,i)==1 then green_Candle_NAME_Counter+GetValue(BodyHeight,i) else sumBH[1] ;
input BubbleCandleCount = 6;
def CandleBodyTop = MidBodyVal() + 0.5 * BodyHeight();
def cond = BodyHeight() is greater than 0 ;
def hcount = CompoundValue(1, if cond then hcount[1] + 1 else hcount[1], 0);
AddChartBubble(cond and HighestAll(hcount) - hcount <= BubbleCandleCount- 1 , CandleBodyTop,
+ BodyHeight()
, Color.CYAN);
def RED = close < open;
def Green = close > open;
input agg = aggregationPeriod.fivE_MIN;
input GreenRedCandleCount = 6;
def o = open(period = agg);
def c = close(period = agg);
def bodyHeight = (AbsValue(o-c));
def RED_BODY_Count = fold i = 1 to GreenRedCandleCount with Red_Counter = 0 do if GetValue(Red,i)==1 then Red_Counter+GetValue(BodyHeight,i) else Red_Counter ;
def GREEN_BODY_Count = fold h = 1 to GreenRedCandleCount with Green_Counter = 0 do if GetValue(Green,h)==1 then Green_Counter+GetValue(BodyHeight,h) else Green_Counter ;
addlabel(1, " Sum Body Height " + RED_BODY_Count+ "|Periods = " + GreenRedCandleCount , color.red);
addlabel(1, " Sum Body Height " + GREEN_BODY_Count+ "|Periods = " + GreenRedCandleCount , color.grEEN);
#Short Term Candle Body Sentiment
input ShortTermSentiment = aggregationPeriod.fivE_MIN;
input ShortTermSumPeriods = 6;
def ST_O = open(period = ShortTermSentiment);
def ST_C = close(period = ShortTermSentiment);
def ST_bodyHeight = (AbsValue(ST_O-ST_C));
def ST_sumGreen= fold i = 0 to ShortTermSumPeriods with s do s + if(getValue(ST_C > ST_C[1], i), getValue(ST_bodyHeight, i), 0);
def ST_sumRed= fold h = 0 to ShortTermSumPeriods with g do g + if(getValue(ST_C < ST_C[1], h), getValue(ST_bodyHeight, h), 0);
#ST LABELS
AddLabel(yes, "|Sum Green Body" + (ST_sumGreen));
AddLabel(yes, "|Sum Red Body" + (ST_sumRed));
Hey @Svanoy thank you for following up with me & thank you @halcyonguy for chiming in to help out.
I am only a few weeks in on learning thinkscript so excuse me on the confusion I may have caused. I truly appreciate the help & guidance.
as for the script I believe i got it to work with fold. It now seems to sum the correct amount when I change the period input & time frame aggregation input. I attached what i have completed any input on if of if not correct would be appreciated.
Ruby:#Short Term Candle Body Sentiment input ShortTermSentiment = aggregationPeriod.fivE_MIN; input ShortTermSumPeriods = 6; def ST_O = open(period = ShortTermSentiment); def ST_C = close(period = ShortTermSentiment); def ST_bodyHeight = (AbsValue(ST_O-ST_C)); def ST_sumGreen= fold i = 0 to ShortTermSumPeriods with s do s + if(getValue(ST_C > ST_C[1], i), getValue(ST_bodyHeight, i), 0); def ST_sumRed= fold h = 0 to ShortTermSumPeriods with g do g + if(getValue(ST_C < ST_C[1], h), getValue(ST_bodyHeight, h), 0); #ST LABELS AddLabel(yes, "|Sum Green Body" + (ST_sumGreen)); AddLabel(yes, "|Sum Red Body" + (ST_sumRed));
def g2 = if ST_C > ST_C[1] then ST_bodyHeight else 0;
def Green2 = sum( g2, ShortTermSumPeriods );
def r2 = if ST_C < ST_C[1] then ST_bodyHeight else 0;
def red2 = sum( r2, ShortTermSumPeriods );
AddLabel(yes, "Sum green2 Body " + green2, color.magenta);
AddLabel(yes, "Sum red2 Body " + red2, color.magenta);
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
C | Creating script for candle height body height | Questions | 9 | |
O | Price Range PER Candle (Body Only) | Questions | 1 | |
M | Don't count a candle if it has a line for a body (doji). | Questions | 1 | |
J | Intraday Candle Body Gaps | Questions | 3 | |
Inside Candle Up or Down using BODY of Mother candle NOT wick. | Questions | 3 |
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.