This code snippet demonstrates how to implement a breakeven trading strategy using percentage thresholds in the ProBuilder language. The strategy adjusts the stop-loss order to a breakeven point after a specified percentage gain, aiming to secure a portion of the profits.
defparam cumulateorders = false
startBreakeven = 0.1 //how much percentage in price gain to activate the breakeven function?
PercentToKeep = 0.05 //how much percentage in price to keep in profit above or below our entry price when the breakeven is activated (beware of spread)
c1 = RSI[14] crosses over 50
if c1 then
BUY 1 LOT AT MARKET
SET STOP %LOSS 1
endif
//reset the breakevenLevel when no trade are on market
IF NOT ONMARKET THEN
breakevenLevel=0
ENDIF
// --- BUY SIDE ---
//test if the price have moved favourably of "startBreakeven" percent already
IF LONGONMARKET AND positionperf>=startBreakeven THEN
//calculate the breakevenLevel
PointsToKeep = (tradeprice(1)/100)*PercentToKeep
breakevenLevel = tradeprice(1)+PointsToKeep
ENDIF
//place the new stop orders on market at breakevenLevel
IF breakevenLevel>0 THEN
SELL AT breakevenLevel STOP
ENDIF
// --- end of BUY SIDE ---
// --- SELL SIDE ---
//test if the price have moved favourably of "startBreakeven" percent already
IF SHORTONMARKET AND positionperf>=startBreakeven THEN
//calculate the breakevenLevel
PointsToKeep = (tradeprice(1)/100)*PercentToKeep
breakevenLevel = tradeprice(1)-PointsToKeep
ENDIF
//place the new stop orders on market at breakevenLevel
IF breakevenLevel>0 THEN
EXITSHORT AT breakevenLevel STOP
ENDIF
// --- end of SELL SIDE ---
The code snippet above is structured to manage trading orders based on the performance of the current position relative to a set percentage gain:
This strategy helps in minimizing losses and protecting gains by dynamically adjusting stop-loss orders based on market performance relative to the entry point.
Check out this related content for more information:
https://www.prorealcode.com/topic/stop-nachziehen-aber-wie/#post-38428
Visit Link