measure the body of candles vs the wicks.

ph19golf

New member
What am I missing? Keep getting an error message. The code looks correct to me but I am missing something. Any assistance would be greatly appreciated. Trying to measure the body of candles in a given time period vs the wicks.

Ruby:
def bodymax = Max(open, close);
def bodymin = Min(open, close);
def rng = BodyHeight();

plot rng1 = rng;


input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;


plot DailyHigh = bodymax;
plot DailyLow = bodymin;
plot Mid;


if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
    DailyHigh = Double.NaN;
    DailyLow = Double.NaN;
} else {
    DailyHigh = Highest(high(period = aggregationPeriod)[-displace], length);
    DailyLow = Lowest(low(period = aggregationPeriod)[-displace], length);
}



Mid = (DailyHigh + DailyLow) / 2;

DailyHigh.SetDefaultColor(GetColor(4));
DailyHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyLow.SetDefaultColor(GetColor(4));
DailyLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Mid.SetDefaultColor(GetColor(4));
Mid.SetPaintingStrategy(PaintingStrategy.HORIZONTAL
 

Attachments

  • Code.txt
    943 bytes · Views: 161
Last edited by a moderator:
Solution
What am I missing? Keep getting an error message. The code looks correct to me but I am missing something. Any assistance would be greatly appreciated. Trying to measure the body of candles in a given time period vs the wicks.

Ruby:
def bodymax = Max(open, close);
def bodymin = Min(open, close);
def rng = BodyHeight();

plot rng1 = rng;


input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;


plot DailyHigh = bodymax;
plot DailyLow = bodymin;
plot Mid;


if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
    DailyHigh = Double.NaN;
    DailyLow = Double.NaN;
} else {
    DailyHigh = Highest(high(period = aggregationPeriod)[-displace], length)...
What am I missing? Keep getting an error message. The code looks correct to me but I am missing something. Any assistance would be greatly appreciated. Trying to measure the body of candles in a given time period vs the wicks.

Ruby:
def bodymax = Max(open, close);
def bodymin = Min(open, close);
def rng = BodyHeight();

plot rng1 = rng;


input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;


plot DailyHigh = bodymax;
plot DailyLow = bodymin;
plot Mid;


if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
    DailyHigh = Double.NaN;
    DailyLow = Double.NaN;
} else {
    DailyHigh = Highest(high(period = aggregationPeriod)[-displace], length);
    DailyLow = Lowest(low(period = aggregationPeriod)[-displace], length);
}



Mid = (DailyHigh + DailyLow) / 2;

DailyHigh.SetDefaultColor(GetColor(4));
DailyHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyLow.SetDefaultColor(GetColor(4));
DailyLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Mid.SetDefaultColor(GetColor(4));
Mid.SetPaintingStrategy(PaintingStrategy.HORIZONTAL

the last code line is missing a ) and ;
Mid.SetPaintingStrategy(PaintingStrategy.HORIZONTAL

should be this,
Mid.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);


after that is fixed, then more errors show up.
this is an annoying quirk of thinkscript, that not all the errors show up at first. this leads people to think they just have 1 error to fix, when they could have 10.


you are trying to use variables within if then's , but you assigned values to them before the if then.

these 2 lines,
plot DailyHigh = bodymax;
plot DailyLow = bodymin;

should be,
plot DailyHigh;
plot DailyLow;


now the errors are gone, but is the code right ?

close up of candles
lines are highest and lowest , from yesterday
tl7xS2Q.jpg


but there is also a line near 0
that is exists because of this
plot rng1 = rng;
tRQOzqH.jpg


don't need that, so disable that line with a #
# plot rng1 = rng;

when i am debugging, i tend to disable code lines, instead of deleting them. that way i can copy it , change it a little, then see a progression of what i tried. when it is all working, then go clean it up.


----------------------

i am not sure what you want to see?
your words don't match the code.
you say wicks and body, but the code is only plotting wicks (high and low)

so it looks like the default values plot lines at the previous 1 day highest and lowest levels, and a mid line.
is that what you want ?
what do you want to see on the chart? (if you can answer this, it is easier to find the answer)


will you ever want the highest number from several days?
if not then you don't need highest( , length)

you could replace that if then with this,

input aggregationPeriod = AggregationPeriod.DAY;
input offset = 1;
plot zhigh = high(period = aggregationPeriod)[offset];
plot zlow = low(period = aggregationPeriod)[offset];


the -displace within that highest() is a little confusing. why have a negative value, and a negative on the variable?
input displace = -1;
2 negatives make a postive, so just leave it off both.


i don't know what this means, so i'm going to stop.
Trying to measure the body of candles in a given time period vs the wicks.

could create a ratio % of body to wicks with this,
def x = 100*bodyheight()/(high-low);

would need to add agg to all values if desired.
 
Solution

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
379 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