Hi Maz, yes you are right, it’s in yen. I think it has something to do with the ploss stoploss 70.. I have before experianced that the pipsize or pointvalue has sometimes an odd way in yen- even though it shouldn’t matter. I will take a look later.
Cheers Kasper
First, cheers to all of you who have paid interest in my topic!
And thanks a lot Maz for helping me out with turning my beginner coding into something more functional!! I’ll have a look at the changes made and try to play around with it 🙂
I’m sorry Kasper but I have no clue what could be wrong. Luckily I think you got some suggested from Maz with regards to what might be wrong.
@ Kasper on the new version from Maz you need to change the value on stoplossmode which is currently 2.
stopLossMode = 2 // 1: Static | 2: Dynamic
I got the same result at you first but when I changed to a higher value I got a positiv result.
Correction -> Try the static stop (1) instead of the dynamic
Here are the results with different kind of stops. I couldn’t get any nice result from an ATR stop. I still haven’t tried a time stop.
MazParticipant
Veteran
For the ATR stop try:
SET STOP pLOSS (atr * slATRmultiple) * pointSize
??
SET STOP pLOSS (atr * slATRmultiple) /pointsize
Now it works 🙂
This is the updated version for EURUSD 5M
Defparam Cumulateorders = false
Defparam Preloadbars = 300
//------ Trading hours-------
Starttime = 100000
Endtime = 240000
fridayEndTime = 225000
// --------Indicators------
blow = Bollingerdown[20]
bhigh = Bollingerup[20]
MA1 = Average[8]
MA2 = Average[200]
ad = adx[24]
adlevel = 14
atr = averageTrueRange[40]
slATRmultiple = 5
targetATRmultiple = 3
stopLossMode = 1 // 1: Static | 2: Dynamic | 3: DONCHIAN STOP
DC = 20
strailing = 1 // 0=off 1=on
strailingstart = 20
isLateFriday = (dayOfWeek = 5 and time >= fridayEndTime)
// ------ ENTRY CONDITIONS LONG-----
cb1 = (low < blow and close < blow)
cb2 = (MA1 > MA2)
cb3 = (currenttime > Starttime and currenttime < Endtime)
cb4 = (ad > adlevel)
c5 = cb1 and cb2 and cb3 and cb4
IF NOT Longonmarket and c5 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// ------ EXIT CONDITIONS LONG-----
cb9 = LONGONMARKET AND ((close > bhigh) OR isLateFriday)
IF cb9 Then
sell at market
endif
// ------ ENTRY CONDITIONS SHORT-----
cs1 = (high > bhigh and close > bhigh)
cs2 = (MA1 < MA2)
cs3 = (currenttime > Starttime and currenttime < Endtime)
cs4 = (ad > adlevel)
cs6 = cs1 and cs2 and cs3 and cs4
IF NOT Shortonmarket and cs6 THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
// ------ ENTRY CONDITIONS SHORT----
cs9 = SHORTONMARKET AND ((close < blow) OR isLateFriday)
IF cs9 Then
Exitshort at market
endif
//------ STOP AND TARGETS -----------
if stopLossMode = 1 then
SET STOP pLOSS 65
//SET TARGET pPROFIT 30
elsif stopLossMode = 2 then
SET STOP pLOSS (atr * slATRmultiple)/pointsize
SET TARGET pPROFIT (atr * targetATRmultiple)/pointsize
elsif stopLossMode = 3 then
e= Highest[DC](high)
f=Lowest[DC](low)
if longonmarket then
laststop = f[1]
endif
if shortonmarket then
laststop = e[1]
endif
if onmarket then
sell at laststop stop
exitshort at laststop stop
endif
endif
if strailing = 1 then
//trailing stop
trailingstop = strailingstart
//resetting variables when no trades are on market
if not onmarket then
MAXPRICE = 0
MINPRICE = close
priceexit = 0
endif
//case SHORT order
if shortonmarket then
MINPRICE = MIN(MINPRICE,close) //saving the MFE of the current trade
if tradeprice(1)-MINPRICE>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price level
endif
endif
//case LONG order
if longonmarket then
MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade
if MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE - trailing stop price level
endif
endif
//exit on trailing stop price levels
if onmarket and priceexit>0 then
EXITSHORT AT priceexit STOP
SELL AT priceexit STOP
endif
endif
MazParticipant
Veteran
Cool. Just a thought – have you tried using combinations stop modes together? For example rather than selection stop mode 1, 2 or 3; being able to switch 1, 2 and 3 on and off separately?
Very useful Maz the timezone offset variable
It may be less confusing for everyone if the timezone offset variable is labelled and set at the World Universal Time which is called UTC. (UK is not at GMT in the Summer, but is at BST or GMT+1).
UTC overcomes confusion as it is the accepted World Standard … a Universal Time Clock.
UK is UTC+1
Kasper is UTC+2
Just a suggestion for improvement, but credit goes to you Maz for a great idea … hope others follow your lead.
GraHal
MazParticipant
Veteran
Good point @GraHal. A shared UTC offset snippet that can be plugged into anyone’s code would be useful.
sorry guys but I skipped adding the time zon for EURUSD but it’s more or less a copy past form the USDJPY.
@Maz – do you mean for example having a fixed target combined with an dynamic stop? That I’ve not yet tried.
MazParticipant
Veteran
Yes, that’s what I was referring to.
Thanks for the idea Maz.
I tried the ATR based target to the trailing stop function which showed the best result and it did improve the return. I also tried the an ATR based starting point for the trailing stop but it left the return, win-rate etc unchanged. I’ve attached the latest code.
I tired to make a small monte carlo on the long side for USDJPY and the result looks like attached file.