В скрипте Pine есть некоторые функции, например:
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)