Heikin Ashi [Improved]

ProValueTrader · study · 57 行 · 点赞 2,024 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © ProValueTrader
 
 
//@version=5
indicator("Heikin Ashi [Improved]", overlay=true)
 
///////////////////////////////////////////////////////////////////////////////// Input
REAL = input(false, title="Use Real Close?", group="Heikin Ashi [Improved]", tooltip="Get the real closing price per bar close")
HA = input(true, title="Add Original Heikin Ashi Smoothness?", group="Heikin Ashi [Improved]", tooltip="Add an extra layer of smoothness.")
s = input.int(1, minval=1, maxval=100, title="Candle Smoothness", group="Heikin Ashi [Improved]")
 
ShowAvg = input(true, title="Show Heikin Ashi Moving Average [improved]", group="Heikin Ashi Moving Average [improved]", tooltip="Display a moving average based on the improved Heikin Ashi bars.")
len = input.int(25, minval=1, maxval=500, title="Length", group="Heikin Ashi Moving Average [improved]", tooltip="Set moving average length.")
 
///////////////////////////////////////////////////////////////////////////////// Heikin Ashi [improved]
close0 =  (open + high + low + close) / 4
close0 :=  na(close0)? nz(na) : (nz(close0) + nz(close)) / 2          
open0 = float(na)
open0 :=  na(open0[1])? nz(na) :  (nz(open0[s]) + nz(close0[1])) / 2   
high0 = math.max(high, math.max(open0,close0))  
low0 = math.min(low, math.min(open0,close0))
 
h = math.max(high0,low0)
l = math.min(high0,low0)
 
 
///////////////////////////////////////////////////////////////////////////////// Original Heikin Ashi Smoothness 
haClose = (open0 + h + l + close0) / 4
haOpen = float(na)
haOpen := na(haOpen[1]) ? (open0 + close0) / 2 : (nz(haOpen[1]) + nz(haClose[1])) / 2
haHigh = math.max(h, math.max(haOpen, haClose))
haLow = math.min(l, math.min(haOpen, haClose)) 
//plotcandle(haOpen,haHigh,haLow,close, color=haClose>haOpen?color.lime:color.red, title="Heikin Ashi [improved] + Original Heikin Ashi Smoothness")
 
///////////////////////////////////////////////////////////////////////////////// Candle Mode
o_ = HA? haOpen : open0
h_ = HA? haHigh : h
l_ = HA? haLow : l 
c_ = HA? REAL? close: haClose : REAL? close: close0
 
///////////////////////////////////////////////////////////////////////////////// Coloring 
BODY = close0>open0?color.lime:color.red
BORDER = close0>open0?color.lime:color.red
if HA 
    BODY := haClose>haOpen?color.lime:color.red
    BORDER := haClose>haOpen?color.lime:color.red
    
///////////////////////////////////////////////////////////////////////////////// Plot Candle
plotcandle(o_,h_,l_,c_, color=BODY, bordercolor=BORDER, title="Heikin Ashi [improved]")
 
 
///////////////////////////////////////////////////////////////////////////////// Heikin Ashi Moving Average [improved]
avg = math.avg(high0,low0,haHigh,haLow,c_)
HA_movingAverage = ta.wma(avg, len)
col = HA_movingAverage>HA_movingAverage[1]? color.lime:color.red
plot(ShowAvg?HA_movingAverage:na, color=col, title="Heikin Ashi Moving Average [improved]")

← 返回列表