Calculating Trading Performance Metrics in ProBuilder

08 Mar 2022
0 comment
0 attachment

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:

  • Initialization of Variables: Sets initial values for capital, points, and counters used to track performance metrics.
  • Equity Calculation: Computes real-time equity based on the strategy's profit and the current position's performance.
  • DrawDown and RunUp Calculation: Tracks the maximum drawdown and run-up values which are essential for assessing the risk and reward characteristics of the trading strategy.
  • Trade Outcome Analysis: Determines whether each trade is winning, losing, or neutral and calculates the total money gained or lost.
  • Performance Index Calculation: Combines all the metrics to compute a single performance index which is then plotted on the graph.
  • Example Trading Strategy: Includes a simple moving average crossover strategy to demonstrate how the metrics can be applied in real trading scenarios.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/scoring-your-report-data/#post-182413

Visit Link
What is a Snippet? A snippet is a small, reusable chunk of code designed to solve specific tasks quickly. Think of it as a shortcut that helps you achieve your coding goals without reinventing the wheel. How to Use: Simply copy the snippet and paste it into your project where needed. Don't forget to tweak it to fit your context. Snippets are not just time-savers; they're also learning tools to help you become a more efficient coder.
robertogozzi Master
Roberto https://www.ots-onlinetradingsoftware.com
Author’s Profile

Comments

Search Snippets

Showing some results...
Sorry, no result found!

Snippets Categories

global
35
indicator
133
strategy
171

Recent Snippets

How to Create a Simple MTF Trend Dashboard with EMA and SMA
indicator
This indicator builds a compact multi-timeframe (MTF) dashboard that shows whether price is trading above or below a [...]
How to Display Per-Bar Volume Accumulation in Real Time (Intrabar Updates)
global
This snippet tracks and displays the current bar’s accumulated volume while the bar is still forming, instead of only [...]
Ticks Counter: Count Tick Updates Per Bar on Tick or Time Charts
global
This snippet counts how many tick updates have occurred for the current bar by incrementing a per-bar counter on each [...]
How to Build a Step-Based Trailing Stop That Moves to Break-Even First
strategy
This snippet implements a step trailing stop that advances in fixed increments once price reaches predefined profit [...]
Utilizing Arrays to Track and Compare Indicator Values Within the Same Bar in ProBuilder
indicator
This ProBuilder code snippet demonstrates how to use arrays to compare the values of an indicator (RSI in this case) [...]
Logo Logo
Loading...