如何使以下代码正常工作?
// @ version = 3
strategy("My Strategy", overlay=true)
longCondition = crossover(ema(close, 13), vwap) and crossover(ADX, DIMinus) and crossover(MACD, MACDSignal)
if (longCondition)
strategy.entry("My Long Entry Id", strategy.long)
shortCondition = crossunder(ema(close, 13), vwap) and crossover(ADX, DIPLUS) and crossover(MACDSignal, MACD)
if (shortCondition)
strategy.entry("My Short Entry Id", strategy.short)
答案 0 :(得分:0)
我不知道这些变量中有多少,但是下面的代码是我基于所提供变量名称的建议。它们类似于“方向运动指示器”和“ macd指示器”值的输出。使用此代码作为示例来构建自己的代码。
//@version=3
strategy("My Strategy", overlay=true)
len = input(14, minval=1, title="DI Length")
lensig = input(14, title="ADX Smoothing", minval=1, maxval=50)
up = change(high)
down = -change(low)
DIPLUS = na(up) ? na : (up > down and up > 0 ? up : 0)
DIMinus = na(down) ? na : (down > up and down > 0 ? down : 0)
trur = rma(tr, len)
plus = fixnan(100 * rma(DIPLUS, len) / trur)
minus = fixnan(100 * rma(DIMinus, len) / trur)
sum = plus + minus
ADX = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), lensig)
[MACD, MACDSignal, histLine] = macd(close, 12, 26, 9)
longCondition = crossover(ema(close, 13), vwap) and crossover(ADX, DIMinus) and crossover(MACD, MACDSignal)
if (longCondition)
strategy.entry("My Long Entry Id", strategy.long)
shortCondition = crossunder(ema(close, 13), vwap) and crossover(ADX, DIPLUS) and crossover(MACDSignal, MACD)
if (shortCondition)
strategy.entry("My Short Entry Id", strategy.short)