Pine 脚本策略在交叉点而不是在收盘时打开交易
Pine script strategy open trade as at crossover not at bar close
我试图在当前价格 EMA200 的交叉点而不是收盘价处建仓。我不在乎价格是否回落。有什么办法可以实现吗?
strategy('EMA200 5 min', overlay=true, process_orders_on_close=true)
ema_200 = ta.ema(close, 200)
// For LONG check if previous bar crossed over EMA200 and set order when current bar crosses EMA200
cross_over = ta.crossover(close[1], ema_200)
cross_over_touch = ta.cross(close, ema_200)
// Long Take Profit
long_tp_inp = input.float(1, title='Long Take Profit %', step=0.1, group='Set Take Profit %') / 100
long_take_level = strategy.position_avg_price * (1 + long_tp_inp)
// Long Stop Loss
long_sl_inp = input.float(0.5, title='Long Stop Loss %', step=0.1, group='Set Take Profit %') / 100
long_stop_level = strategy.position_avg_price * (1 - long_sl_inp)
// Strategy Execution
entry_long = cross_over and cross_over_touch and inDateRange
entry_price = ta.valuewhen(ta.cross(close, ema_200), close , 1)
strategy.entry(id='Long', direction=strategy.long, when=entry_long, limit=entry_price)
strategy.exit('Take Profit/ Stop Loss', 'Long', stop=entry_price, limit=long_take_level)
我设置 limit=entry_price
的行似乎没有任何作用。
您不能使用 historical data。
关于您需要使用的实时数据calc_on_every_tick parameter
我试图在当前价格 EMA200 的交叉点而不是收盘价处建仓。我不在乎价格是否回落。有什么办法可以实现吗?
strategy('EMA200 5 min', overlay=true, process_orders_on_close=true)
ema_200 = ta.ema(close, 200)
// For LONG check if previous bar crossed over EMA200 and set order when current bar crosses EMA200
cross_over = ta.crossover(close[1], ema_200)
cross_over_touch = ta.cross(close, ema_200)
// Long Take Profit
long_tp_inp = input.float(1, title='Long Take Profit %', step=0.1, group='Set Take Profit %') / 100
long_take_level = strategy.position_avg_price * (1 + long_tp_inp)
// Long Stop Loss
long_sl_inp = input.float(0.5, title='Long Stop Loss %', step=0.1, group='Set Take Profit %') / 100
long_stop_level = strategy.position_avg_price * (1 - long_sl_inp)
// Strategy Execution
entry_long = cross_over and cross_over_touch and inDateRange
entry_price = ta.valuewhen(ta.cross(close, ema_200), close , 1)
strategy.entry(id='Long', direction=strategy.long, when=entry_long, limit=entry_price)
strategy.exit('Take Profit/ Stop Loss', 'Long', stop=entry_price, limit=long_take_level)
我设置 limit=entry_price
的行似乎没有任何作用。
您不能使用 historical data。
关于您需要使用的实时数据calc_on_every_tick parameter