This ProBuilder script is designed to manage a short trading position with dynamic exit strategies based on moving averages. It calculates position size based on risk management principles and adjusts orders based on real-time market data.
defparam preloadbars = 10000
defparam cumulateorders = false
// manually enter these variables
spread = 0.01
accountsize = 25000
entrylevel = 146.662
stoplosslevel = 146.937
eurusd = 1.0387
// calculate the desired loss and adjust the entry levels for spread
loss = 0.005*accountsize*eurusd
entrylevel = entrylevel -0.5*spread
stoplosslevel = stoplosslevel+0.5*spread
// calculate the desired position size
Positionsize = (loss / ((stoplosslevel-entrylevel) * (pipvalue/pipsize)/close))
// can only do 1 trade
c1 = TradeIndex(1) = 0
// Short entry order placement with stoploss
IF NOT ShortOnMarket and c1 THEN
Sellshort Positionsize CONTRACTS AT entrylevel stop
Exitshort at stoplosslevel STOP
ENDIF
// Initial stoploss placement
IF ShortOnMarket THEN
Exitshort at stoplosslevel STOP
ENDIF
timeframe(1h, updateonclose)
// Trailingstop exits based on 1h MA10 and MA20 once in profit
once fullposition = 1
IF ShortOnMarket and trailingstop <= entrylevel THEN
if close crosses over average[20] then
Exitshort countofposition contracts at market
else if close crosses over average[10] and fullposition = 1 then
Exitshort (0.5*COUNTOFPOSITION) contracts at market
fullposition = 0
SET STOP $LOSS 0
endif
endif
ENDIF
This script includes several key components:
This example demonstrates how to integrate risk management and real-time trading adjustments using ProBuilder's programming capabilities.