simplifying code for 2 connected variable

 

Hi,

I have 3 input variables with enum data type and 3 other variables with double data type.

enum CLOSE_TRADE_BY
  {
   NONE,
   ATR_STOPLOSS,
   FIXED_STOPLOSS,          //Fixed stoploss
   ATR_TAKE_PROFIT,
   FIXED_TAKE_PROFIT        //Fixed take profit
  };

//Variables
input CLOSE_TRADE_BY InpCloseTradeBy = NONE,
                     InpCloseTradeBy2 = NONE,
                     InpCloseTradeBy3 = NONE;
input double         InpCoef = 0,
                     InpCoef2 = 0,
                     InpCoef3 = 0;

if I want to use fixed stoploss on InpCloseTradeBy variable I will use InpCoef variable for the input value that I need, so does with InpCloseTradeBy2 with InpCoef2 and InpCloseTradeBy3 with InpCoef3. The problem is that I can use (e.g) Fixed stoploss in one of the close trade by variable.

When I want to open new position, on MqlTradeRequest SL parameter I use this code,

if(InpCloseTradeBy   == FIXED_STOPLOSS)
   orderRequest.sl   = tick.bid + Spread - (InpCoef * Point());
if(InpCloseTradeBy2  == FIXED_STOPLOSS)
   orderRequest.sl   = tick.bid + Spread - (InpCoef2 * Point());
if(InpCloseTradeBy3   == FIXED_STOPLOSS)
   orderRequest.sl   = tick.bid + Spread - (InpCoef3 * Point());

Is there a simpler way to tell the EA if fixed stoploss is on InpCloseTradeBy2 variable, it should use data from InpCoef2 variable?

 
Luandre Ezra:

Hi,

I have 3 input variables with enum data type and 3 other variables with double data type.

if I want to use fixed stoploss on InpCloseTradeBy variable I will use InpCoef variable for the input value that I need, so does with InpCloseTradeBy2 with InpCoef2 and InpCloseTradeBy3 with InpCoef3. The problem is that I can use (e.g) Fixed stoploss in one of the close trade by variable.

When I want to open new position, on MqlTradeRequest SL parameter I use this code,

Is there a simpler way to tell the EA if fixed stoploss is on InpCloseTradeBy2 variable, it should use data from InpCoef2 variable?

You could create a new variable on global space (call it iE sl_coef) and assign the value to be used from input to it.

Also, you could use a switch() statement instead of an if() statement.

This way you have only one variable to use when calculating/setting your SL