A change in direction of a moving average.
Forums › ProRealTime English forum › ProOrder support › A change in direction of a moving average.
- This topic has 6 replies, 3 voices, and was last updated 8 years ago by camaleo.
-
-
06/27/2016 at 4:38 PM #9912
Hello everyone
First of all, my apologies for my English …
I am trying to write the code of one setup i use manually, trying to Improve it, runnig backtests.
The idea is to identify a change in direction of a moving average.For example,
Exp Moving Average of 9, five days up. The trigger signal is first day pointing down.
1234567891011121314// Conditions to enter long positionsindicator1 = ExponentialAverage[9](close)c1 = (indicator1[1] < indicator1[2])c2 = (indicator1[2] < indicator1[3])c3 = (indicator1[3] < indicator1[4])c4 = (indicator1[4] < indicator1[5])c5 = (indicator1[5] < indicator1[6])c6 = (indicator1 > indicator1[1])c7 = (close > high[1])IF c1 AND c2 AND c3 AND c4 AND c5 AND c6 AND c7 THENBUY 10000 CASH AT MARKETENDIFI wrote the code like this.
Is this correct? It seems to work, but maybe there is a better way…
Any help is welcome.
Thank You
06/28/2016 at 1:01 AM #9931Hello everyone
I Finished first version of my setup. Inspired in the setup of Larry Williams.
The idea is to capture the signal from the direction of change MM9 Exp.
I still do not know if there is another way to encode the change of direction of a moving average. This was the one that occurred to me.
If anybody know other way, please share here.But the code are not working as it should.
We should open the position in the breakout of the high / low after the candle that gives the signal; and not in the opening.Any sugestions? I dont know what is wrong…
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsindicator1 = ExponentialAverage[9](close)c1 = (indicator1[1] < indicator1[2])c2 = (indicator1[2] < indicator1[3])c3 = (indicator1[3] < indicator1[4])c4 = (indicator1[4] < indicator1[5])c5 = (indicator1[5] < indicator1[6])c6 = (indicator1 > indicator1[1])c7 = (close > high[1])IF c1 AND c2 AND c3 AND c4 AND c5 AND c6 AND c7 THENBUY 10000 CASH AT MARKETENDIF// Conditions to exit long positionsc8 = (close CROSSES UNDER indicator1)IF c8 THENSELL AT MARKETENDIF// Conditions to enter short positionsc1 = (indicator1[1] > indicator1[2])c2 = (indicator1[2] > indicator1[3])c3 = (indicator1[3] > indicator1[4])c4 = (indicator1[4] > indicator1[5])c5 = (indicator1[5] > indicator1[6])c6 = (indicator1 < indicator1[1])c7 = (close < Low[1])IF c1 AND c2 AND c3 AND c4 AND c5 AND c6 AND c7 THENSELLSHORT 10000 CASH AT MARKETENDIF// Conditions to exit short positionsc8 = (close CROSSES OVER indicator1)IF c8 THENEXITSHORT AT MARKETENDIF// Stops and targetsSET STOP %LOSS 5Thank you all
06/28/2016 at 7:53 AM #9944Conditions are always tested at a bar close and trade initiated at the open of the next bar. So obviously, your conditions need to be offset +1 somewhere.
About your moving average conditions, you could have made a loop through bars to test them with less code lines, but that’s ok too with the way you done 🙂
06/28/2016 at 4:22 PM #997207/17/2016 at 1:41 AM #1051007/17/2016 at 10:11 AM #10515I see 2 ways to make this test:
1/ first idea is a FOR/NEXT loop in the previous 5 bars:
12345678910111213test=0for i = 1 to 5 doif indicator1[i]>indicator[i+1] thentest = test+1endifnextc6 = (indicator1 < indicator1[1])c7 = (close < Low[1])if test=5 and c6 and c7 thenSELLSHORT 1 SHARE AT MARKETendif2/ second idea is a SUMMATION of the test result over the last 5 periods:
12345678test = SUMMATION[5](indicator1>indicator[1])c6 = (indicator1 < indicator1[1])c7 = (close < Low[1])if test=5 and c6 and c7 thenSELLSHORT 1 SHARE AT MARKETendif07/17/2016 at 11:23 AM #10517Nicolas, thank you for quick answer.
i am very happy and gratefull for your help, because i am learning a lot.
Of course I could not write this loop code, because I am still trying to take the first steps in Prorealcoding.
Now i will do some backtest and try to make this thing work.
I will give some news about it.
I have several good daily setups that would like to code in PRT but the problem is the opening.
Like in this setup, i want to open position in the breakout of the last bar.
-
AuthorPosts
Find exclusive trading pro-tools on