This code snippet demonstrates how to implement different stop loss strategies in trading using the ProBuilder language. The strategies include a fixed stop loss, a fixed percentage below the Simple Moving Average (SMA), and a dynamic stop loss that updates based on the SMA.
// Fixed Stop Loss below SMA50
Sma50 = average[50,0](close)
MyLongConditions = close CROSSES OVER average[10,0](close)
IF MyLongConditions AND Not OnMarket THEN
BUY 1 Contract at Market
Sl = close - Sma50
Tp = Sl * 2
SET TARGET PROFIT Tp
SET STOP LOSS Sl
ENDIF
// Fixed Stop Loss at 1% below SMA50
Sma50 = average[50,0](close)
MyLongConditions = close CROSSES OVER average[10,0](close)
IF MyLongConditions AND Not OnMarket THEN
BUY 1 Contract at Market
Sl = close - (Sma50 * 0.99)
Tp = Sl * 2
SET TARGET PROFIT Tp
SET STOP LOSS Sl
ENDIF
// Dynamic Stop Loss at 1% below SMA50
Sma50 = average[50,0](close)
IF LongOnMarket THEN
Sl = TradePrice - (Sma50 * 0.99)
SET STOP LOSS Sl
ENDIF
MyLongConditions = close CROSSES OVER average[10,0](close)
IF MyLongConditions AND Not OnMarket THEN
BUY 1 Contract at Market
Sl = close - (Sma50 * 0.99)
Tp = Sl * 2
SET TARGET PROFIT Tp
SET STOP LOSS Sl
ENDIF
The code is structured into three main parts, each implementing a different type of stop loss strategy:
Each section checks for a long entry condition based on the crossover of the close price over a shorter SMA (SMA10), and if the condition is met and there is no open position, it executes a buy order. The stop loss and target profit are then set according to the respective strategy.
Check out this related content for more information:
https://www.prorealcode.com/topic/stop-loss-debajo-de-la-mm50-al-momento-de-la-compra/#post-175764
Visit Link