松树脚本中有一些功能,例如:
closed_trades = strategy.closedtrades
win_trades = strategy.wintrades
loss_trades = strategy.losstrades
percent_profitable = (strategy.wintrades/strategy.closedtrades)*100
但是在不使用这些功能的情况下,如何在pine脚本中测量这些参数?我尝试对其进行编码,但无法管理。你能帮我吗?
最好的问候
//@version=4
study("My Script",overlay=true)
ema1=ema(close,9)
ema2=ema(close,21)
buy=crossover(ema1,ema2)
sell=crossunder(ema1,ema2)
buy_price=valuewhen(buy,close,1)
sell_price=valuewhen(sell,close,1)
plot(ema1,color=color.green)
plot(ema2,color=color.red)
buy_cnt=cum(buy?1:0)
sell_cnt=cum(sell?1:0)
total_cnt = buy_cnt + sell_cnt
win_cnt = cum(buy_price>sell_price?1:0)
loss_cnt = cum(buy_price<sell_price?1:0)
f_draw_label(x,y,textline)=>
var label Label = na
label.delete(Label)
Label := label.new(x, y, textline, color=color.blue, textcolor=color.white,textalign=text.align_left, style=label.style_labeldown, yloc=yloc.price, xloc=xloc.bar_time)
x = timenow
y = highest(close,50)
format_text(str) =>
str + "\n"
txt1 = format_text(tostring(total_cnt))
txt2 = format_text(tostring(buy_cnt))
txt3 = format_text(tostring(sell_cnt))
txt4 = format_text(tostring(win_cnt + loss_cnt))
txt5 = format_text(tostring(win_cnt))
txt6 = format_text(tostring(loss_cnt))
all_txt=txt1 + txt2 + txt3 + txt4 + txt5 + txt6
f_draw_label(x,y,all_txt)
答案 0 :(得分:0)
您需要进行自己的交易管理,并使用var来跟踪您何时进入,何时进行交易。输入时保存输入级别,然后在退出时测量增量并相应地更新交易计数。有关完整的贸易管理代码,请参见Backtesting & Trading Engine。