This code snippet demonstrates how to implement a sequential event detection system in a trading strategy using the ProBuilder language. The system checks for a series of conditions (events) across different timeframes before executing a trade. Each event has a specific lookback period, after which the condition must be re-evaluated.
TIMEFRAME(Daily,updateonclose)
ONCE LookBackA = 5 //after 5 bars reenable checking event
ONCE barA = 0
IF barA AND (barindex - barA) >= LookBackA THEN
barA = 0
ENDIF
IF barA = 0 THEN
eventA = average[10,0](close) CROSSES OVER average[30,0](close)
IF eventA THEN
barA = barindex //save the bar number
ENDIF
ENDIF
// TIMEFRAME(4 hour,updateonclose)
ONCE LookBackB = 5
ONCE barB = 0
IF (barB AND (barindex - barB) >= LookBackB) OR barA = 0 THEN
barB = 0
ENDIF
IF barB = 0 AND barA THEN
eventB = rsi[14](close) CROSSES OVER 30
IF eventB THEN
barB = barindex
ENDIF
ENDIF
// TIMEFRAME(1 hour,updateonclose)
ONCE LookBackC = 5
ONCE barC = 0
IF (barC AND (barindex - barC) >= LookBackC) OR barB = 0 THEN
barC = 0
ENDIF
IF barC = 0 AND barB THEN
eventC = MACD[12,26,9](close) > 0
IF eventC THEN
barC = barindex
ENDIF
ENDIF
// TIMEFRAME(default)
ONCE LookBackD = 5
ONCE barD = 0
IF (barD AND (barindex - barD) >= LookBackD) OR barC = 0 THEN
barD = 0
ENDIF
IF barD = 0 AND barC THEN
eventD = (high = highest[20](high))
IF eventD THEN
barD = barindex
ENDIF
ENDIF
IF eventA AND eventB AND eventC AND eventD AND Not OnMarket THEN
BUY 1 CONTRACT AT MARKET
SET STOP PLOSS 20
SET TARGET PROFIT 60
ENDIF
The code is structured to check for four sequential trading events across different timeframes before placing a trade. Here’s a breakdown of its functionality:
This sequential checking ensures that each condition is dependent on the fulfillment of the previous one, making the strategy stringent and potentially more reliable.
Check out this related content for more information:
https://www.prorealcode.com/topic/mtf-sequential-setup/#post-102442
Visit Link