Multiple Indicators Logic Help - page 3

 
Abdul Wahab Mughal #:
What do you mean by this? 

i mean you will need to send the buy tally and sell tally as references to the check function so that you can read them on the tick so : 

void OnTick(){
//when you check you call the check function
   int buyTally=0,sellTally=0;
   check(indicators etc....,buyTally,sellTally);
}


void check(indictators etc...,int &buyTally,int &sellTally){
//do the tally stuff in here
//and change buyTally and sellTally
}

this tells the function that its using the object that saw sent and not creating a new one 

 
Abdul Wahab Mughal:
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 

As your semantic is complex, probably a good hint is to elicitate all cases designing a Decision-Table, with all conditions (enable/disable indicators and indicators values comparisons) and actions (buy, sell or do nothing). So you'll visualize better all cases to simplify your coding.

Best regards
 
Carlos Camargo #:

As your semantic is complex, probably a good hint is to elicitate all cases designing a Decision-Table, with all conditions (enable/disable indicators and indicators values comparisons) and actions (buy, sell or do nothing). So you'll visualize better all cases to simplify your coding.

Best regards
Hello could you give a code example of this?

Kind Regards 
 
Lorentzos Roussos #:

i mean you will need to send the buy tally and sell tally as references to the check function so that you can read them on the tick so : 

this tells the function that its using the object that saw sent and not creating a new one 

Hello,

I implemented everything however the expert doesn’t trade from some combinations of enabled indicators and if all are enabled.

I believe this because the actual conditions for each indicator need to be refined so that there the total signal isn’t impossible to achieve 


Any suggestions regarding conditions for each indicator.


Lastly for modularity would yo recommend keeping the necessary copybuffer as local variables for the indicators needed in that Void() logic. Instead of having it in OnTick

void IndicatorsLogic(double &RSI[], double &ma1[], double &ma2[], double &bbUpper[], double &bbLower[], double &CurrentBBClose, double &PrevBBClose,int &buyTally,int &sellTally, int &maxTally) 
{
             
            if (EnableRSI)
            {
               if(RSI[0] < RSILowerLevel && RSI[1] >= RSILowerLevel){buyTally++;}
               if(RSI[0] > RSIUpperLevel && RSI[1] <= RSIUpperLevel){sellTally++;}
            }

            if (EnableMA1)
            {
               if(ma1[1] < ma1[0] && ma1Direction >= 0){buyTally++;}
               if(ma1[1] > ma1[0] && ma1Direction <= 0){sellTally++;}
            }

            if (EnableMA2)
            {
                if(ma2[1] < ma2[0] && ma2Direction >= 0){buyTally++;}
                if(ma2[1] > ma2[0] && ma2Direction <= 0){sellTally++;}
            }

            if (EnableBothMA)
            {
                if(ma1[0] < ma2[0] && ma1[1] < ma2[1]){buyTally++;}
                if(ma1[0] > ma2[0] && ma1[1] > ma2[1]){sellTally++;}
            }

            if (EnableBB)
            {
                if(CurrentBBClose > bbLower[0] && PrevBBClose < bbLower[1]){buyTally++;}
                if(CurrentBBClose < bbUpper[0] && PrevBBClose > bbUpper[1]){sellTally++;}
            }
}


And 


      Void OnTick()(
int buyTally=0; int sellTally=0;  int maxTally=((int)EnableRSI)+((int)EnableMA1)+((int)EnableMA2)+((int)EnableBothMA)+((int)EnableBB);
IndicatorsLogic(RSI, ma1, ma2, bbUpper, bbLower, CurrentBBClose, PrevBBClose, buyTally, sellTally, maxTally);
   
 if (sellTally==maxTally&&buyTally<maxTally)
       { ma1Direction = 1;
         ma2Direction = 1;
         // OrderSell
         }
else if (buyTally==maxTally&&sellTally<maxTally)
       { ma1Direction = -1;
         ma2Direction = -1;
         // OrderBuy
         }     
     }  



Kind Regards 

 
Abdul Wahab Mughal #:
Hello,

I implemented everything however the expert doesn’t trade from some combinations of enabled indicators and if all are enabled.

I believe this because the actual conditions for each indicator need to be refined so that there the total signal isn’t impossible to achieve 


Any suggestions regarding conditions for each indicator.


Lastly for modularity would yo recommend keeping the necessary copybuffer as local variables for the indicators needed in that Void() logic. Instead of having it in OnTick


And 




Kind Regards 

Is there an indicator that does not work on its own ?

 
Lorentzos Roussos #:

Is there an indicator that does not work on its own ?

No they all work on their own. I have managed to get them all working by playing around with the signs.
 
Abdul Wahab Mughal #:
No they all work on their own. I have managed to get them all working by playing around with the signs.

great good job . So its solved then

 
Lorentzos Roussos #:

great good job . So its solved then

Yes thank you.