Multiple Indicators Logic Help - page 2

 
Abdul Wahab Mughal #:
No the problem doesn’t correlate with the conditions combined being too rare.

As what’s happening is let’s say RSI, BB and MA1 are enabled only. The expert after being placed on chart will open trades even when RSI and BB are not met. However I noticed that whether it’s a buy or sell is following the MA1 logic.

So it seems the Moving Average logic is somehow overriding the other indicators logic. Or is being prioritised. It could be due to using MA1Direction variable in the firing block of code.


For the second version. Let’s say only RSI is enabled. The expert doesn’t trade at all. I’ve tried all the indicators individually, I’ve tried different combinations of enabled indicators and I’ve tried all together. No orders are being fired at all.

Even if I just modify the original code like below expert stops trading completely.




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 

The simplest way would be to assign a maximum score at the beggining based on how many indicators are on .

Then if an indicator fires you add one to the score . (you set the score to 0 before starting the check).

 
Lorentzos Roussos #:

The simplest way would be to assign a maximum score at the beggining based on how many indicators are on .

Then if an indicator fires you add one to the score . (you set the score to 0 before starting the check).


By using a tally wouldn’t that mean that I can’t disable indicators. So if one day I wanted to use just RSI or just BB I can’t as the tally is hard coded.

The code works and combines the RSI and BB when they’re only enabled. The problem is with Moving Averages logic. How would you code a single moving average expert.

Let’s say just MA1, would you use the same logic I have been taught. Which includes the MaDirection Variable?

Could you send an example for Buy or Sell logic of how you would do conditions for moving averages?



 
Kind Regards 
 
Abdul Wahab Mughal #:

By using a tally wouldn’t that mean that I can’t disable indicators. So if one day I wanted to use just RSI or just BB I can’t as the tally is hard coded.

The code works and combines the RSI and BB when they’re only enabled. The problem is with Moving Averages logic. How would you code a single moving average expert.

Let’s say just MA1, would you use the same logic I have been taught. Which includes the MaDirection Variable?

Could you send an example for Buy or Sell logic of how you would do conditions for moving averages?



 
Kind Regards 

it would not be hardcoded . The user enables or disables indicators .

Then the initialization counts the enabled indicators . That is the max tally 

With Fast and Slow ma ? or price ?

 
Lorentzos Roussos #:

it would not be hardcoded . The user enables or disables indicators .

Then the initialization counts the enabled indicators . That is the max tally 

With Fast and Slow ma ? or price ?

Using price for ma.

Ah I see so you’d set the maximum tally number needed based on enabled indicators during Initialisation.

I’m not sure how to do that could you provide a code template for your suggestions, just for what would need to go in Oninit and either Buy or Sell based on your recent suggestion.



Kind Regards 
 
Abdul Wahab Mughal #:
Using price for ma.

Ah I see so you’d set the maximum tally number needed based on enabled indicators during Initialisation.

I’m not sure how to do that could you provide a code template for your suggestions, just for what would need to go in Oninit and either Buy or Sell based on your recent suggestion.



Kind Regards 

Something like this

int maxTally=((int)EnableRSI)+((int)EnableMA1)+((int)EnableMA2)+((int)EnableBothMA)+((int)EnableBB);
int buyTally=0;
int sellTally=0;
             
            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++;}
            }

            if (buyTally==maxTally&&sellTally<maxTally)
            {
            
            }
            else if (sellTally==maxTally&&buyTally<maxTally)
            {
            
            }
 
Lorentzos Roussos #:

Something like this

I see, thank you for that. 


How would this be put into a Void() or bool() function? To de-clutter the ontick.


Kind Regards 
 
Abdul Wahab Mughal #:
I see, thank you for that. 


How would this be put into a Void() or bool() function? To de-clutter the ontick.


Kind Regards 

Pass the values of the indicators as parameters into a function or move the arrays with the values in too.

 
Lorentzos Roussos #:

Pass the values of the indicators as parameters into a function or move the arrays with the values in too.

So something like this.


Void IndicatorsLogic(double &RSI, double &BB,..other arrays, double CurrentBBClose, double PrevBBClose) 
{int maxTally=((int)EnableRSI)+((int)EnableMA1)+((int)EnableMA2)+((int)EnableBothMA)+((int)EnableBB);
int buyTally=0;
int sellTally=0;
             
            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++;}
            }}

            Void OnTick(){
            if (buyTally==maxTally&&sellTally<maxTally)
            {
           // OrderBuy
            }
            else if (sellTally==maxTally&&buyTally<maxTally)
            {
           // OrderSell
            }}



Would void or bool be best? And then keeping the total required conditions in the OnTick with the Order logic for Buy and Sell


Void OnTick(){
            if (buyTally==maxTally&&sellTally<maxTally)
            {
           // OrderBuy
            }
            else if (sellTally==maxTally&&buyTally<maxTally)
            {
           // OrderSell
            }}


Kind Regards 
 
Abdul Wahab Mughal #:

So something like this.




Would void or bool be best? And then keeping the total required conditions in the OnTick with the Order logic for Buy and Sell




Kind Regards 

yeah but with buytally and selltally as refererences too

 
Lorentzos Roussos #:

yeah but with buytally and selltally as refererences too

What do you mean by this?