Moving Average Slope 1Hr Strategy
Forums › ProRealTime English forum › ProOrder support › Moving Average Slope 1Hr Strategy
- This topic has 11 replies, 6 voices, and was last updated 5 years ago by nfulcher.
-
-
10/26/2017 at 9:13 PM #50649
I coded the below indicator provided by @MAZ into a strategy for EURUSD 1Hr
https://www.prorealcode.com/prorealtime-indicators/moving-average-slope/
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647Defparam cumulateorders = Falsepossize = 1LMA = Average[200](close)MA = Average[26](Close)slope = MA - MA[1]If slope > 0 thenonce GS = slopeAGS = (GS + slope)/2ga = 0gb = 0For a = 0 to 29 DoIf slope[a] > slope[a+1] Thenga = ga + 1ElsIf slope[a] < slope[a+1] thengb = gb + 1EndifNextGS = AGSElsIf slope < 0 thenonce RS = slopeARS = (RS + slope)/2ra = 0rb = 0For b = 0 to 29 DoIf slope[b] < slope[b+1] Thenra = ra + 1ElsIf slope[b] > slope[b+1] thenrb = rb + 1endifNextRS = ARSEndifIf countofposition = 0 and close > LMA and slope > (AGS+(AGS*0.618)) ThenBuy possize contract at marketElsIf countofposition = 0 and close < LMA and slope < (ARS+(ARS*0.618)) ThenSellshort possize contract at marketEndIfIf longonmarket and (slope < (AGS+(AGS*0.618)) or gb >= ga) ThenSell at marketElsIf shortonmarket and (slope > (ARS+(ARS*0.618)) or rb >= ra) ThenExitshort at marketEndIf10/27/2017 at 12:56 AM #5065911/06/2017 at 9:06 PM #5173611/07/2017 at 12:22 AM #517510.618 is a important number of Fibonnacci number sequence.
https://en.m.wikipedia.org/wiki/Golden_ratio
11/07/2017 at 6:29 AM #5175611/07/2017 at 8:21 AM #51761@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.
11/08/2017 at 4:16 PM #5197608/15/2019 at 2:52 PM #104800Hi, 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.
1234567For a = 0 to 29 DoIf slope[a] > slope[a+1] Thenga = ga + 1ElsIf slope[a] < slope[a+1] thengb = gb + 1EndifNextIs 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.
08/15/2019 at 3:03 PM #104801It is used to eventually exit LONG trades at line 43.
1 user thanked author for this post.
08/15/2019 at 3:23 PM #104808Thanks 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]’) ?
08/15/2019 at 3:38 PM #104813Line 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.
1slope [a] > slope[a+1]will be translated, at run time, with:
1(MA[a] - MA[a+1]) > (MA[a+1] - MA[a+2])08/15/2019 at 5:32 PM #104815 -
AuthorPosts
Find exclusive trading pro-tools on