This code snippet demonstrates how to implement dynamic exit strategies in trading algorithms using the ProBuilder language. It includes two distinct strategies for exiting trades based on market conditions and price movements.
// support & resistence once supportresistance = 0 // exit [0-1-2] // timeframe(30 seconds)
if supportresistance then
pivotbar = 20
lookback = 20
barlookback = pivotbar + 1
if low[pivotbar] < lowest[lookback](low)[barlookback] then
if low[pivotbar] = lowest[barlookback](low) then
supportprice = low[pivotbar]
endif
endif
if high[pivotbar] > highest[lookback](high)[barlookback] then
if high[pivotbar] = highest[barlookback](high) then
resistanceprice = high[pivotbar]
endif
endif
endif
timeframe(default)
if supportresistance=1 then
if ((longonmarket and shortonmarket[1]) or (longonmarket and not onmarket[1])) then
sup=supportprice
endif
if ((shortonmarket and longonmarket[1]) or (shortonmarket and not onmarket[1])) then
res=resistanceprice
endif
elsif supportresistance=2 then
sup=supportprice
res=resistanceprice
endif
if supportresistance=1 or supportresistance=2 then
if longonmarket then
sell at sup stop
endif
if shortonmarket then
exitshort at res stop
endif
endif
graphonprice sub
graphonprice res
// exitpivot
once exitpivot=2 // exit [0-1-2] //
if exitpivot=1 or exitpivot=2 then
duration=360 // 720 = 1 hour lookback on 5s
breakvalue=0
if not onmarket then
prell=0
prehh=0
endif
if longonmarket then
prehh=highest[max(1,(barindex-tradeindex))](high)
endif
if ((longonmarket and shortonmarket[1]) or (longonmarket and not onmarket[1])) then
prell=lowest[duration](low)
endif
if shortonmarket then
prell=lowest[max(1,(barindex-tradeindex))](low)
endif
if ((shortonmarket and longonmarket[1]) or (shortonmarket and not onmarket[1])) then
prehh=highest[duration](high)
endif
if onmarket then
fibpivot=(prehh-prell)*0.618
else
fibpivot=0
endif
if exitpivot=1 then
if longonmarket then
sell at (prehh-fibpivot)-breakvalue stop
endif
if shortonmarket then
exitshort at (prell+fibpivot)+breakvalue stop
endif
endif
if exitpivot=2 then
if longonmarket then
sell at prell-breakvalue stop
endif
if shortonmarket then
exitshort at prehh+breakvalue stop
endif
endif
endif
graphonprice prehh
graphonprice prell
graphonprice prell+fibpivot coloured(255,0,0,255) as "short exit"
graphonprice prehh-fibpivot coloured(0,0,255,255) as "long exit"
The code is structured into two main parts, each defining a different exit strategy:
Both strategies are designed to help manage risk by specifying conditions under which a trade should be exited, potentially protecting gains or minimizing losses.
Check out this related content for more information:
https://www.prorealcode.com/topic/discussion-re-pure-renko-strategy/page/23/#post-136817
Visit Link