Forums › ProRealTime English forum › ProOrder support › first hit of a moving average › Reply To: first hit of a moving average
I modified the above code to the below – difference is the trade should get taken on first hit of the 50MA (rather than the 20MA). But there is another condition and that is when prices do hit the 50MA, the next bar’s high must be greater than the 50MA to take the trade. I can’t quite get it to work though based on the results I have attached. The entry gets taken even when the next bar’s high isn’t greater than the 50MA (in dark blue). Yellow = 200 and light blue = 20. Any idea’s what I am doing wrong? I have brushed up on my coding since last time and can now actually read what’s going on sort of 🙂 … Sorry I tried to entry the code into the correct window, but this is what I got below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
starttime = 000000 startday = 1 gapneeded = 20 * pipsize ma20 = average[20](close) ma50 = average[50](close) ma200 = average[200](close) magap = ma20 - ma200 if (opentime = starttime and opendayofweek = startday) or onmarket then crossflag = 0 gapflag = 0 endif if ma20 crosses over ma200 then crossflag = 1 endif if crossflag and magap > gapneeded and Dhigh(0) >= ma50 then gapflag = 1 endif if ma20 crosses under ma200 then crossflag = 0 gapflag = 0 endif if not onmarket and crossflag and gapflag then buy at ma50 limit endif SET STOP pLOSS 25 SET TARGET pPROFIT 25 |