Convert a study into a histogram

shakib3585

Active member
VIP
Greetings all,

I would like to request that a study that I found useful be converted into a histogram. The study that I intend to convert into a histogram is as follows,

Code:
def cl = close(period=aggregationPeriod.THirty_MIN);

def op = open(period=aggregationPeriod.THirty_MIN);

def hi = high(period=aggregationPeriod.THirty_MIN);

def lo = high(period=aggregationPeriod.THirty_MIN);



def EM35 = MovAvgExponential(cl,35);



def haC = (op + hi + lo + cl)/4 ;

def haO = (haO[1] +haC[1])/2 ;

def haL = min(min(lo,haO),haC);

def haH = max(max(hi,haO),haC);



def Per_1 = (((hac[3] - haC)/haC)*100);

def Per_2 = (((EM35[3] - EM35)/EM35)*100);

def Histogram value = Per_1 + Per_2 ;

The color of the histogram should be in a similar pattern to that of a MACD. If the Histogram value is negative, the color should be red; otherwise, the color should be green. It should also be able to track histogram bars where the value has increased/decreased from its previous histogram bar (by changing the histogram bar colors just like MACD). I found it useful for tracing reversals. Any help is much appreciated.

Thank you,

Sha
 
Solution
@shakib3585 I'm going to assume that you will be plotting the histogram based on your last condition (Per_1 + Per_2) since you didn't post the completed code.

Try this:

Code:
declare lower;

def cl = close(period=aggregationPeriod.THirty_MIN);

def op = open(period=aggregationPeriod.THirty_MIN);

def hi = high(period=aggregationPeriod.THirty_MIN);

def lo = high(period=aggregationPeriod.THirty_MIN);

def EM35 = MovAvgExponential(cl,35);

def haC = (op + hi + lo + cl)/4 ;

def haO = (haO[1] +haC[1])/2 ;

def haL = min(min(lo,haO),haC);

def haH = max(max(hi,haO),haC);

def Per_1 = (((hac[3] - haC)/haC)*100);

def Per_2 = (((EM35[3] - EM35)/EM35)*100);

plot data = Per_1 + Per_2 ...
Can you post the entire study?

The histogram style is really easy to implement.

Declare the indicator as a lower study and then use SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
 

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

@shakib3585 I'm going to assume that you will be plotting the histogram based on your last condition (Per_1 + Per_2) since you didn't post the completed code.

Try this:

Code:
declare lower;

def cl = close(period=aggregationPeriod.THirty_MIN);

def op = open(period=aggregationPeriod.THirty_MIN);

def hi = high(period=aggregationPeriod.THirty_MIN);

def lo = high(period=aggregationPeriod.THirty_MIN);

def EM35 = MovAvgExponential(cl,35);

def haC = (op + hi + lo + cl)/4 ;

def haO = (haO[1] +haC[1])/2 ;

def haL = min(min(lo,haO),haC);

def haH = max(max(hi,haO),haC);

def Per_1 = (((hac[3] - haC)/haC)*100);

def Per_2 = (((EM35[3] - EM35)/EM35)*100);

plot data = Per_1 + Per_2 ;
data.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

vD9vBgL.png
 
Solution
@shakib3585 I'm going to assume that you will be plotting the histogram based on your last condition (Per_1 + Per_2) since you didn't post the completed code.

Try this:

Code:
declare lower;

def cl = close(period=aggregationPeriod.THirty_MIN);

def op = open(period=aggregationPeriod.THirty_MIN);

def hi = high(period=aggregationPeriod.THirty_MIN);

def lo = high(period=aggregationPeriod.THirty_MIN);

def EM35 = MovAvgExponential(cl,35);

def haC = (op + hi + lo + cl)/4 ;

def haO = (haO[1] +haC[1])/2 ;

def haL = min(min(lo,haO),haC);

def haH = max(max(hi,haO),haC);

def Per_1 = (((hac[3] - haC)/haC)*100);

def Per_2 = (((EM35[3] - EM35)/EM35)*100);

plot data = Per_1 + Per_2 ;
data.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

vD9vBgL.png
Thanks a lot @BenTen . Can you please modify the code to change the color to red ( if negative ) and green (if positive). The green and red colors should also turn into dark green or dark red when the value starts to decrease/increase from previous
 
Sure. Add this to the bottom of your script:

Code:
data.DefineColor("Positive and Up", Color.GREEN);
data.DefineColor("Positive and Down", Color.DARK_GREEN);
data.DefineColor("Negative and Down", Color.RED);
data.DefineColor("Negative and Up", Color.DARK_RED);
data.AssignValueColor(if data >= 0 then if data > data[1] then data.color("Positive and Up") else data.color("Positive and Down") else if data < data[1] then data.color("Negative and Down") else data.color("Negative and Up"));
 
Sure. Add this to the bottom of your script:

Code:
data.DefineColor("Positive and Up", Color.GREEN);
data.DefineColor("Positive and Down", Color.DARK_GREEN);
data.DefineColor("Negative and Down", Color.RED);
data.DefineColor("Negative and Up", Color.DARK_RED);
data.AssignValueColor(if data >= 0 then if data > data[1] then data.color("Positive and Up") else data.color("Positive and Down") else if data < data[1] then data.color("Negative and Down") else data.color("Negative and Up"));
Thanks a ton @BenTen
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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