因此,我在tradingview中创建了我的第一个策略,到目前为止,它正确地绘制了对象,但是当我试图使用入口/退出函数时,它并不像我所希望的那样工作。

//@version=4
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mattehalen
strategy("Mathias & Christer Timeframe RSI", shorttitle="M&C_RSI",overlay=true)
len = input(7, title="Length", type=input.integer)
src = input(close, title="Source", type=input.source)
show4h = input(true, title="show 4h", type=input.bool)
rsiCurrent = rsi(src, len)
rsi4h = security(syminfo.ticker, "240", rsi(src, len))
//--------------------------------------------------
//MA
trendMA = ema(close,200)
shortMA = ema(close,50)
longMA = ema(close,20)
plot(trendMA, color=color.black, linewidth=5)
plot(shortMA, color=color.red, linewidth=2)
plot(longMA, color=color.green, linewidth=2)
bgcolor(crossunder(longMA,shortMA) ? color.black : na, transp=10)
//--------------------------------------------------
//RSI
BuySignalBarssince = barssince(rsi4h[1]<rsi4h[0] and rsi4h[1]<20)
BuySignal = (rsi4h[1]<rsi4h[0] and rsi4h[1]<20 and BuySignalBarssince[1]>10)
BuySignalOut = crossunder(shortMA,longMA)
bgcolor(BuySignal ? color.green : na, transp=70)
bgcolor(BuySignalOut ? color.green : na, transp=10)
SellSignalBarssince = barssince(rsi4h[1]>rsi4h[0] and rsi4h[1]>80)
SellSignal = (rsi4h[1]>rsi4h[0] and rsi4h[1]>80 and SellSignalBarssince[1]>10)
SellSignalOut = crossunder(longMA,shortMA)
bgcolor(SellSignal ? color.red : na, transp=70)
bgcolor(SellSignalOut ? color.red : na, transp=10)
strategy.entry("short", false, 10000, when = SellSignal)
strategy.exit("exit", "short", when = SellSignalOut, loss = 5000)
strategy.entry("long", true, 10000, when = BuySignal)
strategy.exit("exit", "long", when = BuySignalOut, loss = 5000)所以我现在最大的问题是退出函数不起作用,我也不知道为什么它不起作用。
我的另一个问题是,所有的顾客都被一根蜡烛抵消了,我不知道为什么。
到目前为止,当策略测试器触发所有错误时,我还没有一个好的答案。
我所能得到的一切帮助都是值得感激的
发布于 2020-05-08 07:14:48
您没有解释所需的输入/退出条件的细节,因此进行了猜测。
由于固定数量的合同会产生不现实的结果,所以在使用
process_orders_on_close = true时,possible.default_qty_type = strategy.percent_of_equity, default_qty_value = 100在strategy()调用中用于在bar上执行订单,因为即使所需资金不是available.strategy.exit()输入关于最大损失的出口订单。损失量可以通过Inputs.strategy.close().//@version=4
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mattehalen
strategy("Mathias & Christer Timeframe RSI", shorttitle="M&C_RSI",overlay=true, process_orders_on_close = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100)
len = input(7, title="Length", type=input.integer)
src = input(close, title="Source", type=input.source)
show4h = input(true, title="show 4h", type=input.bool)
maxLoss = input(2000)
rsiCurrent = rsi(src, len)
rsi4h = security(syminfo.ticker, "240", rsi(src, len))
//--------------------------------------------------
//MA
trendMA = ema(close,200)
shortMA = ema(close,50)
longMA = ema(close,20)
plot(trendMA, color=color.black, linewidth=5)
plot(shortMA, color=color.red, linewidth=2)
plot(longMA, color=color.green, linewidth=2)
bgcolor(crossunder(longMA,shortMA) ? color.silver : na, transp=10)
//--------------------------------------------------
//RSI
BuySignalBarssince = barssince(rsi4h[1]<rsi4h[0] and rsi4h[1]<20)
BuySignal = (rsi4h[1]<rsi4h[0] and rsi4h[1]<20 and BuySignalBarssince[1]>10)
BuySignalOut = crossunder(shortMA,longMA)
SellSignalBarssince = barssince(rsi4h[1]>rsi4h[0] and rsi4h[1]>80)
SellSignal = (rsi4h[1]>rsi4h[0] and rsi4h[1]>80 and SellSignalBarssince[1]>10)
SellSignalOut = crossunder(longMA,shortMA)
if BuySignal
strategy.close("short", comment = "Exit short")
strategy.entry("long", true)
strategy.exit("Max Loss", "long", loss = maxLoss)
if BuySignalOut
strategy.close("long", comment = "Exit Long")
if SellSignal
// Enter trade and issue exit order on max loss.
strategy.close("long", comment = "Exit Long")
strategy.entry("short", false)
strategy.exit("Max Loss", "short", loss = maxLoss)
if SellSignalOut
// Force trade exit.
strategy.close("short", comment = "Exit short")
plotchar(BuySignal, "BuySignal", "►", location.top, color.lime)
plotchar(BuySignalOut, "BuySignalOut", "◄", location.top, color.lime)
plotchar(SellSignal, "SellSignal", "►", location.bottom, color.red)
plotchar(SellSignalOut, "SellSignalOut", "◄", location.bottom, color.red)

https://stackoverflow.com/questions/61667962
复制相似问题