Get the time of last Stop Loss (not bars ago)
Forums › ProRealTime English forum › ProOrder support › Get the time of last Stop Loss (not bars ago)
-
-
11/28/2025 at 10:47 AM #25402811/28/2025 at 1:32 PM #25403911/28/2025 at 3:19 PM #254047
The code is on 1 minute timeframe and there are other ways to exit the trade also. But I want only the stop loss give the break of 10 minuttes. Here is a simplified version:
DEFPARAM CumulateOrders = False
// Conditions to enter long positions
timeframe(1 minutes)
indicator1 = Average[1](Stochastic[9,3](close))
c93lav = (indicator1 <= 23)
indicator2 = Average[1](Stochastic[60,10](close))
c6010hoej = (indicator2 >= 80)IF c93lav AND c6010hoej THEN
BUY 1 SHARES AT MARKET
ENDIF// Conditions to exit long positions
timeframe(1 minutes)
EMA200 = ExponentialAverage[200](close)
c3 = (EMA200 – 5 >= close)
IF c3 THEN
SELL AT MARKET
ENDIF// Stops and targets
SET STOP pLOSS 4.7
SET TARGET pPROFIT 5.811/28/2025 at 4:16 PM #254051Here you have an example to control exit:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748// ===========================// Example: NO entry before x minutes after loss// ===========================// ----- General settingsDEFPARAM CumulateOrders = falsex = 10once exitTypeSL=0// ----- Setup Long (example)atr = averagetruerange[14](close)sma5 = average[5](close)sma60 = average[60](close)setupLong = sma5 crosses over sma60if not onmarket and setupLong and ((bars > x and exitTypeSL) or exitTypeSL=0) thenSL=close-2*atrTP=close+3*atrbuy 1 contract at marketset stop price SLset target price TPendifif not onmarket and onmarket[1] thenif strategyprofit>strategyprofit[1] thenexitTypeSL=0bars=0elseexitTypeSL=1bars=1endifelsif not onmarket and exitTypeSL thenbars=bars+1elsif onmarket thenbars=0endif// ===========================// Graphs for monitoring// ===========================GRAPH bars COLOURED("blue")GRAPH x coloured("red")GRAPHONPRICE sma5 COLOURED("fuchsia")GRAPHONPRICE sma60 COLOURED("orange")GRAPHONPRICE SL COLOURED("red")GRAPHONPRICE TP COLOURED("green")3 users thanked author for this post.
11/30/2025 at 1:41 PM #254098At first i thought of the same simple solution as Ivan posted just above, but then i though about a more sophisticated solution that seems not working any better than the simple one… If Someone knows why this kind of solution works well in Probuilder as an indicator, but not in probacktest…
https://www.prorealcode.com/topic/array-variables-availability-in-prorealtime/page/2/#post-12066312345678910111213141516171819202122232425262728293031323334353637383940Timeframe(1 minutes)//Store Buy TimeOnce HalfSpread = 1Once $StopLossTime[0]=TimeOnce $StopLossIndex[0]=BarindexOnce $EntryPriceIndex[0]=Barindexif Longtriggered then //and Lastset($EntryPriceIndex)<Barindex then//$EntryPrice[Barindex]=Open+HalfSpreadEntryPrice = Open + HalfSpreadStopLossPrice = EntryPrice - 4.7Endifif (longtriggered or OnMarket[1]) and Close<=StopLossPrice and Lastset($StopLossIndex)<barindex then$StopLossTime[Barindex]=Time$StopLossIndex[Barindex]=Barindexendif// Conditions to enter long positionsindicator1 = Average[1](Stochastic[9,3](close))c93lav = (indicator1 <= 23)indicator2 = Average[1](Stochastic[60,10](close))c6010hoej = (indicator2 >= 80)IF c93lav AND c6010hoej and not OnMarket and (Time>$StopLossTime[Lastset($StopLossTime)]+001000 Or Barindex>$StopLossIndex[Lastset($StopLossIndex)]+10) THENBUY 1 SHARES AT MARKETSET STOP pLOSS 4.7SET TARGET pPROFIT 5.8ENDIF// Conditions to exit long positionsEMA200 = ExponentialAverage[200](close)c3 = (EMA200 - 5 >= close)IF c3 THENSELL AT MARKETENDIF//Graph EntryPrice//Graph StopLossPriceGraph $StopLossTime[Barindex]2 users thanked author for this post.
12/01/2025 at 12:46 PM #254123 -
AuthorPosts
Find exclusive trading pro-tools on 