This code snippet demonstrates how to implement trailing stops with different percentage values based on specific time intervals during the trading day. Trailing stops are a type of stop-loss order that adjusts automatically to the price movements of a stock.
IF time >= 000000 AND time <= 130000 THEN
percentagelong = 0.45
percentageshort = 0.30
ELSIF time > 130000 AND time <= 230000 THEN
percentagelong = 0.45
percentageshort = 0.30
ENDIF
TGL = (close/100)*percentagelong
TGS = (close/100)*percentageshort
if not onmarket then
MAXPRICE = 0
MINPRICE = close
PREZZOUSCITA = 0
ENDIF
if longonmarket then
MAXPRICE = MAX(MAXPRICE,close)
if MAXPRICE-tradeprice(1)>=TGL then
PREZZOUSCITA = MAXPRICE-tgl
ENDIF
ENDIF
if shortonmarket then
MINPRICE = MIN(MINPRICE,close)
if tradeprice(1)-MINPRICE>=TGS then
PREZZOUSCITA = MINPRICE+tgs
ENDIF
ENDIF
if onmarket and PREZZOUSCITA>0 then
EXITSHORT AT PREZZOUSCITA STOP
SELL AT PREZZOUSCITA STOP
ENDIF
The code is structured to adjust the trailing stop percentages based on the time of day. Here’s a breakdown of its functionality:
This example is useful for understanding how to implement dynamic trading strategies based on time-specific criteria in ProBuilder.
Check out this related content for more information:
https://www.prorealcode.com/topic/trailing-stop-16/#post-84233
Visit Link