Heikin Ashi Long/Short after correction
Forums › ProRealTime English forum › ProScreener support › Heikin Ashi Long/Short after correction
- This topic has 7 replies, 3 voices, and was last updated 2 years ago by robertogozzi.
-
-
08/08/2022 at 7:50 AM #198722
Hi all,
Need some help here!
It would be nice if the Heikin-Ashi-Long-Setup-Correction ( https://www.prorealcode.com/prorealtime-market-screeners/heikin-ashi-long-setup-correction/) by Odin could also scan potentials for short opportunities in a bear market.
Recently I tried to get this to code but………. without result, the screener does not work at all (The ‘long’ part in the screener is also not working, while seperately it does). I included the code below.
Could someone please check for me for the errors in the added code and why the long part is not working anymore?
Thank you for helping me out ……………….
Best regards,
Marcel van Vliet
Heikin Ashi Long/Short After Correction1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162// Heikin Ashi Long or Short after correction// Original by Odin// Short parameters by Marcel van Vliet// 08/08/2020MinPrice=10 // The minimum price of each security.MaxPrice=1000 // The maximum price of each security.DailyVolume = volume>1000000//Longc1 = Average[8](close) > Average[21](close)c2 = Average[21](close)> Average[50](close)n = 0if barindex = 0 thenhaOpen = openhaClose = closeelsif N = 0 thenhaClose =(Open+High+Low+Close)/4haOpen =(haOpen[1]+haClose[1])/2elsif (barindex MOD N) = 0 thenhaClose =(Open[N]+Highest[N](high)+Lowest[N](low)+Close)/4haOpen =(haOpen[1]+haClose[1])/2endifc3 = haclose > haopenc4 = haclose[1] < haopen[1]c5 = haclose[2] < haopen[2]c6 = haclose[3] < haopen[3]ResultLong= c1 and c2 and c3 and c4 and c5 and c6//Shortc7 = Average[8](close) < Average[21](close)c8 = Average[21](close)< Average[50](close)n = 0if barindex = 0 thenhaOpen = openhaClose = closeelsif N = 0 thenhaClose =(Open+High+Low+Close)/4haOpen =(haOpen[1]+haClose[1])/2elsif (barindex MOD N) = 0 thenhaClose =(Open[N]+Highest[N](high)-Lowest[N](low)+Close)/4haOpen =(haOpen[1]+haClose[1])/2endifc9 = haclose < haopenc10 = haclose[1] > haopen[1]c11 = haclose[2] > haopen[2]c12 = haclose[3] > haopen[3]ResultShort= c7 and c8 and c9 and c10 and c11 and c12SCREENER[ResultLong and ResultShort and DailyVolume and haopen>MinPrice and haclose<MaxPrice](volume*close as "traded volume")08/08/2022 at 9:51 AM #198730Firstly you should not dulicate variables and instructions that are common to both directions, so you should remove lines 40-53.
Secondly, you can’t use AND (last line) with the first two conditions, as they cannot be met simultaneously, use OR instead:
1SCREENER[(ResultLong OR ResultShort) and DailyVolume and haopen>MinPrice and haclose<MaxPrice](volume*close as "traded volume")Moreover, your filters in lines 6-8 seem quite strict; setting them to 1, 1000 and 10000 returned over 20 results (with ALL list selected).
1 user thanked author for this post.
08/08/2022 at 5:55 PM #198765Thank you #robertogozzi,
So far so good, a little stupid of me to overlook the ‘or’ mistake.
I have removed the lines you suggested, but the screener does still not work as wanted. How to change the rules 40-53 into a short code, if I copy/paste them back?
Do I have to adjust the second ‘elsif’ part or the whole line 40-53 section?
The lines 6-8 are part of the strategy were I use the screener for, so more results is not what I am looking for.
The haopen and low should be equal for the long ‘trigger’ candles and the haopen and high should be equal for the short ‘trigger’ candles. How to write the code for this?
I hope you will help me further with this screener.
I will add it to the library as soon it works wel and it is tested.
Best regards,
Marcel van Vliet
08/09/2022 at 8:07 AM #198786Lines 40-53 do not affect the direction, in any case you should use different names other then those in lines 14-27.
It may depend on the last line. I think it should be:
1SCREENER[(ResultLong or ResultShort) and DailyVolume and haclose>MinPrice and haclose<MaxPrice](volume*close as "traded volume")as the price is usually identified by the CLOSING price.
I can’t figure out what line 51 is all about. When N=0 it’s not used, otherwise it is executed only every N candles, which is what I don’t understand. In any case line 51 should be the same for both Long and Short trades.
The author might be of help.
08/09/2022 at 12:58 PM #198812Hi…
It appears, the 2nd ‘ELSE’ statement is only executed when, manually set, ‘N’ > 0, and it’s corresponding condition is true. It calculates ‘haClose’ and ‘haOpen’ from, and over an ‘N’ number of bars. It’s updates, are delayed till the true condition. This looks similar to a candle on a higher timeframe which updates on it’s close and not the default timeframes close. Also because of the ‘closed’ candles, the thresholds, hold position for ‘N’ periods.
That’s my understanding, however it doesn’t answer why!
This appears to work with all of Roberto’s comments incorporated. Reducing the ‘DailyVolume’ and what chosen ‘period’ give more results.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162// Heikin Ashi Long or Short after correction// Original by Odin// Short parameters by Marcel van Vliet// 08/08/2020//----------------------------------------------------- price and volume thresholdsMinPrice=10 // The minimum price of each security.MaxPrice=1000 // The maximum price of each security.DailyVolume = volume>1000000//----------------------------------------------------- set up haOpen and haCloseN = 0 // set a calculation range, 'n' over a number of candles.if barindex = 0 thenhaOpen = openhaClose = closeelsif N = 0 thenhaClose =(Open+High+Low+Close)/4haOpen =(haOpen[1]+haClose[1])/2elsif (barindex MOD N) = 0 thenhaClose =(Open[N]+Highest[N](high)+Lowest[N](low)+Close)/4haOpen =(haOpen[1]+haClose[1])/2endif//----------------------------------------------------- long conditions/result//Longc1 = Average[8](close) > Average[21](close)c2 = Average[21](close)> Average[50](close)c3 = haclose > haopenc4 = haclose[1] < haopen[1]c5 = haclose[2] < haopen[2]c6 = haclose[3] < haopen[3]ResultLong= c1 and c2 and c3 and c4 and c5 and c6//----------------------------------------------------- short conditions/result//Shortc7 = Average[8](close) < Average[21](close)c8 = Average[21](close)< Average[50](close)c9 = haclose < haopenc10 = haclose[1] > haopen[1]c11 = haclose[2] > haopen[2]c12 = haclose[3] > haopen[3]ResultShort= c7 and c8 and c9 and c10 and c11 and c12//----------------------------------------------------- output variable listp0 = volume*closep1 = DailyVolumep2 = haopen>MinPricep3 = haclose<MaxPricep20 = ResultLongp21 = ResultShortSCREENER[ (p20 or p21) and p1 and p2 and p3 ]( p0 as "Traded Volume")08/09/2022 at 4:48 PM #198828Dear #robertogozzi and #druby,
Thanks a lot for your efforts. As simple as it seemed in the first place to add a short section to a long only screener it still does not work.
I guess I strip the whole screener down and rebuild it up from scratch with code lines even I understand. 🙂
I will share my attempt here and I hope you will give it a view with a critical eye.
Best Regards,
Marcel van Vliet
08/09/2022 at 6:03 PM #198834hi marcel…
When you say it doesn’t work, what do you mean. When I tried the corrected code, initial I had to set ‘DailyVolume = volume>10′ in code, and it still didn’t give results till I set the period to ‘Daily’ and made sure there were entries in the list I was running the screener on.
In the image I’ve added line 52 and commented out line 53, this displays whether the results found are from the long ‘1’or short ‘0’ result logic.
If its giving you results that you deem wrong, then that another problem all together.
If its the former, then I would assume that the problem lies somewhere else.
As a rule of thumb, I’ve found with coding with the ‘Probuilder’ and ‘PRT’ is:
If you have a problem, don’t assume it’s only one, there could be several, but at the time you don’t know that. And when you find a solution, don’t assume it solves all of the those problems.
Programming or back engineering you own is the best way. You’ll have a better understanding on the code and what its doing. That makes it easier to identify when wrong results are presented. We’ll, at least gives you a better chance.
All the best.
08/10/2022 at 1:57 AM #198842My correct example in post https://www.prorealcode.com/topic/heikin-ashi-long-short-after-correction/#post-198786 was changed to:
1SCREENER[(ResultLong or ResultShort) and DailyVolume and haclose>MinPrice and haclose<MaxPrice](volume*close as "traded volume") -
AuthorPosts
Find exclusive trading pro-tools on