pine-script - 交易视图 pinescript 绘图问题
问题描述
我正在尝试将 thinkorswim 指标转换为交易视图松树脚本,但在绘制数据时卡住了,因为它在零处绘制直线。任何人都可以帮助绘制松树脚本的数据图吗
thinkor游泳代码
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);
松脚本代码
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)
解决方案
推荐阅读
- python - django.db.utils.IntegrityError:NOT NULL 约束失败:迁移后 new__post_user_post.user_id 错误
- sql - 数量变化时的折扣礼物更新
- javascript - 为什么 Swup.js 不处理相对链接?
- apache-nifi - apache Nifi:updateAttribute 处理器
- python - 如何访问第 n 个嵌套列表,我是否知道嵌套列表的深度?
- python - 在 AWS Lambda 上,Openpyxl 不跟踪图像
- javascript - 无法从捆绑的数据库中读取
- angular - 错误:multi (webpack)-dev-server/client?http://0.0.0.0:0&sockPath=/sockjs-node ./node_modules/@angular/material/prebuilt-themes/indigo-pink.css
- image - 从具有复杂图形的图像中提取几何图案
- python - 如何使用 python 在 Salesforce 中创建案例