2
我使用系统投资者工具箱(SIT)在R中测试我的策略。目前,我正在使用此功能在回溯测试中将其用作fixed stop loss。如何在SIT R中编写自定义止损功能?
stop.loss <- function(weight, price, tstart, tend, pstop) {
index = tstart : tend
if(weight > 0)
price[ index ] < (1 - pstop) * price[ tstart ]
else
price[ index ] > (1 + pstop) * price[ tstart ]
}
#The stop loss function
Stoploss = .25/100
#Set our maximum loss at a .25% move in price against our trade
data$weight[] = NA
data$weight[] = custom.stop.fn(coredata(long.short.strategy), coredata(prices), stop.loss,pstop = Stoploss)
models$stoploss = bt.run.share(data, clean.signal=T, trade.summary = TRUE)
#Our long short model with a .25% stop loss
我想创建SIT自己的自定义停止功能,但不知道如何,应在SIT中使用什么参数用于此目的。
我的自定义止损的想法是
1) Initially fixed stop loss should be 10% of entry price
2) when price move more than 20% of entry price a new fixed stop loss be made at 10% of new entry price
这不是一个尾随止损,因为我不想止损落后的价格,但只能移动一次。