How to define only the first correction after the start of a new trend
Forums › ProRealTime English forum › ProScreener support › How to define only the first correction after the start of a new trend
- This topic has 12 replies, 3 voices, and was last updated 3 years ago by robertogozzi.
-
-
03/21/2021 at 12:03 PM #164796
How to define the exclusive output of the first correction after the start of a new trend?
Dear all!
Unfortunately I am still quite inexperienced and I have no idea how to solve this. I am asking for the output of the first correction after the start of a new trend in the screener.
Trend is defined as EMA 100 > EMA 200, as well as momentum higher timeframe. (that is clear)
Correction is to be defined by a negative histogram for uptrends or vice versa.I want to avoid the output of further corrections in the trend, only the first correction should be relevant. I hope someone can possibly solve this. Many thanks in advance.
03/21/2021 at 12:48 PM #164799I tested it and it seems to work as expected:
123456789101112131415161718192021IF BarIndex <= 1 THENCrossOver = 0Flag = 0ENDIFEma100 = average[100,1](close)Ema200 = average[200,1](close)MyMACD = MACD[12,26,9](close)IF Ema100 CROSSES OVER Ema200 THENCrossOver = 1Flag = 0ELSIF Ema100 CROSSES UNDER Ema200 THENCrossOver = 0Flag = 0ENDIFMacdCross = MyMacd CROSSES UNDER 0IF Flag THENMacdCross = 0ELSIF CrossOver AND MacdCross THENFlag = 1ENDIFSCREENER[MacdCross]1 user thanked author for this post.
03/21/2021 at 1:30 PM #164802wow, that was really fast, thanks a lot! But as far as I can see I’m not getting the results I want, I only changed the code slightly because I am using a very slow macd (30/60/25). e.g. usdhuf, tf 1 hour, is returned as hit, but there is already the 4th correction (macd negative). But anyway I got an idea how I can fix this. Thanks a lot
I used
123456789101112131415161718192021IF BarIndex <= 1 THENCrossOver = 0Flag = 0ENDIFEma100 = average[100,1](close[1])Ema200 = average[200,1](close[1])MyMACD = MACD[30,60,25](close[1])IF Ema100 CROSSES OVER Ema200 THENCrossOver = 1Flag = 0ELSIF Ema100 CROSSES UNDER Ema200 THENCrossOver = 0Flag = 0ENDIFMacdCross = MyMacd CROSSES UNDER 0IF Flag THENMacdCross = 0ELSIF CrossOver AND MacdCross THENFlag = 1ENDIFSCREENER[MacdCross]03/21/2021 at 4:16 PM #164811I think i have to add a count so that the flags / histogram are counted while the trend is still present and an output only occurs when count = 1.
09/20/2021 at 1:42 PM #177977Hi guys, I haven’t dealt with this question for a while and would now like to try to get an answer. The above code does not give the desired results in the screener. The question would be the first correction defined as a MACD cross after the start of a trend, e.g. by an EMA cross. Unfortunately, my knowledge is not sufficient for this. Maybe someone has an idea.
09/20/2021 at 3:04 PM #177979Hello,
Indeed you may need a count. Though the code of @robertogozzi looks good, I would try something like this (not tested):alternative proposal12345678910111213141516171819IF BarIndex <= 1 THENCrossOver = 0Flag = 0ENDIFEma100 = average[100,1](close)Ema200 = average[200,1](close)MyMACD = MACD[12,26,9](close)IF Ema100 CROSSES OVER Ema200 THENCrossOver = 1Flag = 0ELSIF Ema100 CROSSES UNDER Ema200 THENCrossOver = 0Flag = 0ENDIFMacdCross = MyMacd CROSSES UNDER 0IF CrossOver AND MacdCross THENFlag = Flag+1ENDIFSCREENER[Flag=1]09/20/2021 at 3:17 PM #177980Line 5 to line 17 makes perfect sense to me, but I don’t understand counting events logically.
The suggested code unfortunately does not work and gives no results. It seems that the counting does not work.
Thanks nevertheless!09/21/2021 at 6:09 AM #178008Hello,
To better know how the code works, you may start to develop an indicator to put on price that will show your signals. Then you will be able to screen more confidently I believe.Example of indicator123456789101112131415161718192021IF BarIndex <= 1 THENCrossOver = 0Flag = 0ENDIFEma100 = average[100,1](close)Ema200 = average[200,1](close)MyMACD = MACD[12,26,9](close)IF Ema100 CROSSES OVER Ema200 THENCrossOver = 1Flag = 0ELSIF Ema100 CROSSES UNDER Ema200 THENCrossOver = 0Flag = 0ENDIFMacdCross = MyMacd CROSSES UNDER 0IF CrossOver AND MacdCross THENFlag = Flag+1DRAWARROWUP(barindex,low-1*AverageTrueRange[14])coloured(204,0,0)DRAWTEXT("N#Flag#",barindex,low-1.5*AverageTrueRange[14],SansSerif,Bold,11)coloured(0,0,0)ENDIFRETURNPS: The screener may be SCREENER[CrossOver and MacdCross and Flag=1]
09/21/2021 at 7:09 AM #178012My code is working as expected, with any MACD setting you choose, as from my pic.
Try increasing the units on your chart, an Ema200 will require many more bars than its periods to be correctly calculated. Use at least 1K bars.
09/21/2021 at 8:15 AM #178026I’m sorry, but I don’t think that’s the case.
Attached is the screener, as well as the results in 4 hours.
As an example USDCAD – it gives me every single correction, but only the very first is asked for.09/21/2021 at 8:20 AM #178032Yes, you asked for the very first one in your first post “I am asking for the output of the first correction after the start of a new trend in the screener“.
09/21/2021 at 8:33 AM #178037Yes, indeed, and can write a code for a screener that gives me any correction, but I am not able to filter only the first correction after the start of a new trend – that is what I want to learn
09/21/2021 at 8:59 AM #178047This one will allow you to detect a) the first correction only or b) all corrections:
123456789101112131415161718192021222324IF BarIndex <= 1 THENCrossOver = 0Flag = 0FirstOnly = 1 //1=detect ONLY the first correction, 0=detect ALL correctionsENDIFEma100 = average[100,1](close)Ema200 = average[200,1](close)MyMACD = MACD[30,60,25](close)IF Ema100 CROSSES OVER Ema200 THENCrossOver = 1Flag = 0ELSIF Ema100 CROSSES UNDER Ema200 THENCrossOver = 0Flag = 0ENDIFMacdCross = MyMacd CROSSES UNDER 0IF Flag THENMacdCross = 0ELSIF CrossOver AND MacdCross THENIF FirstOnly THENFlag = 1ENDIFENDIFSCREENER[MacdCross]simply change 1 to 0 in line 4 to detect ALL corrections.
-
AuthorPosts