我是松-脚本的新手,目前我正在玩一些现有的脚本。
我想知道战略测试器是否被窃听了。
我已经编辑了这个问题,简化了很多脚本,只是为了关注我的问题,正如评论者所建议的那样。
1)我在数量上有问题。我写了这个脚本,它需要一个简单的信号(交叉2 MA),并试图翻转一个多空头寸,其大小总是相同的,100,000美元。
这就是为什么我定义了
strategy("Debug Qty and Returns ", default_qty_type=strategy.cash, default_qty_value=100000,overlay=true, precision=5)我在代码BITMEX上尝试了以下脚本:每日XBT美元间隔
//@version=3
strategy("Debug Qty and Returns ", default_qty_type=strategy.cash, default_qty_value=100000,overlay=true, precision=5)
// Upon execution, why are some short trades with a notional of 200,000 USD equivalent ?
tradeType = input("BOTH", title="Trade Type ", options=["LONG", "SHORT", "BOTH"])
// === BACKTEST RANGE ===
FromMonth = input(defval = 1, title = "From Month", minval = 1)
FromDay = input(defval = 1, title = "From Day", minval = 1)
FromYear = input(defval = 2019, title = "From Year", minval = 2014)
ToMonth = input(defval = 1, title = "To Month", minval = 1)
ToDay = input(defval = 1, title = "To Day", minval = 1)
ToYear = input(defval = 9999, title = "To Year", minval = 2014)
testPeriod() =>
(time > timestamp(FromYear, FromMonth, FromDay, 00, 00)) and (time < timestamp(ToYear, ToMonth, ToDay, 23, 59))
//////////////////////////////
isLongOpen = false
isShortOpen = false
//Order open on previous ticker?
isLongOpen := nz(isLongOpen[1])
isShortOpen := nz(isShortOpen[1])
////////////
//Somes EMAs to trigger trades
ema7Avg = ema(ohlc4, 7)
ema30Avg = ema(ohlc4, 30)
plot(ema7Avg)
plot(ema30Avg)
//Entry Conditions
shortEntry= (tradeType=="SHORT" or tradeType=="BOTH") and crossunder(ema7Avg,ema30Avg )
longEntry = (tradeType=="LONG" or tradeType=="BOTH") and crossover(ema7Avg,ema30Avg )
///////////////////
shortExit = isShortOpen[1] and longEntry
longExit = isLongOpen[1] and shortEntry
if(testPeriod() and (tradeType == "LONG" or tradeType == "BOTH" ))
strategy.entry("long", strategy.long, when=longEntry)
strategy.close("long", when = longExit)
if(testPeriod() and (tradeType == "SHORT" or tradeType == "BOTH" ))
strategy.entry("short", strategy.short, when=shortEntry)
strategy.close("short", when = shortExit)
//If the value changed to invoke a buy, lets set it before we leave
isLongOpen := longEntry ? true : (longExit == true ? false : isLongOpen)
isShortOpen := shortEntry ? true : (shortExit == true ? false : isShortOpen)
plotshape(isShortOpen, title= "Short Open", color=red, style=shape.circle, location=location.bottom)
plotshape(isLongOpen, title= "Long Open", color=green, style=shape.circle, location=location.bottom)在选定的图表和时间间隔内,只有3个信号。
它以4,005美元的价格为24.96合约开盘Jan8th,其价值为24.96,因此所花费的总价值为4,005*24.96 = 100,000美元
然后,策略测试人员发现,当策略在Jan12th上翻转时,它确实在3,631.5点结束(亏损)多头头寸,并以相同的价格做空,但是空头头寸的数量是52.5055合约,相当于总价值(3,631.5*52.5055) =20万美元。
这不是我所期望的行为。
2)我注意到,strategy.entry命令以与下一支蜡烛打开的价格相等的价格打开交易,然后满足进入条件。这是正常行为吗?
发布于 2019-03-14 10:26:09
这里描述了您的两个问题/问题:emulator,broker emulator主题涵盖第二个问题,Order placement commands涵盖第一个问题。
简而言之(对不起双关语),你下了两份相同条件的订单,一条一条。因此,这是模仿一种情况,有时会发生在真正的经纪人。首先,多头头寸被填满,所以你以10万美元的价格得到BTC,然后第二个订单说:‘我想在100 K中出现BTC的亏空’,因为策略测试者以100,000美元的价格卖出你的BTC,再卖出100,000美元来做空。
发布于 2019-03-14 17:34:33
谢谢Michel_T
如果我将strategy.close转换为strategy.exit
问题消失了
发布于 2019-03-23 00:40:38
这是TradingView回溯测试器中的一个巨大且著名的错误。每当strategy.close条件与strategy.entry条件一致(因此一个交易在下一个交易被打开的同时被关闭),一些非常丑陋的条目被添加到交易列表中--一个交易被输入一个信号“关闭入口顺序.”?这根本没道理。
像这样的条目包含在反测试计算中,因此完全破坏了它。有时他们在提高回溯成绩,有时他们使情况变得更糟--但他们总是不正确。
解决方案:导出整个交易列表,粘贴到Excel中,手动删除那些难看的交易。导出功能由ProvitView或AutoView Chrome插件提供。
https://stackoverflow.com/questions/55147752
复制相似问题