Hi
I want to avoid a new entry if last trade triggered a stop loss and it happened less than 10 minuttes ago.
How can I program that?
It depend on which time frame the code is running and if you have several ways of exiting a running trade… (if there is no instruction to get that exact time)
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.8
Here you have an example to control exit:
// ===========================
// Example: NO entry before x minutes after loss
// ===========================
// ----- General settings
DEFPARAM CumulateOrders = false
x = 10
once exitTypeSL=0
// ----- Setup Long (example)
atr = averagetruerange[14](close)
sma5 = average[5](close)
sma60 = average[60](close)
setupLong = sma5 crosses over sma60
if not onmarket and setupLong and ((bars > x and exitTypeSL) or exitTypeSL=0) then
SL=close-2*atr
TP=close+3*atr
buy 1 contract at market
set stop price SL
set target price TP
endif
if not onmarket and onmarket[1] then
if strategyprofit>strategyprofit[1] then
exitTypeSL=0
bars=0
else
exitTypeSL=1
bars=1
endif
elsif not onmarket and exitTypeSL then
bars=bars+1
elsif onmarket then
bars=0
endif
// ===========================
// 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")
At 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…
array variables availability in ProRealTime – examples and discussions
Timeframe(1 minutes)
//Store Buy Time
Once HalfSpread = 1
Once $StopLossTime[0]=Time
Once $StopLossIndex[0]=Barindex
Once $EntryPriceIndex[0]=Barindex
if Longtriggered then //and Lastset($EntryPriceIndex)<Barindex then
//$EntryPrice[Barindex]=Open+HalfSpread
EntryPrice = Open + HalfSpread
StopLossPrice = EntryPrice - 4.7
Endif
if (longtriggered or OnMarket[1]) and Close<=StopLossPrice and Lastset($StopLossIndex)<barindex then
$StopLossTime[Barindex]=Time
$StopLossIndex[Barindex]=Barindex
endif
// Conditions to enter long positions
indicator1 = 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) THEN
BUY 1 SHARES AT MARKET
SET STOP pLOSS 4.7
SET TARGET pPROFIT 5.8
ENDIF
// Conditions to exit long positions
EMA200 = ExponentialAverage[200](close)
c3 = (EMA200 - 5 >= close)
IF c3 THEN
SELL AT MARKET
ENDIF
//Graph EntryPrice
//Graph StopLossPrice
Graph $StopLossTime[Barindex]
JSParticipant
Veteran
@LucasBest
In ProBuilder, the code is triggered on every tick, whereas in ProBackTest the code is only triggered on the close…