MazParticipant
Veteran
@Wilko yep, that would change the premise of the entire system – it’s a different indicator. We aren’t interested in momentum direction here.
CKWParticipant
Veteran
Hello,
Any of you running this strategy Live / Demo on currencies pair 1H? I have 1H Dow, 1H FTSE in demo but i couldn’t find the good one on 1H currencies..
br,
CKW
Hi, I think there could be some edge on Brent crude for this system but I have very limited history. Maybe there is someone with slightly more data who wants to give it a try?
// ====================================== \\
// :: Optimizations --
// -------------------------------------- //
// Static Optimization for Brent Crude Contract 1 hour
// Jan 2013 - April 2017
// Spread 3 points
reinvest = 0
opti = 2
if opti =1 then
wintarget = 30 // Clip target to maximum of x points (45)
//wintarget = (atr * targetATRmultiple)*pointsize
minTradeTime = 17 // stay in trade for at least x bars
mcShortPeriod = 6 // Short period momentum
rcShortPeriod = 3 // Short period average range
mcLongPeriod = 92 // Long period momentum
rcLongPeriod = 54 // Long period average range
mcThreshold = 0.16 // 0.5 // Momentum coefficient threshold
rcThreshold = 0.41 // 1 // Range coefficient threshold
maShortPeriod = 44 // Short term moving average
maLongPeriod = 25 // Long term moving average
atrPeriod = 14 // preiods for average true range
slATRmultiple = 5 // multiplier for dynamic stop (3)
stoptargettype = 2 // 1= fixed stop, 2=dynamic stop
//targetATRmultiple = 2 //if dynamic target
// Static Optimization for Brent Crude Contract 1 hour
// Jan 2013 - April 2017
// Spread 3 points
elsif opti = 2 then
//wintarget = 30 // Clip target to maximum of x points (45)
wintarget = (atr * targetATRmultiple)*pointsize
targetATRmultiple = 1 //if dynamic target
minTradeTime = 17 // stay in trade for at least x bars
mcShortPeriod = 4 // Short period momentum
rcShortPeriod = 3 // Short period average range
mcLongPeriod = 40 // Long period momentum
rcLongPeriod = 120 // Long period average range
mcThreshold = 0.16 // 0.5 // Momentum coefficient threshold
rcThreshold = 0.41 // 1 // Range coefficient threshold
maShortPeriod = 5 // Short term moving average
maLongPeriod = 15 // Long term moving average
atrPeriod = 14 // preiods for average true range
slATRmultiple = 3 // multiplier for dynamic stop (3)
stoptargettype = 1 // 1= fixed stop, 2=dynamic stop
endif
traidingtime = (currenttime > 060000 and currenttime < 230000)
// ====================================== \\
// :: Position size
// -------------------------------------- //
once startpositionsize=1
once positionsize=startpositionsize
if reinvest = 0 then
positionsize=1
elsif reinvest = 1 then
//------------ Fixed fraction money management ----------
once multiplier=1
once fraction=100*pipvalue
once newlevel=100*pipvalue
once oldlevel=100*pipvalue
once startequity=1000
if strategyprofit+startequity>newlevel then
multiplier=multiplier+1
oldlevel=newlevel
newlevel=strategyprofit+startequity+multiplier*fraction
positionsize=multiplier*startpositionsize
elsif strategyprofit+startequity<oldlevel and multiplier>=2 then
newlevel=strategyprofit+startequity
oldlevel=strategyprofit+startequity-multiplier*fraction
multiplier=multiplier-1
positionsize=multiplier*startpositionsize
endif
endif
// ====================================== \\
// :: Indicators --
// -------------------------------------- //
// Momentum Coefficient and Range Coefficient ============= \\
if barIndex >= max(mcLongPeriod, rcLongPeriod) then
mShort = momentum[mcShortPeriod]
mLong = momentum[mcLongPeriod]
mc = max(0, (abs(mShort) / abs(mLong)) -1)
r = abs(range)
arLong = average[max(1, rcLongPeriod)](r)
arShort = average[max(1, rcShortPeriod)](r)
rc = max(0, (arShort / arLong) -1)
//rc = max(0, arShort - arLong)
endif
// ----------------------------------- //
// General Indicators ================= \\
upBar = close > open
maShort = exponentialAverage[maShortPeriod](Close)
maLong = exponentialAverage[maLongPeriod](Close)
atr = averagetruerange[atrPeriod](Close)
// ----------------------------------- //
// ====================================== \\
// :: Entry Logic
// -------------------------------------- //
// long entry rules (buy condition)
bc1 = not longOnMarket
bc1 = bc1 and (mc >= mcThreshold)
bc1 = bc1 and (rc >= rcThreshold)
bc1 = bc1 and upBar
bc1 = bc1 and maShort > maShort[1]
bc1 = bc1 and traidingtime
// long exit rules (exit long conditions)
le1 = longOnMarket
le1 = le1 and ( barIndex >= barIndexAtBuy + minTradeTime)
le1 = le1 and (maLong < maLong[4])
// ====================================== \\
// :: Execution Handlers
// -------------------------------------- //
if bc1 then
buy positionsize contracts at market
set target pprofit wintarget
barIndexAtBuy = barIndex
endif
if le1 and longOnMarket then
sell at market
endif
if stoptargettype = 1 then
SET STOP pLOSS 95
elsif stoptargettype= 2 then
SET STOP plOSS (atr * slATRmultiple)*pointsize
endif
//trailing stop
trailingstop = 25
//resetting variables when no trades are on market
if not onmarket then
MAXPRICE = 0
priceexit = 0
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
SELL AT priceexit STOP
endif
Hi Victormork, any reason why it trades only on the long side?
Grazie!
Hi! This is the long side only. I’ve not tried to make a short version yet.
LeoParticipant
Veteran
Please correct me if I wrong,
At the begining, when I was learning to code, I test a lot of ideas with a lot of variable to be optimized and nice results. Then I run them in real and I made a lot of losses.
Then I continue reading and practicing until I learn that and over optimization create an strategy that only work in the past…. then the WF tool came to PRT….
…but,
Is it a correct aproach to create a trading System with a lot of variables and of course it will very profitable because is over-optimized in the past but not for the future?
Is it “robustness” inversely proportional to the number of variable in a trading system?
Hi Leo, One suggestion could be to start with a base line. Let say that if close > atr(10)*2 you will go long and exit after 5 bars. If this entry/exit criteria alone produce a positive return then you have a baseline. Let’s say that you try simliar entries on several markets and you find that it works on a few, then you have a kind of robust start. You can then enhance the return slightly with different trend filters etc. but here you need to be careful not to add to many or taking out a lot of trades. With the momentum-range system this indicator which is stated in the code is the base that filters has been added around. If you take out filters from the system you can see what difference they make and maybe judge if it make sense to include or not.