De-bug the code. The only tools you have are the Print statements. The strategy tester helps make the process faster also. Start with something like.
if( MacdCurrent<(MACDOpenBuyLevel*Point) ){ Print("Made-It-This-Far"); }
Then you comment-Out the above and check the other if-statement. If the 1st statement passes but the second statement does-not pass. Then you want to take a closer look at the values of MacdCurrent vs MACDOpenBuyLevel*Point. Again you use the back-tester and print (MACDOpenBuyLevel*Point) and MacdCurrent. You're looking to see if they're in the same ball park. Can or Have MacdCurrent ever been less then (MACDOpenBuyLevel*Point) ???
Added: When Printing Doubles use something like Print("MacdCurrent="+MacdCurrent); The + will give you up-to 8-digit resolutions instead of the usual 4 (with, seperated) and thats usually enough for de-bugging.
thank you for the tips, I think you didn't understand me (sorry it's my fault ^^)
But I solved it!!! What I need is the "Weighted mean" or average... The key was in arithmetic (not trigonometry)... hehe
Look: now the "CrossLevelCalculation()" function, will calculate the arithmetic weigthed average for determine the cross level !!
extern double MACDOpenBuyLevel = -10; MacdPrevious =iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,2; SignalPrevious =iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,2); MacdCurrent =iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1); SignalCurrent =iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1); [...] if( ((MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious) || (MacdCurrent>SignalCurrent && MacdPrevious<SignalPrevious)) && (CrossLevelCalculation(MacdPrevious,SignalPrevious,MacdCurrent,SignalCurrent)<(MACDOpenBuyLevel*Point))) { [...]
thank you for the tips, I think you didn't understand me (sorry it's my fault ^^)
But I solved it!!! What I need is the "Weighted mean" or average... The key was in arithmetic (not trigonometry)... hehe
Look: now the "CrossLevelCalculation()" function, will calculate the arithmetic weigthed average for determine the cross level !!
The example you gave is not "exact" as per your requirement as it will lag by one bar. Plenty can happen during bar 0 which you are ignoring. The correct way to check for levels or crosses is as follows (taken from https://www.mql5.com/go?link=http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/forum/viewtopic.php?t=57376). You should use other methods to prevent multiple signals or trades on bar 0 and not totally ignoring bar 0 as you have done.
When A crosses and goes above B(golden-cross)
Code:
Logic #1 [AND] [A] [<] [B]
+---------------------------------------+
|A: |
| ... |
| Shift: [1] |
+---------------------------------------+
+---------------------------------------+
|B: |
| ... |
| Shift: [1] |
+---------------------------------------+
Logic #2 [AND] [A] [>] [B]
+---------------------------------------+
|A: |
| ... |
| Shift: [0] |
+---------------------------------------+
+---------------------------------------+
|B: |
| ... |
| Shift: [0] |
+---------------------------------------+
When A crosses and goes below B(dead-cross)
Code:
Logic #1 [AND] [A] [>] [B]
+---------------------------------------+
|A: |
| ... |
| Shift: [1] |
+---------------------------------------+
+---------------------------------------+
|B: |
| ... |
| Shift: [1] |
+---------------------------------------+
Logic #2 [AND] [A] [<] [B]
+---------------------------------------+
|A: |
| ... |
| Shift: [0] |
+---------------------------------------+
+---------------------------------------+
|B: |
| ... |
| Shift: [0] |
+---------------------------------------+
When the value of A becomes N or more
Code:
Logic #1 [AND] [A] [<] [Number/Variable]
+---------------------------------------+
|A: |
| ... |
| Shift: [1] |
+---------------------------------------+
+---------------------------------------+
|B: |
| ... |
| Value: [N] |
+---------------------------------------+
Logic #2 [AND] [A] [=>] [Number/Variable]
+---------------------------------------+
|A: |
| ... |
| Shift: [0] |
+---------------------------------------+
+---------------------------------------+
|B: |
| ... |
| Value: [N] |
+---------------------------------------+
When the value of A becomes N or less
Code:
Logic #1 [AND] [A] [>] [Number/Variable]
+---------------------------------------+
|A: |
| ... |
| Shift: [1] |
+---------------------------------------+
+---------------------------------------+
|B: |
| ... |
| Value: [N] |
+---------------------------------------+
Logic #2 [AND] [A] [<=] [Number/Variable]
+---------------------------------------+
|A: |
| ... |
| Shift: [0] |
+---------------------------------------+
+---------------------------------------+
|B: |
| ... |
| Value: [N] |
+---------------------------------------+
Thanks Roeder, nice optimization, but I'm not only checking for a cross, I'm also checking the point value from that.
rocketman99:
The example you gave is not "exact" as per your requirement as it will lag by one bar. Plenty can happen during bar 0 which you are ignoring. The correct way to check for levels or crosses is as follows (taken from https://www.mql5.com/go?link=http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/forum/viewtopic.php?t=57376). You should use other methods to prevent multiple signals or trades on bar 0 and not totally ignoring bar 0 as you have done.
Thanks rocketman. I know that is not real cross point (like in bar0), but what I have now is the EXACT cross point from the indicators graph we see in our screen, (from the lines between bars 1 and 2)
Why can't I ignore bar 0? I saw lots of EA working with bars 1,2 like the conclusion from the post WHRoeder said: checking Ma 20 and 50 intersection - MQL4 forum In bar 0 I'm having the real "drawing shape" but also the problems of cross and uncross multiples times.
Regards
Thanks Roeder, nice optimization, but I'm not only checking for a cross, I'm also checking the point value from that.
Thanks rocketman. I know that is not real cross point (like in bar0), but what I have now is the EXACT cross point from the indicators graph we see in our screen, (from the lines between bars 1 and 2)
Why can't I ignore bar 0? I saw lots of EA working with bars 1,2 like the conclusion from the post WHRoeder said: checking Ma 20 and 50 intersection - MQL4 forum In bar 0 I'm having the real "drawing shape" but also the problems of cross and uncross multiples times.
Regards
If you want the exact level of an cross then it happens when the values gets from not equal to equal and then pass each other
you only read this exact value at the time it happens..... but that doesn't mean you have then also to close or open new trades
if you wait for that till the time the bar is closed then there will be no problem of cross and uncross multiples times
If you want the exact level of an cross then it happens when the values gets from not equal to equal and then pass each other
you only read this exact value at the time it happens..... but that doesn't mean you have then also to close or open new trades
if you wait for that till the time the bar is closed then there will be no problem of cross and uncross multiples times
Yes, I understand, but supose an example: while current bar is under construction, we are having 3 crosses, so finally the lines are in diferent position from each other, and you say: read the cross point value and keep it, but like in this case, wich of the 3 crosses points ???
I think that my alternative is a good option. I will have the exact cross level point I see in the "false" or "not precise" indicator graph... (obviously the precision is related to timeframe, and the maximum presicion is in 1 minute)
Yes, I understand, but supose an example: while current bar is under construction, we are having 3 crosses, so finally the lines are in diferent position from each other, and you say: read the cross point value and keep it, but like in this case, wich of the 3 crosses points ???
I think that my alternative is a good option. I will have the exact cross level point I see in the "false" or "not precise" indicator graph... (obviously the precision is related to timeframe, and the maximum presicion is in 1 minute)
with 3 crosses you have to take the last cross on that current bar with 2,4,6,8 ...... crosses you can also say the endresult is no cross
with 1,3,5,7,9... then the last cross will be a valid cross but in most cases if there is a little difference with the exact value it will not have a big influence I think on most brokers spread can also be changing from point to point. So an alternative is in most cases good to work with.....
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I'm trying to find the exact level where they cross the "macd" and the signal.
for example, I have this:
But the comparison with the "MACDOpenBuyLevel" It's not accurate, for the moment I do it with "MacdCurrent<...", and this it's not the cross level from the cross point.
I'm trying to get some formula, with drawings on a paper, but it has been some years ago from my basic trigonometry learning.
It wouldn't have to be difficult, the optimum would be a function with 4 points parameters, wich returns the cross level (a double). Being aware that level can be (+ or -)
(excuse me for my english) Thanks!