Formulate new candlesticks

shakib3585

Active member
VIP
Hello All,

I am trying to make a candlestick chart based on the code provided. It should follow the same strategy of "red" and "green" colors for bullish and bearish candles, respectively.
I intend to use the formulated candlestick in any time frame. Once formulated, I only want to see the formulated candlesticks and not the regular candlesticks. Please help.

Thanks
Code:
def op = (0.5*(open[1]+open[2]));
def cl = (0.5*(close[1]+close[2]));
def hi = (0.5*(high[1]+high[2]));
def lo = (0.5*(low[1]+low[2]));
 
Hello All,

I am trying to make a candlestick chart based on the code provided. It should follow the same strategy of "red" and "green" colors for bullish and bearish candles, respectively.
I intend to use the formulated candlestick in any time frame. Once formulated, I only want to see the formulated candlesticks and not the regular candlesticks. Please help.

Thanks
Code:
def op = (0.5*(open[1]+open[2]));
def cl = (0.5*(close[1]+close[2]));
def hi = (0.5*(high[1]+high[2]));
def lo = (0.5*(low[1]+low[2]));

Try this

Code:
input hide_price_plot = yes;
HidePricePlot(hide_price_plot);

def op = (0.5 * (open[1] + open[2]));
def cl = (0.5 * (close[1] + close[2]));
def hi = (0.5 * (high[1] + high[2]));
def lo = (0.5 * (low[1] + low[2]));

input charttype = ChartType.CANDLE;

def o1 = if op < cl
         then op
         else Double.NaN;
def c1 = if op < cl
         then cl
         else Double.NaN;
def h1 = if op < cl
         then hi
         else Double.NaN;
def l1 = if op < cl
         then lo
         else Double.NaN;

AddChart(growColor = Color.GREEN, fallColor = Color.RED, neutralColor = Color.GRAY, high = h1, low = l1, open = c1, close = o1, type = charttype);

def o2 = if op > cl
         then op
         else Double.NaN;
def h2 = hi;
def l2 = lo;
def c2 = if op > cl
         then cl
         else Double.NaN;
AddChart(growColor = Color.RED, fallColor = Color.GREEN, neutralColor = Color.GRAY, high = h2, low = l2, open = o2, close = c2, type = charttype);

def o3 = if op == cl
         then op
         else Double.NaN;
def h3 = hi;
def l3 = lo;
def c3 = if op == cl
         then cl
         else Double.NaN;
AddChart(growColor = Color.YELLOW, fallColor = Color.GREEN, neutralColor = Color.GRAY, high = h3, low = l3, open = o3, close = c3, type = charttype);
 

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

Thank you @SleepyZ . I have plotted the code and looks like the following
View attachment 19415

In the chart, there are some prices that looks like four price candlesticks ( high = low =open = close). Is there a possible way to make it into a solid candlsestick like Heiken-Ashi

Please the the chart in the following. I have red circled some areas where there are no sloid candlesticks, only dashes
shared chart link: http://tos.mx/Z9fcutA

1691372367414.png
 
Last edited by a moderator:
Thank you @SleepyZ . I have plotted the code and looks like the following
View attachment 19415

In the chart, there are some prices that looks like four price candlesticks ( high = low =open = close). Is there a possible way to make it into a solid candlsestick like Heiken-Ashi

Please the the chart in the following. I have red circled some areas where there are no sloid candlesticks, only dashes
shared chart link: http://tos.mx/Z9fcutA

This uses heikin ashi logic for the candles you circled. The color of those candles is determined by comparing the hahigh to the prior candle's hahigh

Screenshot 2023-08-07 102052.png
Code:
#Formulate_new_candlesticks

input hide_price_plot = yes;
HidePricePlot(hide_price_plot);

def op = (0.5 * (open[1] + open[2]));
def cl = (0.5 * (close[1] + close[2]));
def hi = (0.5 * (high[1] + high[2]));
def lo = (0.5 * (low[1] + low[2]));

def  HAclose = (op + hi + lo + cl) / 4;
def  HAopen  = (CompoundValue(1, (HAopen[1] + HAclose[1]) / 2, (op[1] + cl[1]) / 2));
def  haopen_ = (HAopen + 0) ;
def  HAhigh  = (Max(Max(hi, haopen_), HAclose));
def  HAlow   = (Min(Min(lo, haopen_), HAclose));

input charttype = ChartType.CANDLE;

def o1 = if op < cl
         then op
         else Double.NaN;
def c1 = if op < cl
         then cl
         else Double.NaN;
def h1 = if op < cl
         then hi
         else Double.NaN;
def l1 = if op < cl
         then lo
         else Double.NaN;

AddChart(growColor = Color.GREEN, fallColor = Color.RED, neutralColor = Color.GRAY, high = h1, low = l1, open = c1, close = o1, type = charttype);

def o2 = if op > cl
         then op
         else Double.NaN;
def h2 = if op > cl
         then hi
         else Double.NaN;
def l2 = if op > cl
         then lo
         else Double.NaN;
def c2 = if op > cl
         then cl
         else Double.NaN;
AddChart(growColor = Color.RED, fallColor = Color.GREEN, neutralColor = Color.GRAY, high = h2, low = l2, open = o2, close = c2, type = charttype);

def o3 = if op == cl and HAhigh < HAhigh[1]
         then HAhigh
         else Double.NaN;
def h3 = if op == cl and HAhigh < HAhigh[1]
         then HAhigh
         else Double.NaN;
def l3 = if op == cl and HAhigh < HAhigh[1]
         then HAlow
         else Double.NaN;
def c3 = if op == cl and HAhigh < HAhigh[1]
         then HAlow
         else Double.NaN;
AddChart(growColor = Color.RED, fallColor = Color.GREEN, neutralColor = Color.GRAY, high = h3, low = l3, open = o3, close = c3, type = charttype);


def o4 = if op == cl and HAhigh >= HAhigh[1]
         then HAhigh
         else Double.NaN;
def h4 = if op == cl and HAhigh >= HAhigh[1]
         then HAhigh
         else Double.NaN;
def l4 = if op == cl and HAhigh >= HAhigh[1]
         then HAlow
         else Double.NaN;
def c4 = if op == cl and HAhigh >= HAhigh[1]
         then HAlow
         else Double.NaN;
AddChart(growColor = Color.GREEN, fallColor = Color.GREEN, neutralColor = Color.GRAY, high = h4, low = l4, open = o4, close = c4, type = charttype);
 
Thank you @SleepyZ . I have plotted the code and looks like the following
View attachment 19415

In the chart, there are some prices that looks like four price candlesticks ( high = low =open = close). Is there a possible way to make it into a solid candlsestick like Heiken-Ashi

Please the the chart in the following. I have red circled some areas where there are no sloid candlesticks, only dashes
shared chart link: http://tos.mx/Z9fcutA

View attachment 19416
Think about it. You are asking to plot as a candle: the delta of the candle from 2 bars ago compared to the previous candle. The dashes are where there is no appreciable difference so nothing to build a candle on.
It is an awesome way to visually display exhaustion.
Love it!
 
Last edited:
This uses heikin ashi logic for the candles you circled. The color of those candles is determined by comparing the hahigh to the prior candle's hahigh
Hi SleepyZ, can you please write the codes for drawing a straight line between the highestall(high) and lowestall(low) with any length. basically I want to draw a straight line between two points. I did as follow but it did not draw a line.

plot HL = if !isnan(highestall(high)) then highestall(high) else lowestall(low);
HL.enableApproximation();
HL.setlineWeight(5);
HL.setdefaultColor(color.white);
 
Last edited:
Hi SleepyZ, can you please write the codes for drawing a straight line between the highestall(high) and lowestall(low) with any length. basically I want to draw a straight line between two points. I did as follow but it did not draw a line.

plot HL = if !isnan(highestall(high)) then highestall(high) else lowestall(low);
HL.enableApproximation();
HL.setlineWeight(5);
HL.setdefaultColor(color.white);

Try this. This finds the bar location and then the price to use.

Screenshot 2023-08-28 084003.png
Code:
def hh  = if high == highestall(high) then 1 else double.nan;
def ll  = if low == lowestall(low) then 1 else double.nan;
plot HL = if !isnan(hh) then high else if !isnan(ll) then low else double.nan;
HL.enableApproximation();
HL.setlineWeight(5);
HL.setdefaultColor(color.white);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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