#// This source code is subject to the terms of the Mozilla Public License 2.0 at
https://mozilla.org/MPL/2.0/
#// © the_MarketWhisperer
#// Version 1.0
#// (Based on a code that I found somewhere in the TV world)
#// A simple indicator that paints candles with different shades of colors based on the volume transacted.
#// Supports 6 levels of sensitivity at present.
#// Darkest indicates the most volume transacted. Lightest, the least.
#// Use it for your Volume Spread Analysis and/or in conjunction with any other strategies that you employ.
#// Relative volume is calculated based on EMA (set to 20 period by default)
#//@version=4
#study(title="Candle Color by Volume", shorttitle="VolumeColoredCandles", overlay=true)
# CONVERTED BY SAM4COK Request from
https://usethinkscript.com/
input emaPeriod = 20; # Volume EMA Period
input PaintBar = yes;
def volumeRatio = volume / ExpAverage(volume, emaPeriod);
def isUp = close > open ;
#//Green and red color repository. 6 is darkest. 1 is lightest.
DefineGlobalColor("g_01" , CreateColor(223,245,223));
DefineGlobalColor("g_02" , CreateColor(200,230,201));
DefineGlobalColor("g_03" , CreateColor( 3,247, 3));
DefineGlobalColor("g_04" , CreateColor( 68,198, 73));
DefineGlobalColor("g_05" , CreateColor( 12,168, 12));
DefineGlobalColor("g_06" , CreateColor( 0,103, 0));
DefineGlobalColor("r_01" , CreateColor(244,229,229));
DefineGlobalColor("r_02" , CreateColor(249,205,205));
DefineGlobalColor("r_03" , CreateColor(247,155,155));
DefineGlobalColor("r_04" , CreateColor(230, 97, 97));
DefineGlobalColor("r_05" , CreateColor(243, 0, 0));
DefineGlobalColor("r_06" , CreateColor(159, 0, 0));
#//=================================================================================================================#============
AssignPriceColor(if PaintBar then if volume and isUp then if volumeRatio > 2 then GlobalColor("g_06") else
if volumeRatio > 1.5 then GlobalColor("g_05") else
if volumeRatio > 1.2 then GlobalColor("g_04") else
if volumeRatio > 0.8 then GlobalColor("g_03") else
if volumeRatio > 0.4 then GlobalColor("g_02") else GlobalColor("g_01")
else if volume then if volumeRatio > 2 then GlobalColor("r_06") else
if volumeRatio > 1.5 then GlobalColor("r_05") else
if volumeRatio > 1.2 then GlobalColor("r_04") else
if volumeRatio > 0.8 then GlobalColor("r_03") else
if volumeRatio > 0.4 then GlobalColor("r_02") else GlobalColor("r_01")
else color.current else color.current);
###### END ####