This ProBuilder code snippet is designed to calculate various trading performance metrics such as average gain, average loss, percentage of winning trades, maximum run-up, maximum drawdown, gain-loss ratio, and performance index over a specified duration. These metrics are crucial for evaluating the effectiveness of a trading strategy.
// Rating formula
////////////////////////////////////////////////////////////////////////////////
// https://www.prorealcode.com/topic/scoring-your-report-data/
//
// av.Gain / Av.Loss * %Win * MaxRunup / MaxDD * GainLossRatio / Duration (days)
// Timeframe(default)
////////////////////////////////////////////////////////////////////////////////
// DrawDown & RunUp
ONCE Capital = 10000
ONCE MinPoint = Capital
ONCE MaxPoint = 0
ONCE MaxRU = 0
ONCE MaxDD = 0
//------------------------------------------
// EQUITY
Equity = Capital + StrategyProfit
TempProfit = PositionPerf * PositionPrice / PipSize * PipValue
TempEquity = Equity + TempProfit
//------------------------------------------
// DrawDown
MaxPoint = max(MaxPoint,TempEquity)
DD = MaxPoint - TempEquity
MaxDD = max(MaxDD,DD)
DDperc = MaxDD * 100 / Capital
//
//------------------------------------------
// RunUp
MinPoint = min(MinPoint,TempEquity)
RU = TempEquity - MinPoint
MaxRU = max(MaxRU,RU)
RUperc = MaxRU * 100 / Capital
//------------------------------------------
// DD/RU ratio
DDRUratio = MaxDD / MaxRU
////////////////////////////////////////////////////////////////////////////////
// DAY tally
Timeframe(Daily,UpdateOnClose)
ONCE Dtally = 0
Dtally = Dtally + 1
Timeframe(default)
////////////////////////////////////////////////////////////////////////////////
// Winning, Losing and Neutral trades
ONCE Winning = 0
ONCE Losing = 0
ONCE Neutral = 0
ONCE MoneyG = 0
ONCE MoneyL = 0
NewTrade = (OnMarket AND Not OnMarket[1]) OR (LongOnMarket AND ShortOnMarket[1]) OR (LongOnMarket[1] AND ShortOnMarket)
IF NewTrade THEN
Money = StrategyProfit - StrategyProfit[1]
IF Money > 0 THEN
Winning = Winning + 1
MoneyG = MoneyG + Money //Money GAINED
ELSIF Money < 0 THEN
Losing = Losing + 1
MoneyL = MoneyL + Money //Money LOST
ELSIF OnMarket AND OnMarket[1] THEN
Neutral = Neutral + 1
ENDIF
ENDIF
//
// %Winning, %Losing trades
TotalTrades = Winning + Losing// + Neutral //Neutral trades are ignored
WinPC = Winning * 100 / TotalTrades
WinPC = Losing * 100 / TotalTrades
WinRatio = Winning / Losing
//
// GainLoss Ratio
GainLossRatio = MoneyG / MoneyL
////////////////////////////////////////////////////////////////////////////////
PerfIND = (GainLossRatio * 1.00)
PerfIND = PerfIND * (WinRatio * 1.00)
PerfIND = PerfIND * (DDRUratio * 1.00)
PerfIND = PerfIND / (Dtally * 1.00)
////////////////////////////////////////////////////////////////////////////////
GRAPH PerfIND
////////////////////////////////////////////////////////////////////////////////
// Example(tested on DAX, 1H, 200K, ranges from -0.00001 down to -0.04641):
//
FastAVG = average[20,0](close)
SlowAVG = average[100,0](close)
IF FastAVG CROSSES OVER SlowAVG THEN
BUY AT Market
ENDIF
IF FastAVG CROSSES UNDER SlowAVG THEN
SELLSHORT AT Market
ENDIF
This code snippet includes several key sections:
Check out this related content for more information:
https://www.prorealcode.com/topic/scoring-your-report-data/#post-182413
Visit Link