This ProBuilder script is designed to manage a trading position by implementing a trailing stop loss and instantly reopening a trade when certain conditions are met. The code snippet below demonstrates how to set up these trading controls.
Once TriggerPips = 175 * pipsize
Once CloseTrigger = 100 * pipsize
Once TPflag = 0 //will be set to 1 when TP reaches 175 pips
If not OnMarket then
TPflag = 0
MyProfit = 0
Endif
If LongOnMarket then
MyProfit = Close - PositionPrice
Elsif ShortOnMarket then
MyProfit = PositionPrice - close
Endif
If MyProfit >= TriggerPips Then
TPflag = 1
Endif
If TPflag And MyProfit <= CloseTrigger Then
TPflag = 0
MyProfit = 0
NewSL = 0
If LongOnMarket Then
Sell at Market
Buy 1 Contract at Market
Elsif ShortOnMarket Then
Exitshort at Market
Sellshort 1 contract at Market
Endif
Endif
The code operates as follows:
This script is useful for traders looking to capitalize on favorable market movements while protecting gains with a trailing stop, and immediately re-entering the market upon retracement.