I coded the below indicator provided by @MAZ into a strategy for EURUSD 1Hr
Moving Average Slope
Defparam cumulateorders = False
possize = 1
LMA = Average[200](close)
MA = Average[26](Close)
slope = MA - MA[1]
If slope > 0 then
once GS = slope
AGS = (GS + slope)/2
ga = 0
gb = 0
For a = 0 to 29 Do
If slope[a] > slope[a+1] Then
ga = ga + 1
ElsIf slope[a] < slope[a+1] then
gb = gb + 1
Endif
Next
GS = AGS
ElsIf slope < 0 then
once RS = slope
ARS = (RS + slope)/2
ra = 0
rb = 0
For b = 0 to 29 Do
If slope[b] < slope[b+1] Then
ra = ra + 1
ElsIf slope[b] > slope[b+1] then
rb = rb + 1
endif
Next
RS = ARS
Endif
If countofposition = 0 and close > LMA and slope > (AGS+(AGS*0.618)) Then
Buy possize contract at market
ElsIf countofposition = 0 and close < LMA and slope < (ARS+(ARS*0.618)) Then
Sellshort possize contract at market
EndIf
If longonmarket and (slope < (AGS+(AGS*0.618)) or gb >= ga) Then
Sell at market
ElsIf shortonmarket and (slope > (ARS+(ARS*0.618)) or rb >= ra) Then
Exitshort at market
EndIf
BCParticipant
Master
Thanks for share, will try it tonight.
Hello Juanj
Thanks for sharing.
Could you explain the concept of this ? ( I don’t understand the 0.618 value)
slope > (AGS+(AGS*0.618))
Regards
BCParticipant
Master
0.618 is a important number of Fibonnacci number sequence.
https://en.m.wikipedia.org/wiki/Golden_ratio
Hi
I Know that 0.618 is the golden number and the ratio of infinite convergence of Fibonnaci serie.
it is used in trading for retracement of waves but why is it used in slopes of moving average ?
regards
@Yannick simple answer it works well. I use an optimization algorithm during backtesting that I graph to track optimal values during different points in the backtested period and found that ~0.6 is frequently the optimal value. I then just decided to make it 0.618 for the heck of it.
HI JuanJ,
good work for the code , seems interest
Just a question , Did you test it on 200k bar ?
Thanks
Hi, very interesting post. Can somebody please help with my understanding as I’m new to the site.
In the code above, it includes a For/Next Loop in which the ‘user variable’ slope is incremented through each pass of the loop.
For a = 0 to 29 Do
If slope[a] > slope[a+1] Then
ga = ga + 1
ElsIf slope[a] < slope[a+1] then
gb = gb + 1
Endif
Next
Is this piece of code testing the change in the Moving Average (MA) of each of the last 30 (0 to 29) bars and incrementing ga and gb accordingly?
If so, does it somehow pass the bar reference number (a) to the slope calculation at the start of the code further up (slope = MA – MA[1]) to calculate the step – or have I got this completely wrong?
I appreciate any help to understand this better.
Thanks.
It is used to eventually exit LONG trades at line 43.
Thanks Roberto.
I’m still a little confused with the coding – doesn’t the ‘slope = MA – MA[1]’ need to be nested within the For-Next loops – or does PRC know to look back up the code to find ‘slope’ calculation and recalculate it for each change in [a] and [b] (‘slope [a] > slope[a+1]’) ?
Line 7 is the base to start with. It changes each new candle.
The code later scans the past 30 (0 – 29) MA slopes to accomplish its goal.
slope [a] > slope[a+1]
will be translated, at run time, with:
(MA[a] - MA[a+1]) > (MA[a+1] - MA[a+2])
Thanks Roberto, makes perfect sense.