You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PineScript EMA指标自定义颜色输入不生效及默认色设置咨询

错误点排查

  • 执行顺序错误:颜色输入变量col_ema01、col_ema02定义在plot函数之后,Pine Script按自上而下顺序执行,调用plot时颜色变量还未声明,无法生效。
  • plot缺少颜色参数:你没有将自定义颜色变量传入plot的color参数,系统会默认使用蓝色渲染线条。
  • 语法笔误:plot函数中的空值占位符错写为an,Pine Script的空值关键字是na。
  • 参数冲突:颜色输入项同时声明了两个group参数(group="Color Settings"和group=emacross),冲突会导致分组配置失效。
  • 绘图默认关闭:plot_fastEma和plot_slowEma的默认值设为false,指标初次加载时默认不会显示EMA线条。

自定义默认颜色方法

直接在颜色输入项的第一个参数位置填写你需要的默认色值即可,比如快速EMA设为橙色#FFA500、慢速EMA设为红色#FF0000,初次打开指标时就会默认使用指定颜色。

修正后完整代码

//@version=5
indicator("EMA Cross 自定义", overlay=true)

var emacross = "EMA Cross"
// EMA 基础参数输入
ema_01_len = input(20, title='Fast EMA', step=1, type=input.integer, group = emacross)      
ema_02_len = input(50, title='Slow EMA', step=1, type=input.integer, group = emacross)
ema_src = input(title="Source", type=input.source, defval=close, group = emacross)

plot_fastEma = input(title="Plot Fast Ema", type=input.bool, defval=true,group=emacross)
plot_slowEma = input(title="Plot Slow Ema", type=input.bool, defval=true,group=emacross)

// 颜色参数输入(提前到plot之前,自定义默认色值)
col_ema01 = input(color.new(#FFA500, 0), "Fast EMA 颜色", group="Color Settings", inline="EMA FAST")
col_ema02 = input(color.new(#FF0000, 0), "Slow EMA 颜色", group="Color Settings", inline="EMA SLOW")

// EMA 计算
ema_01 = ta.ema(ema_src, ema_01_len)
ema_02 = ta.ema(ema_src, ema_02_len)

// 绘图,传入颜色参数
plot(plot_fastEma ? ema_01 : na, color=col_ema01, title="Fast EMA")
plot(plot_slowEma ? ema_02 : na, color=col_ema02, title="Slow EMA")

内容的提问来源于stack exchange,提问作者Trader_M

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 03:27:03