Topic: Turning indicators on and off in single strategy

Im wondering if someone can help with with this problem.

I want to be able to turn ON/OFF opening and closing indicators signals given by EA Studio generated stratgies from the strategy properties screen on MT4. Reason being is I am building some EA's for some friends and they want to be able to play around with what indicators they want to use ie build a EA using EA Studio with RSI,MACD,EMA and they then have the ability to turn off the RSI for example.

The way I have tried is making the Indictor a bool however if I do this and set to false then no entry signals are created, due to how the manageOpen is coded:

void ManageOpen()
  {
   double ind0val1 = iRSI(NULL,0,Ind0Param0,PRICE_CLOSE,1);
   bool ind0long  = ind0val1 > Ind0Param1 + sigma && ActivateRSI;
   bool ind0short = ind0val1 < 100 - Ind0Param1 - sigma ;

   double ind1val1 = iMA(NULL,0,Ind1Param0,0,MODE_LWMA,PRICE_CLOSE,1);
   double ind1val2 = iMA(NULL,0,Ind1Param1,0,MODE_LWMA,PRICE_CLOSE,1);
   bool ind1long  = ind1val1 > ind1val2 + sigma && ActivateVWMA;
   bool ind1short = ind1val1 < ind1val2 - sigma ;

   double ind2val1 = iMACD(NULL,0,Ind2Param0,Ind2Param1,Ind2Param2,PRICE_CLOSE,MODE_MAIN,1);
   double ind2val2 = iMACD(NULL,0,Ind2Param0,Ind2Param1,Ind2Param2,PRICE_CLOSE,MODE_MAIN,2);
   double ind2val3 = iMACD(NULL,0,Ind2Param0,Ind2Param1,Ind2Param2,PRICE_CLOSE,MODE_MAIN,3);
   bool ind2long  = ind2val1 > ind2val2 + sigma && ind2val2 < ind2val3 - sigma && ActivateMACD;
   bool ind2short = ind2val1 < ind2val2 - sigma && ind2val2 > ind2val3 + sigma ;

   double ind3val1 = iMA(NULL,0,Ind3Param0,0,MODE_EMA,PRICE_CLOSE,1);
   double ind3val2 = iMA(NULL,0,Ind3Param1,0,MODE_EMA,PRICE_CLOSE,1);
   bool ind3long  = ind3val1 > ind3val2 + sigma && ActivateEMA;
   bool ind3short = ind3val1 < ind3val2 - sigma ;

   const bool canOpenLong  = ind0long && ind1long && ind2long && ind3long;
   const bool canOpenShort = ind0short && ind1short && ind2short && ind3short;

   if(canOpenLong && canOpenShort)
      return;

   if(canOpenLong)
      OpenPosition(OP_BUY);
   else if(canOpenShort)
      OpenPosition(OP_SELL);
  }

Re: Turning indicators on and off in single strategy

It is easy:

Add these two lines at the beginning of the expert, just below `#property strict`:

input bool AllowEntry = true; // Allow Entry
input bool AllowExit  = true; // Allow Exit

Add these checks at the beginning of `ManageOpen` and `ManageClose` functions:

void ManageOpen()
  {
   if (!AllowEntry) return;

....

void ManageClose()
  {
   if (!AllowExit) return;

You will have options for allowing entry or exits at the Expert's Input.

https://image-holder.forexsb.com/store/expert-advisor-options-for-allow-entry-and-allow-exit.png

Re: Turning indicators on and off in single strategy

If you want to enable or disable separate indicators, add the following flags:

input bool ind0enabled= true; // Indicator MACD Enabled
input bool ind1enabled= true; // Indicator Volume Enabled

And then in `ManageOpen`:

void ManageOpen()
  {
...

   const bool canOpenLong  = (!ind0enabled || ind0long)  && (!ind1enabled || ind1long);
   const bool canOpenShort = (!ind0enabled || ind0short) && (!ind1enabled || ind1short);

It works like that:

The original code gives a signal when both indicators allow it:

   const bool canOpenLong  = ind0long && ind1long;

Now we change `ind0long` with `(!ind0enabled || ind0long)` and the same for the others.

If `ind0enabled` is `true` and because we negate the flag, the `||` must check the second rule. The code works as the original one.

If `ind0enabled` is `false`, it negates to `true` and the code allows the entry no matter the actual indicator signal.

Re: Turning indicators on and off in single strategy

Hi Popov,

Why did I not think of that! So simple!

Thank you for your help I really appreciate it!.