I’m currently working on logic for multiple indicators.
The desired outcome is that indicators can be enabled and disabled individually. The expert should trade the logic of each individual indicator if only that indicator is enabled.
If multiple indicators are enabled the expert should combine the Logic and only place an order when the conditions for all enabled indicators are met.
Sounds simple but I’ve been having issues when multiple indicators are enabled. I’ve made different iterations of the code individual conditions work. RSI and Bollinger bands are giving problems and when both are enabled RSI, BB conditions combine. But if I enable EMA1, Or EMA2 or BothEMA. The expert just starts opening orders even when RSI and BB conditions aren’t met. It seems the issue is when Moving Average related logic is enable with another or multiple indicators.
I have provided 2 of the different styles of coding this logic I have tried.
Below is the original attempt to get the desired outcome.
With the above original version. All indicators work when when individually enabled. And when multiple are enabled the RSI and BB work together properly but if I then enable one of the Moving Average logics expert seems to place trade based on MA even when RSI and BB conditions aren’t met.
Below is another version.
with the version above the expert has completely stopped trading even if only one of the indicators are enabled. And of course when multiple are enabled it doesn’t open orders.
What should happen is let’s say RSI,BB and MA1 are enabled expert should only trade Buy when RSI and BB and MA1 conditions are all met.
Need guidance on what’s wrong as I’m aware there are experts that work on 8+ indicators.
Kind Regards
What happens is on the first version any indicator can fire the signal .
For the second version , i assume you want all the indicators that are enabled to fire at the same signal a signal(or be at that state)
If i understand correctyly then you should have a "tally to beat" variable which you initialize at the start of the ea and it counts how many indicators are enabled.
Then you treat each indicator as a "vote" , and in this case you need all the votes to be in for a trade .
What happens is on the first version any indicator can fire the signal .
For the second version , i assume you want all the indicators that are enabled to fire at the same signal a signal(or be at that state)
If i understand correctyly then you should have a "tally to beat" variable which you initialize at the start of the ea and it counts how many indicators are enabled.
Then you treat each indicator as a "vote" , and in this case you need all the votes to be in for a trade .
Hello to clarify each individual indicator has its own Boolean. What I want is when multiple indicators are enabled the Expert should open orders when all the enabled conditions are met. So if only 1 indicator is enabled then only that condition needs to be met. If 4 indicators are enabled then the conditions of all 4 indicators needs to be met before an order is issued.
Vice versa for any number of enabled Indicators.
A tally wouldn’t work I don’t think as it can’t exclude the disabled indicators.
I have tried a different way shown below. The expert still doesn’t trade for any number of enable indicators so somewhere is wrong.
bool buyCondition = true; bool sellCondition = true; if (EnableRSI) { buyCondition = buyCondition && (RSI[0] < RSILowerLevel && RSI[1] >= RSILowerLevel); sellCondition = sellCondition && (RSI[0] > RSIUpperLevel && RSI[1] <= RSIUpperLevel); } if (EnableMA1) { buyCondition = buyCondition && (ma1[1] < ma1[0] && ma1Direction >= 0); sellCondition = sellCondition && (ma1[1] > ma1[0] && ma1Direction <= 0); } if (EnableMA2) { buyCondition = buyCondition && (ma2[1] < ma2[0] && ma2Direction >= 0); sellCondition = sellCondition && (ma2[1] > ma2[0] && ma2Direction <= 0); } if (EnableBothMA) { buyCondition = buyCondition && (ma1[0] < ma2[0] && ma1[1] < ma2[1]); sellCondition = sellCondition && (ma1[0] > ma2[0] && ma1[1] > ma2[1]); } if (EnableBB) { buyCondition = buyCondition && (CurrentBBClose > bbLower[0] && PrevBBClose < bbLower[1]); sellCondition = sellCondition && (CurrentBBClose < bbUpper[0] && PrevBBClose > bbUpper[1]); } if (buyCondition) { // Place your buy trade here } else if (sellCondition) { // Place your sell trade here } }
Kind Regards
Hello to clarify each individual indicator has its own Boolean. What I want is when multiple indicators are enabled the Expert should open orders when all the enabled conditions are met. So if only 1 indicator is enabled then only that condition needs to be met. If 4 indicators are enabled then the conditions of all 4 indicators needs to be met before an order is issued.
Vice versa for any number of enabled Indicators.
A tally wouldn’t work I don’t think as it can’t exclude the disabled indicators.
I have tried a different way shown below. The expert still doesn’t trade for any number of enable indicators so somewhere is wrong.
Kind Regards
I see
Are the indicator values called in properly ?
Hello, yes they are. I have used print statements to check and Handles and Copy buffer are correct.
If you disable all indicators does it trade ?
What are ma1Direction and ma2Direction ?If you disable all indicators does it trade ?
What are ma1Direction and ma2Direction ?For the original conditions code, when all indicators are disabled the expert doesn’t trade, it’s not supposed to so that is okay.
Sort of a way to save the last signal ,i see .
So , unless i'm blind , i can't see the issue here . I believe the problem is in another part of the code in conjuction with this method of firing signals
Sort of a way to save the last signal ,i see .
So , unless i'm blind , i can't see the issue here . I believe the problem is in another part of the code in conjuction with this method of firing signals
The problem has to be with the conditions as the indicators work on their own just not together.
could it be too rare that they fire at the exact same time ? Since there is no flaw in the code above (from what i can see) and there is no flaw in the other parts .
could it be too rare that they fire at the exact same time ? Since there is no flaw in the code above (from what i can see) and there is no flaw in the other parts .
Even if I just modify the original code like below expert stops trading completely.
if((EnableRSI && RSI[0] > RSIUpperLevel) && RSI[1] <= RSIUpperLevel){ if((EnableMA1 && ma1[1] > ma1[0]) && ma1Direction <= 0) || ((EnableMA2 && ma2[1] > ma2[0]) && ma2Direction <= 0) || ((EnableBothMA && ma1[0] > ma2[0] && ma1[1] > ma2[1]) && ma1Direction <= 0 && ma2Direction <= 0) || ((EnableBB && CurrentBBClose < bbUpper[0]) && PrevBBClose > bbUpper[1]){ ma1Direction = 1; ma2Direction = 1; //Sell Order Placeholder }} else if((EnableRSI && RSI[0] < RSILowerLevel) && RSI[1] >= RSILowerLevel){ if((EnableMA1 && ma1[1] < ma1[0]) && ma1Direction >= 0) || ((EnableMA2 && ma2[1] < ma2[0]) && ma2Direction >= 0) || ((EnableBothMA && ma1[0] < ma2[0] && ma1[1] < ma2[1]) && ma1Direction >= 0 && ma2Direction >= 0) || ((EnableBB && CurrentBBClose > bbLower[0]) && PrevBBClose < bbLower[1]){ ma1Direction = -1; ma2Direction = -1; //Buy Order Placeholder }} if(!EnableRSI || !EnableMA1 || !EnableMA2 || !EnableBothMA || !EnableBB)return;
Just one change at RSI stops it from working completely.
Okay a separate question if you were trying to use 4 indicators and achieve the same desired function as me How would you code it? Maybe that would be a good starting point to figure the issue out
Kind Regards
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
The desired outcome is that indicators can be enabled and disabled individually. The expert should trade the logic of each individual indicator if only that indicator is enabled.
If multiple indicators are enabled the expert should combine the Logic and only place an order when the conditions for all enabled indicators are met.
Sounds simple but I’ve been having issues when multiple indicators are enabled. I’ve made different iterations of the code individual conditions work. RSI and Bollinger bands are giving problems and when both are enabled RSI, BB conditions combine. But if I enable EMA1, Or EMA2 or BothEMA. The expert just starts opening orders even when RSI and BB conditions aren’t met. It seems the issue is when Moving Average related logic is enable with another or multiple indicators.
I have provided 2 of the different styles of coding this logic I have tried.
Below is the original attempt to get the desired outcome.
With the above original version. All indicators work when when individually enabled. And when multiple are enabled the RSI and BB work together properly but if I then enable one of the Moving Average logics expert seems to place trade based on MA even when RSI and BB conditions aren’t met.
Below is another version.
with the version above the expert has completely stopped trading even if only one of the indicators are enabled. And of course when multiple are enabled it doesn’t open orders.
What should happen is let’s say RSI,BB and MA1 are enabled expert should only trade Buy when RSI and BB and MA1 conditions are all met.
Need guidance on what’s wrong as I’m aware there are experts that work on 8+ indicators.
Kind Regards