Forex Factory (https://www.forexfactory.com/forum.php)
-   Platform Tech (https://www.forexfactory.com/forumdisplay.php?f=69)
-   -   How to add moving average criteria to pattern indicator? (https://www.forexfactory.com/showthread.php?t=458962)

ReyesWhite Nov 23, 2013 11:25am | Post# 1

How to add moving average criteria to pattern indicator?
 
2 Attachment(s)
I like this common pattern indicator but i only want it to show bearish patterns above a 20 SMA and bullish patterns below the 20 SMA. What line of code would i need to add to the script to make this work? i'm a newbie with coding

Pattern_Recognition_Master_v3.mq4

Here is how i'd want it to look for those wanting a better understanding.

Click to Enlarge

Name: filter1.png
Size: 20 KB

fxdaytrader_ Nov 23, 2013 11:29am | Post# 2

you have to post the .MQ4 file because the .ex4 is not editable ...

edit: you can find the mq4 at http://www.forexfactory.com/showthre...82#post4691982

I think it should possible to implement the ma-filter. I will have a look to it later ...

FerruFx Nov 23, 2013 11:30am | Post# 3

I like this common pattern indicator but i only want it to show bearish patterns above a 20 SMA and bullish patterns below the 20 SMA. What line of code would i need to add to the script to make this work? i'm a newbie with coding {file}
You can't add nothing in this file.

FerruFx Nov 23, 2013 11:31am | Post# 4

you have to post the .MQ4 file because the .ex4 is not editable ...
Quicker than me !

ReyesWhite Nov 23, 2013 11:35am | Post# 5

1 Attachment(s)
Here it is -

Pattern_Recognition_Master_v3.mq4

fxdaytrader_ Nov 23, 2013 12:41pm | Post# 6

2 Attachment(s)
I like this common pattern indicator but i only want it to show bearish patterns above a 20 SMA and bullish patterns below the 20 SMA.
ok, here we go, just an attempt

At first I extended the alert-functions (the usual stuff, Popup was already there, but I renamed the variable, then added sound(bullish/bearish), email and push-notification).

And the moving-average filter. Please note that the filter is optional, you have to enable it by setting UseMAfilter=true (yes, you can change the ema-settings like period, etc.)

If enabled you have to specify the MAFilterMode. If it is =0 then for a signal the price has to be below MA for bullish/over MA for bearish signals.
If =1 then price must be over MA for bullish/below MA for bearish signals.

I attached one screenshot with the filter enabled (mode=0), for me that looks fine. But please test and check if everything is ok ...

edit: added 2 external vars "DisplayBullArrows" and "DisplayBearArrows" which gives you the opportunity to deactivate the arrows/texts ...

Attachment 1317474

edit: I found a mistake (not important, but better to fix) and I've added the harami-pattern (took the logics from an indicator, I referenced that in the sourcecode).
PatternRecognitionMaster v3ext.fxdaytrader.mq4

ReyesWhite Nov 23, 2013 2:40pm | Post# 7

1 Attachment(s)
Thank you that works so much better now. I appreciate your time doing that. I'm just wondering one more thing, I notice on the indicator it only shows an engulfing pattern if the candle has gapped slightly, when in forex really a gap is not needed due to the 24/7 action, so essentially when one bull candle for instance is bigger than the prior bear candle that is a bullish engulfing pattern ie no gap needed.

For instance here it doesn't show up as an engulfing pattern yet it is. I'm just wondering what part of the code is needed to change (i can do it myself it's no problem).

Name:  Capture.PNG
Views: 1677
Size:  < 1 KB

So essentially for engulfing candles it needs just changing so that one candle is bigger than the previous one to qualify as an engulfing, rather than the need for the slight gap down or up.

If you tell me what part of the code needs editing i can maybe do it myself.

Thanks again for your time spent with the editing of this indicator.

fxdaytrader_ Nov 23, 2013 2:54pm | Post# 8

you have too look at the lines following line line 656 (bearish engulfing)

Inserted Code
if ((C1>O1)&&(O>C)&&(O>=C1)&&(O1>=C)&&((O-C)>(C1-O1))&&(CL>=(Engulfing_Length*Point))) {

For bullish engulfing line 789:

Inserted Code
if ((O1>C1)&&(C>O)&&(C>=O1)&&(C1>=O)&&((C-O)>(O1-C1))&&(CL>=(Engulfing_Length*Point))) {


To know what the variables hold look at (approx.) line 490 (search vor "O = Open[shift1];");

ReyesWhite Nov 23, 2013 3:23pm | Post# 9

Ok thanks. Yeh i did have a look at those lines earlier but couldn't make out which part of the code was making it gap.

ReyesWhite Nov 23, 2013 3:39pm | Post# 10

Is that the code i should use to replace? Sorry i don't understand. Thanks

Kiads Nov 24, 2013 12:26am | Post# 11

Is that the code i should use to replace? Sorry i don't understand. Thanks
Yes, My Friend..
that line code to check engulfing pattern..

if ((C1>O1)&&(O>C)&&(O>=C1)&&(O1>=C)&&((O-C)>(C1-O1))&&(CL>=(Engulfing_Length*Point)))

this for bearish engulfing and read like;
(
(C1>O1) && ==> if previous candle close higher than previous candle open (bullish previous candle) "and"
(O>C) && ==> current candle open higher than current candle close "and"
(O>=C1) && ==> current candle open higher or same with previous candle close "and"
(O1>=C) && ==> previous candle open higher or same with current candle close "and"
((O-C) > (C1-O1)) && ==> current candle open "minus" current candle close range bigger than previous candle close "minus" previous candle open "and"

(CL>=(Engulfing_Length*Point)) ==> CL higher or same with "Engulfing_Length times Point (you should find out what is CL variable mean and Engulfing_Length * Point refer to converting pip/point value to double value
)

According to above engulfing 'rule' there should be no problem about there is a 'gap' or not. (>=). The problem maybe in this 'Engulfing_Length' or 'CL' variables. Try it to change with smaller value.

Hope it help and best regard.

wnabo Jan 27, 2014 4:45am | Post# 12

Anybody been making money with this indicator? And if so how have you been using it?


© Forex Factory