交易视图 pinescript 绘图问题

时间:2021-03-23 05:11:35

标签: pine-script

我正在尝试将 thinkorswim 指标转换为交易视图松树脚本,但在绘制数据时卡住了,因为它在零处绘制直线。任何人都可以帮助绘制松树脚本的数据图

thinkorSwim 代码

input price = close;
input length = 10;

def tmp1 = if price > price[1] then price - price[1] else 0;
def tmp2 = if price[1] > price then price[1] - price else 0;
def d2 = sum(tmp1, length);
def d4 = sum(tmp2, length);
def cond = d2 + d4 == 0;
def ad3 = if cond then 0 else (d2 - d4) / (d2 + d4) * 100;
def coeff = 2 / (length + 1) * AbsValue(ad3) / 100;
def asd = compoundValue("visible data" = coeff * price + (if IsNaN(asd[1]) then 0 else asd[1]) * (1 - coeff), "historical data" = price);

plot VMA = asd;
VMA.setDefaultColor(GetColor(0));
def vwma8 = sum(volume * close, 8) / sum(volume, 8);
def vwma21 = sum(volume * close, 21) / sum(volume, 21);
def vwma34 = sum(volume * close, 34) / sum(volume, 34);

def bullish = if vwma8 > vwma21 and vwma21 > vwma34 then 1 else 0;
def bearish = if vwma8 < vwma21 and vwma21 < vwma34 then 1 else 0;
def distribution = if !bullish and !bearish then 1 else 0;

VMA.AssignValueColor(if bearish and close<= VMA then color.red else if bullish and close >= VMA then color.green else color.gray);

Pine 脚本代码

study("marketPulse", overlay = true, shorttitle="marketPulse",precision=1)

asd1 = float(0)
price = close 
length = 10
 
tmp1 = max(0, change(price))
tmp2 = min(0, change(price))
 
d2 = sum(tmp1, length)
d4 = sum(tmp2, length)
 
cond = d2+d4 ? false : true
ad3 = cond ? 0 : 100*(d2-d4)/(d2+d4)
coeff = 2/(length+1)*abs(ad3)/100
asd2 = price
asd = coeff*price + (asd1) *(1-coeff)
asd2 := asd[1]     
 
VMA = asd

vwma8  = sum(VMA * close,  8) / sum(VMA,  8)
vwma21 = sum(VMA * close, 21) / sum(VMA, 21)
vwma34 = sum(VMA * close, 34) / sum(VMA, 34)
 
bullish = vwma8 > vwma21 and vwma21 > vwma34 
bearish = vwma8 < vwma21 and vwma21 < vwma34 

vmacolor = bullish ? color.green : bearish ? color.red : close >= VMA ? color.yellow : color.orange

plot(series=VMA, color = vmacolor, linewidth =2, transp = 50)

0 个答案:

没有答案