Convert volume based color bars to ToS?

D

dstock

New member
convert tradingview to Tos

Code:
//@version=3
//author KIVANC @fr3762 on twitter
//indicates the price bars whether it's supported by volume or not

study("Volume Based Coloured Bars", title="VCB", overlay=true)
length=input(21, "length", minval=1)
avrg=sma(volume,length)

vold1 = volume > avrg*1.5 and close<open
vold2 = volume >= avrg*0.5 and volume<=avrg*1.5 and close<open
vold3 = volume < avrg *0.5 and close<open

volu1 = volume > avrg*1.5 and close>open
volu2 = volume >= avrg*0.5 and volume<=avrg*1.5 and close>open
volu3 = volume< avrg*0.5 and close>open


cold1=#800000
cold2=#FF0000
cold3=orange


colu1=#006400
colu2=lime
colu3=#7FFFD4


color = vold1 ? cold1 : vold2 ? cold2 : vold3 ? cold3 : volu1 ? colu1 : volu2 ? colu2 : volu3 ? colu3 : na

barcolor(color)
 
T

tomsk

Well-known member
VIP
Warehouse
@dstock Here's your code converted to TOS.

Code:
# Volume Based Coloured Bars
# tomsk
# 11.16.2019

# Converted to ThinkScript
#
# //@version=3
# //author KIVANC @fr3762 on twitter
# //indicates the price bars whether it's supported by volume or not
#
# https://tr.tradingview.com/script/8RPiMMmn-Volume-Based-Coloured-Bars/

input length = 21;

def avrg = Average(volume, length);

def vold1 = volume > avrg * 1.5 and close < open;
def vold2 = between(volume, avrg * 0.5, avrg * 1.5) and close < open;
def vold3 = volume < avrg * 0.5 and close < open;

def volu1 = volume > avrg * 1.5 and close > open;
def volu2 = between(volume, avrg * 0.5, avrg*1.5) and close > open;
def volu3 = volume < avrg * 0.5 and close > open;

AssignPriceColor(if vold1 then Color.DARK_RED
                 else if vold2 then Color.RED
                 else if vold3 then Color.ORANGE
                 else if volu1 then Color.DARK_GREEN
                 else if volu2 then Color.GREEN
                 else Color.LIGHT_GREEN);
# End Code
Please note that color codes were obtained from the following web link

 

Top