independant if function

 

hi, here is my problem

//imput section
imput bool Condition 1 =false;
imput bool Condition 2 =false;
imput bool Condition 3 =false;


bool Trade filter()
  {

// All the variables and declarations here

if (X && Condition 1) tradingallowed=True;
if (Y && Condition 2) tradingallowed=True;
if (Z && Condition 
3 ) tradingallowed=True;
return tradingallowed;
}

in this case, how can i set all if function to run independently? when i test, i found out that two if function can't run at the same time, if i use "else" all function get executed without taking into consideration the input bool variable. if separate each of them in different function (Bool trade filter) it greatly affects my variables and the returned variables.

i would like each if function to be executed separately, no matter how many is active at the same time. Thanks

 
Create a flowchart and then program what you have drawn.
 
Carl Schreiber #:
Create a flowchart and then program what you have drawn.
I think that's a little bit sloppy as an answer. Doesn't even animate or guide into the right direction.
 
Sie Samuel Roland Youl:

hi, here is my problem

in this case, how can i set all if function to run independently? when i test, i found out that two if function can't run at the same time, if i use "else" all function get executed without taking into consideration the input bool variable. if separate each of them in different function (Bool trade filter) it greatly affects my variables and the returned variables.

i would like each if function to be executed separately, no matter how many is active at the same time. Thanks

What exactly do you mean with "at the same time"?

This is not possible, you always need one after the other.

The main question is, what do you want to achieve. It is not clear to me, and I cannot extrapolate from what you have written.

Please clarify your goal and requirements.
 
Dominik Christian Egert #:
I think that's a little bit sloppy as an answer. Doesn't even animate or guide into the right direction.
I disagree that is how non programmers should learn programming.   Define what you want.  Programme what you defined

The answer the OP needs is to integrate OR Statements but will they understand that 
 

ok, i will explain it more in detail. I'm trying to write a trading days function so that the ea can only trade on the choosen days.

//--------- Imput Section

input bool               InpTimeControl             = false;             // Use time control
input bool               Monday                     = false;             // Monday
input bool               Tuesday                    = false;             // Tuesday
input bool               Wednesday               = false;             // Wednesday
input bool               Thursday                  = false;             // Thursday
input bool               Friday                      = false;             // Friday
input bool               Saturday                  = false;             // Saturday
input bool               Sunday                     = false;             // Sunday



//------ The main function is bool and return a variable


//+------------------------------------------------------------------+
//|    CheckTradingTime                                              |
//+------------------------------------------------------------------+
bool TimeControlHourMinute()
{
      
     
// i have already defined all variables used, days of the week are ok, server times also.

if(DayOfTheWeek==1) WeekDay="Monday";
if(DayOfTheWeek==2) WeekDay="Tuesday";
if(DayOfTheWeek==3) WeekDay="Wednesday";
if(DayOfTheWeek==4) WeekDay="Thursday";
if(DayOfTheWeek==5) WeekDay="Friday";
if(DayOfTheWeek==6) WeekDay="Saturday";
if(DayOfTheWeek==0) WeekDay="Sunday";

Comment ( "The Date is ",YearAndDate,"\n",
          "Today is ",WeekDay,"\n",
          "The time is ",HoursAndMinutes,"\n"
          "TradingIsAllowed= ",TradingAllowed,"\n",
          "Current Time = ", CurrenTime,"\n");


// Monday Statement
if(Monday){
if(DayOfTheWeek==1)
TradingAllowed=true;
if(DayOfTheWeek !=1)
TradingAllowed=false;
}

if(Tuesday){
if(DayOfTheWeek==2)
TradingAllowed=true;
if(DayOfTheWeek !=2)
TradingAllowed=false;
}

if(Wednesday){
if(DayOfTheWeek==3)
TradingAllowed=true;
if(DayOfTheWeek !=3)
TradingAllowed=false;
}

if(Thursday){
if(DayOfTheWeek==4)
TradingAllowed=true;
if(DayOfTheWeek !=4)
TradingAllowed=false;
}


if(Friday){
if(DayOfTheWeek==4)
TradingAllowed=true;
if(DayOfTheWeek !=4)
TradingAllowed=false;
}

if(Saturday){
if(DayOfTheWeek==5)
TradingAllowed=true;
if(DayOfTheWeek !=5)
TradingAllowed=false;
}

if(Sunday){
if(DayOfTheWeek==0)
TradingAllowed=true;
if(DayOfTheWeek !=0)
TradingAllowed=false;
}
// Return the result to the main function
return TradingAllowed;


}

The function are basically ok, before to open a trade, if InpTimeControl, then the ea will check which day is allowed or not. but the function stop working when more than one day is set true, however suppose if you choose to trade only on Monday, the function will work extremely weel, if you decided to trade only on Monday and another day, the function stop working, and after many tests i have realize that each day work well when they only one activated at the time.

 
Sie Samuel Roland Youl #:

ok, i will explain it more in detail. I'm trying to write a trading days function so that the ea can only trade on the choosen days.

The function are basically ok, before to open a trade, if InpTimeControl, then the ea will check which day is allowed or not. but the function stop working when more than one day is set true, however suppose if you choose to trade only on Monday, the function will work extremely weel, if you decided to trade only on Monday and another day, the function stop working, and after many tests i have realize that each day work well when they only one activated at the time.

if I understood, this is all you need:

if(DayOfTheWeek==1) { WeekDay="Monday"; TradingAllowed = Monday; }
 
Dominik Christian Egert #:
{ WeekDay="Monday"; TradingAllowed = true; }

ii have tried your proposition but it still not working

 
Sie Samuel Roland Youl #:

ii have tried your proposition but it still not working

More details please.

Show all relevant code.
 
Sie Samuel Roland Youl #:

ok, i will explain it more in detail. I'm trying to write a trading days function so that the ea can only trade on the choosen days.

The function are basically ok, before to open a trade, if InpTimeControl, then the ea will check which day is allowed or not. but the function stop working when more than one day is set true, however suppose if you choose to trade only on Monday, the function will work extremely weel, if you decided to trade only on Monday and another day, the function stop working, and after many tests i have realize that each day work well when they only one activated at the time.

do things only once when you can it is easier to code and understand...

TradingAllowed=false;   // do this once

if(Monday && DayOfTheWeek==1) TradingAllowed=true;
if(Tuesday && DayOfTheWeek==2) TradingAllowed=true;
if(Wednesday && DayOfTheWeek==3) TradingAllowed=true;
// etc....

// or simplify again....

if((Monday && DayOfTheWeek==1) || (Tuesday && DayOfTheWeek==2) || (Wednesday && DayOfTheWeek==3)) TradingAllowed=true;

//  or use a switch statement
 
Paul Anscombe #:

do things only once when you can it is easier to code and understand...

Could be simplified to

TradingAllowed = (Monday && DayOfTheWeek==1) || (Tuesday && DayOfTheWeek==2) || (Wednesday && DayOfTheWeek==3);