If you need the ROC crosses below/above 0, you can change the Cross function to :
int Cross() { double ROCP1=iCustom(NULL,0,"ROC2_VG",ROCPeriod1,ROCType1,0,1); double ROCP1_1=iCustom(NULL,0,"ROC2_VG",ROCPeriod1,ROCType1,0,0); Print(StringConcatenate("ROCP1: ",ROCP1)); Print(StringConcatenate("ROCP1_1: ",ROCP1_1)); if(ROCP1<0 && ROCP1_1>0){return(1);} if(ROCP1>0 && ROCP1_1<0){return(-1);} return(0); }
But if you don't need the ROC crosses, only above/below EA, then change the Cross function to :
int Cross() { double ROCP1_1=iCustom(NULL,0,"ROC2_VG",ROCPeriod1,ROCType1,0,0); Print(StringConcatenate("ROCP1_1: ",ROCP1_1)); if( ROCP1_1>0){return(1);} if( ROCP1_1<0){return(-1);} return(0); }
If you need the ROC crosses below/above 0, you can change the Cross function to :
But if you don't need the ROC crosses, only above/below EA, then change the Cross function to :
Thats not what i mean. The problem i have is, that the ROC gets above 0 later then the first buy signal. but right not the EA only takes trades when its happening at the same time
Try changing this:
// Buy Rules if (Cross()>0) if (sell_hmaprevious!=EMPTY_VALUE && sell_hmacurrent==EMPTY_VALUE && buy_hmacurrent!=EMPTY_VALUE)
...to this:
// Buy Rules if ( Cross()>0 && sell_hmaprevious!=EMPTY_VALUE && sell_hmacurrent==EMPTY_VALUE && buy_hmacurrent!=EMPTY_VALUE)
The conditions must be "Cross" AND "sell_hmaprevious"... basically, your entry conditions are just based on:
if (sell_hmaprevious!=EMPTY_VALUE && sell_hmacurrent==EMPTY_VALUE && buy_hmacurrent!=EMPTY_VALUE)
...if I am correct and that makes any sense to you...
VisaVersa for "Sell" obviously...
// Sell Rules if( Cross()<0 && buy_hmaprevious!=EMPTY_VALUE && buy_hmacurrent==EMPTY_VALUE && sell_hmacurrent!=EMPTY_VALUE)
Try changing this:
...to this:
The conditions must be "Cross" AND "sell_hmaprevious"... basically, your entry conditions are just based on:
...if I am correct and that makes any sense to you...
The problem is, that the ROC crosses 0 mostly way later. The EA is only opening trades when it happens at the same time.
If the ROC crosses 0 after the HMA turns green/red, then its not opening any trades. But I want it to.
i have the feeling it can de done with iBar. But im not sure.
The problem is, that the ROC crosses 0 mostly way later. The EA is only opening trades when it happens at the same time.
Well... it is delayed because of your Cross() function... read what Biantoro said above... but you could also be using the wrong "hma-trend-indicator" buffer values... If the buffer values are the "Arrows" of the indicator then your entry conditions will only be "true" on that candle... if however you use the "Dots"... then your "HMA" entry conditions will be true over several candles....
... if that makes any sense...
Well... it is delayed because of your Cross() function... read what Biantoro said above... but you could also be using the wrong "hma-trend-indicator" buffer values... If the buffer values are the "Arrows" of the indicator then your entry conditions will only be "true" on that candle... if however you use the "Dots"... then your "HMA" entry conditions will be true over several candles....
... if that makes any sense...
https://ibb.co/1sn7MZc
That's when it should open a trade. The HMA Indicator is a line in my case. As you can see on the picture. If its just the HMA, then everything is fine.
My problem is that it doesn't open trades when the hma turns green/red first and then the ROC crosses or the ROC crosses first and then the hma turns green/red.
I'm sorry if i didn't explain that clearly before
Attach your HMA indi so that I can have a look at the buffers... but an easy fix would be to simply take the "Slope" of your "HMA" indi line.... something like:
double HMA_Slope = (iCustom(NULL, 0, "hma-trend-indicator", 30,3,0, 0, 0) - iCustom(NULL, 0, "hma-trend-indicator", 30,3,0, 0, 1));
Then change your Entry conditions to:
// Buy Rules if ( Cross()>0 && HMA_Slope > 0) // Sell Rules if ( Cross()<0 && HMA_Slope < 0)
...now the "Entry" conditions should be "True" whenever the HMA line is "Green" AND ROC crosses above "0"... and whenever the HMA line is "Red" and ROC crosses down below "0".... well... it should
Sorry... AND change your Cross() function to what Biantoro said...
int Cross() { double ROCP1=iCustom(NULL,0,"ROC2_VG",ROCPeriod1,ROCType1,0,1); double ROCP1_1=iCustom(NULL,0,"ROC2_VG",ROCPeriod1,ROCType1,0,0); Print(StringConcatenate("ROCP1: ",ROCP1)); Print(StringConcatenate("ROCP1_1: ",ROCP1_1)); if(ROCP1<0 && ROCP1_1>0){return(1);} if(ROCP1>0 && ROCP1_1<0){return(-1);} return(0); }Hope that helps...
Attach your HMA indi so that I can have a look at the buffers... but an easy fix would be to simply take the "Slope" of your "HMA" indi line.... something like:
Then change your Entry conditions to:
...now the "Entry" conditions should be "True" whenever the HMA line is "Green" AND ROC crosses above "0"... and whenever the HMA line is "Red" and ROC crosses down below "0".... well... it should
Sorry... AND change your Cross() function to what Biantoro said...
Hope that helps...Thank you ! Its already working well, but its not taking any short trades now.
...it was the "buffer" number (normly is with these 'Changing Color' trend indicators)....
Buffer 0 - is the "Green" color "Up" trend value...
Buffer 1 - is the "Red" color "Down" trend value...
Buffer 2 - is the actual indicator "Line" value....
.....so, your "Slope" calculation should be using Buffer 2... otherwize the calc. will only be using the Up or Down value.... hence only making "Long" trades...
double HMA_Slope = (iCustom(NULL, 0, "hma-trend-indicator", 30,3,0, 2, 0) - iCustom(NULL, 0, "hma-trend-indicator", 30,3,0, 2, 1));
...should work ok now...
...it was the "buffer" number (normly is with these 'Changing Color' trend indicators)....
Buffer 0 - is the "Green" color "Up" trend value...
Buffer 1 - is the "Red" color "Down" trend value...
Buffer 2 - is the actual indicator "Line" value....
.....so, your "Slope" calculation should be using Buffer 2... otherwize the calc. will only be using the Up or Down value.... hence only making "Long" trades...
...should work ok now...
Thank you very much !!! its working just fine !
- 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,
This EA is buying when the HMA indicator is turning green and selling when its turning red. But then it needs to wait till the ROC is getting above 0 for a buy and below 0 for a sell.
Right now its only opening a trade if it happens at the same time. Mostly the hma turns green first and then the ROC crosses 0. So mostly its not opening trades, because its not happening at the same time
What do I need to do in order to let it "wait" for the ROC and then open a trade ?