下面是我的简单 EMA 策略。如何将其转换为指标? 请注意“开盘时间”和“万能出场”,即在交易所收盘前全部平仓。
//@version=5
strategy("EMAs Strategy", overlay = true, calc_on_every_tick=true,
process_orders_on_close = true)
session_time = input.session("0925-1520", "Session")
is_in_session = time(timeframe.period, session_time)
ema10Close = ta.ema(close, 10)
ema20Close = ta.ema(close, 20)
longEntryCondition = (is_in_session) and (ta.crossover(ema10Close,
ema20Close))
longCloseCondition = (is_in_session) and (ta.crossunder(ema10Close,
ema20Close))
if (longEntryCondition)
strategy.entry("Long", strategy.long)
if (longCloseCondition)
strategy.close("Long")
shortEntryCondition = (is_in_session) and (ta.crossunder(ema10Close ,
ema20Close))
shortCloseCondition = (is_in_session) and (ta.crossover(ema10Close ,
ema20Close))
if (shortEntryCondition)
strategy.entry("Short", strategy.short)
if (shortCloseCondition)
strategy.close("Short")
if not is_in_session
strategy.close_all(comment = 'Trading session ended, all positions
closed.')
plot(ema10Close, color = color.new(color.blue, 0), linewidth = 1)
plot(ema20Close, color = color.new(color.red, 0), linewidth = 1)