//--------------------------------------------------------//
// *** Range Breakout Backtest *** //
//--------------------------------------------------------//
// Author: Vivien Schmitt
// Website: https://artificall.com
// Range Breaker: https://artificall.com/range-breaker-prorealtime/
// Indicator: Range Breaker
// Date: 2025/02/24
//--------------------------------------------------------//
DEFPARAM CUMULATEORDERS = False
DEFPARAM PRELOADBARS = 1000
//--------------------------------------------------------//
// *** SETTING BLOCK *** //
//--------------------------------------------------------//
// * Position Size
// Capital to invest
ONCE CapitalToInvest = 10000
// Minimum number of contracts
ONCE NumberOfContractsMin = 0.5
// Position Size
NumberOfContracts = MAX(ROUND(CapitalToInvest / Close, 2), NumberOfContractsMin)
// * Indicator Parameters
// Type of Breakout
ONCE BullishBreakout = 1
ONCE BearishBreakout = 0
// Length of the range
ONCE RangeLength = 30
// Extension of the Range
ONCE RangeExtension = 5
// Min range height (%)
ONCE HeightMin = 20
// Max range height (%)
ONCE HeightMax = 100
// Breakout conditions
ONCE ValidatedBreakout = 0
// Volume Filter
ONCE VolumeIncreases = 0
// Trend Filter
ONCE IntTheTrend = 0
ONCE Reversal = 0
// Target and Stoploss levels
ONCE TargetLevel = 5
ONCE StoplossLevel = 5
// Font Size
ONCE FontSize = 12
// Starting Year
ONCE StartingYear = 2000
//--------------------------------------------------------//
//--------------------------------------------------------//
// *** INITIALIZATION OF THE VARIABLES *** //
//--------------------------------------------------------//
ONCE myBreakout = 0
ONCE myTargetLong = 0
ONCE myStoplossLong = 0
ONCE myTargetShort = 0
ONCE myStoplossShort = 0
//--------------------------------------------------------//
// *** INDICATOR CALLING *** //
//--------------------------------------------------------//
myBreakout, myTargetLong, myStoplossLong, myTargetShort, myStoplossShort = CALL "Range Breaker"[BullishBreakout, BearishBreakout, RangeLength, RangeExtension, HeightMin, HeightMax, ValidatedBreakout, VolumeIncreases, IntTheTrend, Reversal, TargetLevel, StoplossLevel, FontSize, StartingYear](close)
//--------------------------------------------------------//
// *** ENTRY OPENING *** //
//--------------------------------------------------------//
// *** LONG POSITION OPENING *** //
IF NOT OnMarket AND myBreakout = 1 THEN
BUY NumberOfContracts CONTRACTS AT MARKET
Set Target Price myTargetLong
Set Stop Price myStoplossLong
ENDIF
// *** SHORT POSITION OPENING *** //
IF NOT OnMarket AND myBreakout= -1 THEN
SELLSHORT NumberOfContracts CONTRACTS AT MARKET
Set Target Price myTargetShort
Set Stop Price myStoplossShort
ENDIF