This topic presents a Sure-Fire flip-at-stop recovery strategy coded for ProRealTime / ProOrder.
Main characteristics:
- No hedging (only one position at a time)
- STOP orders only for reversals
- When a position hits its stop, an opposite order is triggered at the exact same price
- Position size is recalculated at each level to:
- recover all previous losses
- reach a fixed net profit target
- Fully parameterized
- Modular architecture using CALL functions

This code is fully functional and intended for advanced users who understand recovery systems and risk management.
Strategy Logic (High Level):
> The strategy starts with an initial direction (Dir0)
> An entry is triggered using:
- a breakout STOP order, or
- a moving average crossover (optional)
> Once in position:
- a Take Profit is set
- a reverse STOP order is placed at the stop level
>If Take Profit is hit:
- the cycle ends
- level and losses are reset
>If Stop Loss is hit:
- the reverse order opens a new position
- direction flips
- lot size increases
- level increments
>The process repeats until:
- profit is achieved
- or
Nmax recovery levels are reached
User Parameters:
Strategy = 1 // 0 = breakout, 1 = MA cross
once Dir0 = 1 // Initial direction: 1 = long, -1 = short
once D0 = 20.0 // Initial stop distance (points)
once rTPoverSL = 1.2 // Take Profit / Stop Loss ratio
once eScale = 1.0 // Distance scaling (1.0 = constant)
once GtargetEUR = 10.0 // Net profit target per cycle (ā¬)
once Nmax = 5 // Maximum recovery levels
once MinLot = 1.0
once LotStep = 1.0
once LotMax = 100.0
once nBreak = 20 // Breakout lookback
once bufferPts = 1.0 // Breakout buffer (points)
With eScale = 1.0, stop and target distances remain constant at all levels.
Main Strategy Code:
DEFPARAM CumulateOrders = False
ONCE level = 0
ONCE CprevEUR = 0.0
ONCE lastEntryPrice = 0.0
once ipointvalue = pointvalue
longWasOn = LONGONMARKET[1]
shortWasOn = SHORTONMARKET[1]
// --- Current level setup
dirK = CALL "SF_DirectionAtLevel"[Dir0, level]
SLpts, TPpts = CALL "SF_LevelMetrics"[D0, rTPoverSL, eScale, level]
lotK = CALL "SF_LotSizer"[CprevEUR, GtargetEUR, TPpts, ipointvalue, MinLot, LotStep, LotMax]
// --- End of cycle reset
IF NOT ONMARKET AND (longWasOn OR shortWasOn) THEN
level = 0
CprevEUR = 0
dirK = Dir0
traded = 0
ENDIF
// --- Entry logic
IF NOT ONMARKET THEN
IF Strategy = 0 THEN
entryStopPrice = CALL "SF_EntryStopPrice"[dirK, nBreak, bufferPts]
IF dirK = 1 THEN
BUY lotK CONTRACTS AT entryStopPrice STOP
ELSE
SELLSHORT lotK CONTRACTS AT entryStopPrice STOP
ENDIF
ELSIF Strategy = 1 THEN
maf = average[7,1]
mas = average[21,1]
IF maf CROSSES OVER mas THEN
dirK = 1
BUY lotK CONTRACTS AT MARKET
SET TARGET PPROFIT TPpts
IF traded = 0 THEN Dir0 = dirK : traded = 1 ENDIF
ELSIF maf CROSSES UNDER mas THEN
dirK = -1
SELLSHORT lotK CONTRACTS AT MARKET
SET TARGET PPROFIT TPpts
IF traded = 0 THEN Dir0 = dirK : traded = 1 ENDIF
ENDIF
ENDIF
ENDIF
// --- Position management
IF ONMARKET THEN
SET TARGET PPROFIT TPpts
revPrice = CALL "SF_ReversePrice"[positionprice, dirK, SLpts]
CprevNextEUR = CprevEUR + lotK * SLpts * pointvalue
SLptsNext, TPptsNext = CALL "SF_LevelMetrics"[D0, rTPoverSL, eScale, level + 1]
lotNext = CALL "SF_LotSizer"[CprevNextEUR, GtargetEUR, TPptsNext, ipointvalue, MinLot, LotStep, LotMax]
IF level < Nmax - 1 THEN
IF dirK = 1 THEN
SELLSHORT lotNext CONTRACTS AT revPrice STOP
ELSE
BUY lotNext CONTRACTS AT revPrice STOP
ENDIF
SET STOP PRICE 0
ELSE
SET STOP PRICE revPrice
ENDIF
IF (longWasOn AND SHORTONMARKET) OR (shortWasOn AND LONGONMARKET) THEN
CprevEUR = CprevNextEUR
level = level + 1
lastEntryPrice = positionprice
ENDIF
ENDIF
Functions (Called via CALL)
CALL “SF_LevelMetrics”
Calculates stop and target distances per recovery level.
SLpts = D0 * POW(e, level)
TPpts = r * SLpts
RETURN SLpts, TPpts
CALL “SF_LotSizer”
Computes the minimum lot size required to recover losses and reach the profit target.
raw = (CprevEUR + GtargetEUR) / (TPpts * iPointValue)
q = raw / LotStep
qInt = round(q, 0)
ceilq = qInt + (q > qInt)
ilot = ceilq * LotStep
IF ilot < MinLot THEN ilot = MinLot ENDIF
IF ilot > LotMax THEN ilot = LotMax ENDIF
RETURN ilot
CALL “SF_EntryStopPrice”
Determines the STOP entry price based on a breakout.
IF dir = 1 THEN
entryStopPrice = HIGHEST[nBreak](HIGH) + bufferPts * pointsize
ELSE
entryStopPrice = LOWEST[nBreak](LOW) - bufferPts * pointsize
ENDIF
RETURN entryStopPrice
CALL “SF_ReversePrice”
Returns the exact price where the position must flip.
reversePrice = entryPrice - dir * SLpts * pointsize
RETURN reversePrice
CALL “SF_DirectionAtLevel”
Defines trade direction depending on the recovery level.
IF level MOD 2 = 0 THEN
dir = Dir0
ELSE
dir = -Dir0
ENDIF
RETURN dir
Important Notes
ā ļø This is a recovery system with increasing exposure
- Lot size can grow very fast
- Margin requirements may explode
- Slippage and gaps can invalidate assumptions
- Always use:
NmaxLotMax- session filters
- volatility filters
- manual emergency stop
This strategy is not a free lunch and must be tested thoroughly.
Good Luck! š