我遇到以下问题:
我输入一个在收盘价 < EMA 后关闭的策略。为了更好地退出,我想在收盘 > EMA 时关闭它,但低点(入场后任何给定的柱)低于 EMA(低点 < EMA)。
我不知道如何执行“输入后的任何给定栏”时刻。我猜脚本应该以某种方式存储前一个柱的值(如果为真),但是当策略实际启动时,脚本编写就会出现问题。任何帮助,将不胜感激!
附言。如您所见,我不是编码员,这可能很难理解。我对此深表歉意,并感谢您抽出时间。
米哈伊尔
我尝试用strategy.position_avg_price > 0 来说明入场条件何时开启,并添加所需的条件:
h = nz(strategy.position_avg_price) > 0 and not
crossunder(close,ema(close,length)) and
crossunder(low,ema(close,length)) ? 1 : 0
rightborder = barstate.islast // treat the last bar (most recent bar)
as the right edge of the lookback window range
// if examining the last bar (newest bar, rightborder is true)
// set variable "val" to the previous value of series variable "h"
// else set to na so nothing is plotted
val = rightborder ? h[1] : na
Run Code Online (Sandbox Code Playgroud)
但没有成功...
scalp = b and c and d and e and f and g ? 1 : 0 // scalp is main
variable, if 1 the strategy is entered//
if (scalp)
strategy.entry("Short", strategy.short, when = scalp) // entry of
strategy
if (crossunder(close,ema(close,length))) // usual close of strategy
strategy.close("Short")
if (not crossunder(close,ema(close,length)) and
crossunder(low,ema(close,length))) // attempt for a better exit!
strategy.close("Short")
Run Code Online (Sandbox Code Playgroud)
在研究了米奇的建议后:
///Entry
if entry_on == 0 and scalp
strategy.entry("Short", strategy.short)
entry_on := 1
///Desired exit
if entry_on == 1 and crossunder(close,ema(close,length))
strategy.close("Short")
entry_on := 0
/// Risk mitigation - 1 - Additional risk mitigation (when close > ema but
low < ema of any given candle after entry -> exit at breakeven)
if entry_on == 1 and close > ema(close, length) and low < ema(close, length)
entry_on := 2
if entry_on == 2 and crossover(close,strategy.position_avg_price)
strategy.close("Short")
entry_on := 0
/// Risk mitigation - 2 - exit 15 bars after entry if not desired exit or
risk mitigation - 1
if entry_on == 1 and scalp[15]
strategy.close("Short")
entry_on := 0
Run Code Online (Sandbox Code Playgroud)
小智 5
尝试这样的事情:
entry_on = 0.0
entry_on := entry_on[1] //this will carry entry_on result from last candle
if entry_on == 0 and close > ema(close, length)
xx enter your open position code
entry_on := 1
if entry_on == 1
if close < ema(close, length) or low < ema(close, length)
xx enter your close position code
entry_on := 0
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4685 次 |
| 最近记录: |