Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 236

 
ALXIMIKS:

no Alert from this script. Else refers to the condition " if (5>3){Alert ("AAAAAAAAAAAAAAAAAAAAAAAAAA"); a=5;} "

Acknowledgments :

have anAlert: "a=0".

The result is that the non-condition handling is only possible for the last condition when the curly brackets "{" are not used during the enumeration of a certain series of conditions.

That's right, the logic works, just don't put everything in one row:

int start(){
 int a=0;
 if (3>3)
    if (5>3)
       if (5>3){Alert ("AAAAAAAAAAAAAAAAAAAAAAA"); a=5;}
       else Alert ("a=", a);
}
then it will become clearer. Parentheses are needed if if is true: {operator1;operator2;operatorN}. If there is only one operator, the curly brackets can be omitted, and since the operator is also a condition, everything is repeated.
 
artmedia70:

That is, brackets are needed to organise logical branches. Without them, the first condition is basic. If it is not true, the other conditions will not be fulfilled.

Try to work it out:

And after that, figure out what else it refers to:


else refers to " if (b>c)"
 

Hello.

if (DayOfWeek()==DayOfWeekIf
  && TimeCurrent()>=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE)+" "+TimeTradeIf)
  && TimeCurrent()<StrToTime(TimeToStr(TimeCurrent(), TIME_DATE)+" "+TimeTradeIf)+Duration)
   {
    if  (iClose("XAUUSD",PERIOD_H1,0)-iOpen("XAUUSD",PERIOD_H1,0)>=0)
    Sell = true;
    if  (iOpen("XAUUSD",PERIOD_H1,0)-iClose("XAUUSD",PERIOD_H1,0)>0)
    Sell =false;
   }
  if (DayOfWeek()==DayOfWeekOpen
  && TimeCurrent()>=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE)+" "+TimeTradeOpen)
  && TimeCurrent()<StrToTime(TimeToStr(TimeCurrent(), TIME_DATE)+" "+TimeTradeOpen)+Duration)
  {...

The idea is this: if a candle is bullish on such a day at such a time, then sell = true, if bearish, then false. Then on such and such a day at such and such a time we sell, if sell=true and buy, if vice versa.

But the condition does not work for some reason, all trades are opened for sell. I am testing it on M1.

 
ALXIMIKS:

else refers to " if (b>c) ".

Correct.

if (a>b)
   if (b>c) 
      Alert(" условие if (a>b && b>c) выполнено ");
   else if (d>e) 
      if (e>f) 
         Alert(" условие if (d>e && e>f) выполнено");

Now try to make logic without curly brackets:

If (a>b), then the lines if (b>c) Alert() are executed;

Otherwise if (d>e), then lines if (e>f) Alert() are executed;

In other words: make else refer to the very first condition. Without using curly braces.

 
Antonius:

Hello.

The idea is this: if a candle is bullish on such a day at such a time, then sell = true, if bearish, then false. Then on such and such a day at such and such a time we sell, if sell=true and buy, if vice versa.

But the condition does not work for some reason, all trades are opened for sell. I have tested it on M1.

I am sure it is this part of the code. From what you have shown it is difficult to draw conclusions - there are a lot of unknown variables and opening itself is not visible.

To find the reason yourself, print or display the values of the variables with comments. Then you can see their values at any time.

 
Antonius:

Hello.

The idea is this: if a candle is bullish on such a day at such a time, then sell = true, if bearish, then false. Then on such and such a day at such and such a time we sell, if sell=true and buy, if vice versa.

But the condition does not work for some reason, all trades are opened for sell. I am testing it on M1.

Is it possible to compare like this? I don't like the right part ("type conversion there will put everything in a string with the value "yyyy.mm.dd "TimeTradeIf")??
 TimeCurrent()>=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE)+" "+TimeTradeIf
 
ALXIMIKS:
I don't like the right part ("yyyy.mm.dd "TimeTradeIf" value will be converted into a string)?

You can see that the TimeTradeIf value is added to the calculated value. Who told you and showed you exactly what is contained in TimeTradeIf ?

That's what I wrote to the person that there are a lot of unknown and unclear values to look for the problem in his code.

 
artmedia70:

Correct.

Now try to make logic without curly brackets:

If (a>b), then the lines if (b>c) Alert() are executed;

Otherwise if (d>e), then lines if (e>f) Alert() are executed;

In other words: make else refer to the very first condition. Without curly brackets.


if (a>b)
   if (b>c) Alert(" условие if (a>b && b>c) выполнено ");
   else; 
else 
   if (d>e) 
      if (e>f)Alert(" условие if (d>e && e>f) выполнено");

Taki did it, it's not very convenient for reading logic, if without braces, and compiler still a little bit rubs ";' - semicolon unexpected "

but still alerts "condition if (d>e && e>f) is satisfied" when a>bis not satisfied .(if that's how I understood the task).


 
Antonius:

Hello.

The idea is this: if a candle is bullish on such a day at such a time, then sell = true, if bearish, then false. Then on such and such a day at such and such a time we sell, if sell=true and buy, if vice versa.

But the condition does not work for some reason, all trades are opened for sell. I am testing it on M1.


In my opinion, the calculation starts at the beginning of the zero bar, when the opening is still equal to the closing and of course the difference is 0. I have to check the previous bar.
 

Hello, gentlemen programmers.

I'm too lazy to look into the tutorial. Maybe you know what should be changed in your Expert Advisor so that it would apply money management in 0.01 step instead of 0.1

Files:
Reason: