This code snippet demonstrates how to simulate a trading strategy in ProBuilder, which is particularly useful for testing strategies that involve pending orders. The example provided calculates an equity curve, allowing for performance analysis over time.
p = 300
upper = open + average[p](high[1]-open[1])
lower = average[p](close[2]-low[1])
if (not flag) and (low < (close[1] - lower[1])) and (low[1] > average[p,2](close[1])) then
drawarrowup(barindex, low) coloured(0,128,0)
entryprice = close[1] - lower[1]
startequity = equity
flag = 1
endif
if flag[1] then
floatingequity = startequity + (close - entryprice)
endif
if (flag[1] = 1) and ((close > entryprice) or (high < average[p,2](close[1]))) and (entryprice <> 0) then
equity = equity + (close - entryprice)
flag = 0
drawarrowdown(barindex, high) coloured(128,0,0)
endif
return floatingequity as "equity"
The code snippet above is structured to simulate entry and exit points of a trading strategy based on specific conditions, and to calculate the resulting equity curve. Here’s a step-by-step breakdown:
This example is useful for understanding how to simulate trading strategies and visualize their performance through an equity curve in the ProBuilder language.