TradingView
LonesomeTheBlue
Oct 25, 2021 3:18 PM

DrawIndicatorOnTheChart 

Bitcoin / TetherUSBinance

描述

Library "DrawIndicatorOnTheChart"
this library is used to show an indicator (such RSI, CCI, MOM etc) on the main chart with indicator's horizontal lines in a window. Location of the window is calculated dynamically by last price movemements

drawIndicator(indicatorName, indicator, indicatorcolor, period, indimax_, indimin_, levels, precision, xlocation) draws the related indicator on the chart
  Parameters:
    indicatorName: is the indicator name as string such "RSI", "CCI" etc
    indicator: is the indicator you want to show, such rsi(close, 14), mom(close, 10) etc
    indicatorcolor: is the color of indicator line
    period: is the length of the window to show
    indimax_: is the maximum value of the indicator, for example for RSI it's 100.0, if the indicator (such CCI, MOM etc) doesn't have maximum value then use "na"
    indimin_: is the minimum value of the indicator, for example for RSI it's 0.0, if the indicator (such CCI, MOM etc)doesn't have maximum value then use "na"
    levels: is the levels of the array for the horizontal lines. for example if you want horizontal lines at 30.0, and 70.0 then use array.from(30.0, 70.0). if no horizontal lines then use array.from(na)
    precision: is the precision/number of decimals that is used to show indicator values, for example for RSI set it 2
    xlocation: is end location of the indicator window, for example if xlocation = 0 window is created on the index of the last bar/candle
  Returns: none

版本注释

v2
background color of the window changed as black

版本注释

v3

版本注释

v4

版本注释

v5:
- updated to show multiple indicator lines for the indicators such DMI
- so indicator parameter changed to indicator1, indicator2, indicator3 (if indicator2 or indicator3 doesn't exist then send na value)
- added line width parameter
- color parameter changed to the array

Updated:
drawIndicator(enabled, indicatorName, indicator1, indicator2, indicator3, indicatorcolor, period, indimax_, indimin_, levels, precision, xlocation, lnwidth) draws the related indicator on the chart
  Parameters:
    enabled: if it's enabled to show
    indicatorName: is the indicator name as string such "RSI", "CCI" etc
    indicator1: is first indicator you want to show, such rsi(close, 14), mom(close, 10) etc
    indicator2: is second indicator you want to show, such -DI of DMI
    indicator3: is third indicator you want to show, such ADX of DMI
    indicatorcolor: is the color of indicator line
    period: is the length of the window to show
    indimax_: is the maximum value of the indicator, for example for RSI it's 100.0, if the indicator (such CCI, MOM etc) doesn't have maximum value then use "na"
    indimin_: is the minimum value of the indicator, for example for RSI it's 0.0, if the indicator (such CCI, MOM etc)doesn't have maximum value then use "na"
    levels: is the levels of the array for the horizontal lines. for example if you want horizontal lines at 30.0, and 70.0 then use array.from(30.0, 70.0). if no horizontal lines then use array.from(na)
    precision: is the precision/nuber of decimals that is used to show indicator values, for example for RSI set it 2
    xlocation: is end location of the indicator window, for example if xlocation = 0 window is created on the index of the last bar/candle
    lnwidth: is the line width of the indicator lines
  Returns: none

版本注释

v6

Somehow indicator doesn't show the lines. fixed. Thank to @TanHef for the solution
评论
hudavertokgoz
Hello, I wrote many times but I guess you didn't see it. I want permission to use harmonic pattern pro. I can't send private messages. I don't have reputation points. Please I want permission to use harmonic pattern pro. Username: hudavertokgoz
Disciple_Of_Shiva
Magic man at his best again! Killer idea.. many thanks LTB! God bless you always! :)
LonesomeTheBlue
@Disciple_Of_Shiva, you are welcome!
rbower
What's up with the max_bars_back error?
import LonesomeTheBlue/DrawIndicatorOnTheChart/5 as di indicator("My Script", overlay=true) di.drawIndicator(enabled=true, indicatorName='test', indicator1=ta.rsi(close,3), indicator2=na, indicator3=na, indicatorcolors=array.from(color.green), period = 21, indimax_ = 100, indimin_ = 0, levels = array.from(20.0, 80.0), precision = 1, xlocation = 0, lnwidth = 2)

This should be pretty simple, no?
LonesomeTheBlue
@rbower, => indicator("My Script", overlay = true, max_bars_back = 100)
kakola
(if indicator2 or indicator3 doesn't exist then send na value)

TV supports default-parameter values (i.e. optional arguments), so just set to them to na by default, e.g.
float indicator1, float indicator2=na, float indicator3=na,
rbower
Note that in the later version, indicatorcolor parameter (as stated in the documentation) is now indicatorcolors, and it takes an array instead.
omeradilokur
Gute arbeit🤌🤌🤌
Ghost3ader
thanks!
serkany88
Also i would suggest a functionality parameter like conditional drawing, draw the indi on chart Only if given condition in parameter is true otherwise do not draw. Currently it is not possible because enabled parameter seems to be static and non adaptable to stop drawing if condition is not true in x axis so the box always fixes it's own position to last bar index. Ofc this has a possibility of hitting box drawing limitations but it's just a theory i haven't tried to code it myself yet.
更多