Input on Enum function not working for opening position on EA

 

Hello, 

I'm currently working on a Ichimoku EA and I'm struggling with the possible conditions for opening a position. 

I would like to know WHY when the EA is checking for the condition "BUY_OPEN" or "SELL_OPEN"

if (Nb_positions<1 && BUY_OPEN

It does NOT take into account the  "Open_buy_position" input to know which condition needs to be checked:

input Open_buy_position BUY_OPEN=OP_LONG2;

It works only if it's hard coded like below but it isn't what I'm looking for... 

if (Nb_positions<1 && OP_LONG2

Here is a part of EA code:

enum Open_buy_position
  {
   LONG_KUMO_BREAKOUT,   // Kumo Breakout (buy)
   LONG_KIJUN_BREAKOUT,  // Kijun Breakout (buy)
   LONG_TENKAN_KIJUN_CO, // Tenkan & Kijun crossover (buy)
   OP_LONG1,
   OP_LONG2
  };

enum Open_sell_position
  {
   SHORT_KUMO_BREAKOUT,   // Kumo Breakout (sell)
   SHORT_KIJUN_BREAKOUT,  // Kijun Breakout (sell)
   SHORT_TENKAN_KIJUN_CO, // Tenkan & Kijun crossover (sell)
   OP_SHORT1,
   OP_SHORT2
  };

enum Close_buy_position
  {
   CL_LONG1,   
   CL_LONG2,  
   CL_LONG3 

  };

enum Close_sell_position
  {
   CL_SHORT1,   
   CL_SHORT2,  
   CL_SHORT3 
  };
  
//---------------------------------

input Open_buy_position BUY_OPEN=OP_LONG2;
input Open_sell_position SELL_OPEN=OP_SHORT2;
input Close_buy_position BUY_CLOSE=CL_LONG2;
input Close_sell_position SELL_CLOSE=CL_SHORT2;

//+----------------STRATEGY FOR LONG POSITION-----------------------------------+
   bool LONG_KUMO_BREAKOUT= iClose(NULL,0,0)>Top_cloud_0;
   bool LONG_KIJUN_BREAKOUT= iClose(NULL,0,0)>KijunValue && iClose(NULL,0,0)>Top_cloud_0;
   bool LONG_TENKAN_KIJUN_CO= TenkanValue>KijunValue && TenkanValue_1<=KijunValue_1 && TenkanValue>Top_cloud_0;
   
   bool OP_LONG1 = iClose(NULL,0,0)>Top_cloud_0 && SSA_Value > SSB_Value && Chikou_Value > Top_cloud_0 && TenkanValue>KijunValue;
   bool OP_LONG2 = ValeurRSI<20;
   
//+----------------STRATEGY FOR OPENING SHORT POSITION-----------------------------------+   
   
   bool SHORT_KUMO_BREAKOUT=  iClose(NULL,0,0)<Down_cloud_0;
   bool SHORT_KIJUN_BREAKOUT= iClose(NULL,0,0)<KijunValue && iClose(NULL,0,0)<Down_cloud_0;
   bool SHORT_TENKAN_KIJUN_CO= TenkanValue<KijunValue && TenkanValue_1>=KijunValue_1 && TenkanValue<Down_cloud_0;  
   
   bool OP_SHORT1 = iClose(NULL,0,0)<Down_cloud_0 && SSA_Value < SSB_Value && Chikou_Value < Down_cloud_0 && TenkanValue<KijunValue;
   bool OP_SHORT2 = ValeurRSI>80;

//+----------------STRATEGY FOR CLOSING LONG POSITION-----------------------------------+ 

bool CL_LONG1 = SSA_Value < SSB_Value;
bool CL_LONG2 = TenkanValue<=KijunValue;
bool CL_LONG3 = iClose(NULL,0,0)<Top_cloud_0;

//+----------------STRATEGY FOR CLOSING SHORT POSITION-----------------------------------+ 

bool CL_SHORT1 = SSA_Value > SSB_Value;
bool CL_SHORT2 = TenkanValue>=KijunValue;
bool CL_SHORT3 = iClose(NULL,0,0)>Down_cloud_0;
   
//+------------------------------------------------------------------+
//| Check for long position opening                                  |
//+------------------------------------------------------------------+
         if (Nb_positions<1 && BUY_OPEN)   
             //if (BUY_OPEN)          
                  { 
                  m_trade.PositionOpen(Symbol(),ORDER_TYPE_BUY,MM,Ask,Ask-SL*_Point,Ask+TK*_Point);
                  }

//+------------------------------------------------------------------+
//| Check for long position closing                                  |
//+------------------------------------------------------------------+    
         if (Nb_positions==1)
            if((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY) 
             if(BUY_CLOSE) 
                  {
                  m_trade.PositionClose(Symbol());
                  }
//+------------------------------------------------------------------+
//| Check for short position opening                                 |
//+------------------------------------------------------------------+

         if (Nb_positions<1 && SELL_OPEN)    
              //if (SELL_OPEN)                      
                 {
                  m_trade.PositionOpen(Symbol(),ORDER_TYPE_SELL,MM,Bid,Bid+SL*_Point,Bid-TK*_Point);
                 }

//+------------------------------------------------------------------+
//| Check for short position closing                                  |
//+------------------------------------------------------------------+ 
         if (Nb_positions==1)
            if((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL) 
             if(SELL_CLOSE)
                  {
                  m_trade.PositionClose(Symbol());
                  }   
 

Enums are not booleans, they have integers behind, so when you write:

if (Nb_positions<1 && BUY_OPEN)   

MQL just checks if BUY_OPEN is zero or non-zero. Zero is false, any other value is true.


Your comparison should be something like this:

if (Nb_positions<1 && BUY_OPEN == LONG_KUMO_BREAKOUT)   // or any other value depending on your strategy
 
Drazen Penic #:

Enums are not booleans, they have integers behind, so when you write:

MQL just checks if BUY_OPEN is zero or non-zero. Zero is false, any other value is true.


Your comparison should be something like this:

Ok, this is probably the reason why I don't the result I was expecting. 

The problem with your suggestion is that I can't change the condition in the "Input" tab of the strategy tester , right ? 


If so, how can I proceed to be able to change the opening condition in the strategy tester ? 

Files:
 
Isendar #:

Ok, this is probably the reason why I don't the result I was expecting. 

The problem with your suggestion is that I can't change the condition in the "Input" tab of the strategy tester , right ? 


If so, how can I proceed to be able to change the opening condition in the strategy tester ? 


My suggestion has nothing to do with input parameters, it's about a way you do comparison in your program.

I have no idea why do you have problems with changing input parameters, but it is definitely not because of the change in code.

Here's a dummy EA where I copied your enums and input variables:

enum Open_buy_position
  {
   LONG_KUMO_BREAKOUT,   // Kumo Breakout (buy)
   LONG_KIJUN_BREAKOUT,  // Kijun Breakout (buy)
   LONG_TENKAN_KIJUN_CO, // Tenkan & Kijun crossover (buy)
   OP_LONG1,
   OP_LONG2
  };

enum Open_sell_position
  {
   SHORT_KUMO_BREAKOUT,   // Kumo Breakout (sell)
   SHORT_KIJUN_BREAKOUT,  // Kijun Breakout (sell)
   SHORT_TENKAN_KIJUN_CO, // Tenkan & Kijun crossover (sell)
   OP_SHORT1,
   OP_SHORT2
  };

enum Close_buy_position
  {
   CL_LONG1,   
   CL_LONG2,  
   CL_LONG3 

  };

enum Close_sell_position
  {
   CL_SHORT1,   
   CL_SHORT2,  
   CL_SHORT3 
  };
  
//---------------------------------

input Open_buy_position BUY_OPEN=OP_LONG2;
input Open_sell_position SELL_OPEN=OP_SHORT2;
input Close_buy_position BUY_CLOSE=CL_LONG2;
input Close_sell_position SELL_CLOSE=CL_SHORT2;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
//+------------------------------------------------------------------+


I can change values in the tester:


MT5 tester