Hello all, I stumbled upon this more or less by accident and can’t understand why it seems that it ‘might’ actually work.
It enters long when a) the slow MA is above the fast MA (normally short conditions) and b) when the slow MA changes direction. How is this possible? By the time a slow MA can change direction surely it would be below the fast MA?
Attached are backtests for 4min and 3min versions, both of which appear to be profitable over the past year. Position size = €1
If anyone could enlighten me as to what is going on here, I’d be most grateful.
// Definition of code parameters
DEFPARAM CumulateOrders = false // Cumulating positions deactivated
DEFPARAM preloadbars = 5000
//Money Management NAS
MM = 0 // = 0 for optimization
if MM = 0 then
positionsize=1
ENDIF
if MM = 1 then
ONCE startpositionsize = 1
ONCE factor = 10 // factor of 10 means margin will increase/decrease @ 10% of strategy profit; factor 20 = 5% etc
ONCE margin = (close*.005) // tier 1 margin value of 1 contract in instrument currency; change decimal according to available leverage
ONCE margin2 = (close*.01)// tier 2 margin value of 1 contract in instrument currency; change decimal according to available leverage
ONCE tier1 = 200 // IG first tier margin limit
ONCE maxpositionsize = 2000 // IG tier 2 margin limit
ONCE minpositionsize = 1 // enter minimum position allowed
IF Not OnMarket THEN
positionsize = startpositionsize + Strategyprofit/(factor*margin)
ENDIF
IF Not OnMarket THEN
IF startpositionsize + Strategyprofit/(factor*margin) > tier1 then
positionsize = (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor*margin2)) + tier1 //incorporating tier 2 margin
ENDIF
IF Not OnMarket THEN
if startpositionsize + Strategyprofit/(factor*margin) < minpositionsize THEN
positionsize = minpositionsize //keeps positionsize from going below allowed minimum
ENDIF
IF (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor*margin2)) + tier1 > maxpositionsize then
positionsize = maxpositionsize// keeps positionsize from going above IG tier 2 margin limit
ENDIF
ENDIF
ENDIF
ENDIF
Ctime = time >=080000 and time <210000
TIMEFRAME(default)
Period= 5
inner = 2*weightedaverage[round( Period/2)](typicalprice)-weightedaverage[Period](typicalprice)
HULLa = weightedaverage[round(sqrt(Period))](inner)
Periodb= 24
innerb = 2*weightedaverage[round( Periodb/2)](typicalprice)-weightedaverage[Periodb](typicalprice)
HULLb = weightedaverage[round(sqrt(Periodb))](innerb)
Periodc= 90
innerc = 2*weightedaverage[round( Periodc/2)](typicalprice)-weightedaverage[Periodc](typicalprice)
HULLc = weightedaverage[round(sqrt(Periodc))](innerc)
c1 = HULLb > HULLa
c2 = HULLb < HULLa
c3 = HULLb > HULLb[1]and HULLb[1]<HULLb[2]
c4 = HULLb < HULLb[1]and HULLb[1]>HULLb[2]
c5 = HULLc > HULLc[1]
c6 = HULLc < HULLc[1]
// Conditions to enter long positions
IF Ctime and c1 AND C3 AND C5 THEN
BUY positionsize CONTRACT AT MARKET
ENDIF
// Conditions to enter short positions
IF Ctime and c2 AND C4 AND C6 THEN
SELLSHORT positionsize CONTRACT AT MARKET
ENDIF
//SET STOP %LOSS sl
//SET TARGET %PROFIT tp
It’s because of conditions C3 and C4, both form a reversal peak while the lowest average, C5 and C6, is also going the reversed way.
Sorry Roberto, I still don’t get it.
c5 means the MA90 is rising – this is unproblematic. c3 means the MA24 has reversed from falling to rising, this also makes sense.
But how can that happen when it is also above the MA5 ? By the time MA24 reverses, the MA5 is surely going to be above it ???
Use this indicator:
Period= 5
inner = 2*weightedaverage[round( Period/2)](typicalprice)-weightedaverage[Period](typicalprice)
HULLa = weightedaverage[round(sqrt(Period))](inner)
Periodb= 24
innerb = 2*weightedaverage[round( Periodb/2)](typicalprice)-weightedaverage[Periodb](typicalprice)
HULLb = weightedaverage[round(sqrt(Periodb))](innerb)
Periodc= 90
innerc = 2*weightedaverage[round( Periodc/2)](typicalprice)-weightedaverage[Periodc](typicalprice)
HULLc = weightedaverage[round(sqrt(Periodc))](innerc)
c1 = HULLb > HULLa
c2 = HULLb < HULLa
c3 = HULLb > HULLb[1]and HULLb[1]<HULLb[2]
c4 = HULLb < HULLb[1]and HULLb[1]>HULLb[2]
c5 = HULLc > HULLc[1]
c6 = HULLc < HULLc[1]
// Conditions to enter long positions
cLong = c1 AND C3 AND C5
cShort = c2 AND C4 AND C6
IF cLong THEN
DRAWARROWUP(barindex,low - range*3) coloured(0,255,0,255)
ELSIF cShort THEN
DRAWARROWDOWN(barindex,high + range*3) coloured(255,0,0,255)
ENDIF
//
RETURN Hulla AS "Ha", Hullb AS "Hb", Hullc AS "Hc"
the attached pic shows that:
- HullB (blue) has formed a (almost invisible) peak – C3
- HullB (blue) > HullA (red) – C1
- HullC (purple) > previous HullC (purple) – C5
thanked this post
Thanks for that Roberto, so at least its not impossible for those conditions to occur.
Still very odd that it should give a decent result. If I remove HULLa (MA5) completely, with just the rising MA90 and the MA24 reversal the results are much worse. I don’t see why the HULLa should improve anything, but there it is.
Because (Long example) C is ascending, B is reversing from descending so it’s now ascending, thus the idea is that the faster A, temporarily behind, will soon cross over B.
Yes, short term weakness, medium and long term uptrend, so you buy the dip to enter the medium and long term uptrend (good entry point)
Thank you for stumbling across this Nonetheless.
I get more or less same as you on 4 min, but wildly different on 3 min … weird, why should that be??
Thank you for stumbling across this Nonetheless.
I get more or less same as you on 4 min, but wildly different on 3 min … weird, why should that be??
For the 3min version, I have Periodb = 27, all other values are the same. Interesting that, as far as i can see, the 4min and 3min pick up completely different trades, so could be run in tandem.
There is another problem though; the MM doesn’t seem to do anything. This is weird because it’s just an add-on block of code that I’ve been using for ages, but here it makes no difference if MM=1 or 0 … could you test it to see if you get the same?
Hello, as I can see the MM will not step up because that the strategy is always in market (Over 99%). No stop, no target, no sell and no takeprofit.
Yes, that’s true, but positions are still closed and reopened… how long does it realistically take to calculate strategy profit and position size? Should be a matter of milliseconds. If the time on market is anything less than 100% there should be time for the MM to activate at some point.
Any use of stops or targets results in worse performance.
“If the time on market is anything less than 100% there should be time for the MM to activate at some point.”
I was thinking that the other 1 or 2 % had to do with the time before the strategy took the first trade. I have no idea as I am a beginner on this.
Can @Nicolas or someone else tell us how Prorealtime internals works when the strategy is doing like this eg. when there is no stop nor any target in the code and the trade reverses by the strategy?
Does Prorealtime send a command to the broker IG to “reverse” the trade or is there two commands sent? (sell/short vs exitshort(sell)/buy depending on direction)?
The only commands sent to the broker are those the author coded within the strategy.
In this strategy there are two, BUY and SELLSHORT.
Whenever one of the two is executed the position is automatically reversed since there cannot be two opposite positions open within the same strategy.
Reversing implies first closing the open position, then opening a new one the opposite direction. There’s no need to use SELL/EXITSHORT to stay 100% of time on the market.
The author commented the las two lines to avoid being on market less than 100% of time.
time before the strategy took the first trade
I think this may be the case?
I have never had an always on strategy to be on market 100% of the time and often wondered where the < 1% or 2% ish went to?
I have no idea as I am a beginner on this.
Seems you do have good ideas, keep them coming!
It’s good to have new blood in the Community! 🙂
@robertogozzi thanks! That’s almost what I suspected. Does this mean that there is no chance for ProRealTime to run the “Not OnMarket” code in this strategy and that the specific part of the MM code will not run?
GraHal thanks. I will do my very best 😉
Excellent Community you have here. Everyone, thanks for sharing. Thumbs up to you all 😀