Check - what have I done wrong? - page 6

 
Nikolai Semko #:

Yes, Natalia - that was just a "When they pay you for a line of code" meme.

That's the kind of humor programmers have.


You don't need a function in your case.

You just need to form the variables Volume1 ... Volume10 first form an array Volume[10]
and then use index n to refer to its items volume[n].
Do not worry - almost every programmer has gone through this.
The main thing is that you really like programming. I can feel it.
So you'll go far.

Tell me how to write it nicely. I do not want to duplicate arrays of code.
The Expert Advisor uses 2 indicators.
and conditions for order opening look like this now:

if (Indicator1 > 0 && Indicator2 > 0)
{
OrderSend
}


But I would like to add a filter in settings
Use or not use 1 or 2 indicators
Only I don't know how to implement it more correctly.
It would look something like this:

if (Indicator1 && Indicator1 > 0)
{
if (Indicator2 && Indicator2 > 0) || (Indicator2 == false)
{
///
}
}



if (Indicator2 && Indicator2 > 0)
{
if (Indicator1 && Indicator1 > 0) || (Indicator1 == false)
{
///
}
}
so that I can disable 1 indicator or the second indicator in the settings.
Can't figure out how to do it without copying a lot of code.....
 
Natalya Smirnova #:

Please advise how to write it nicely. So as not to duplicate code arrays.
The Expert Advisor uses 2 indicators.
and conditions for order opening look like this now:


But I would like to add filter
Use or not use 1 or 2 indicators
Only I don't know how to implement it more correctly.
It would look like this:

That I could turn off 1 indicator or the other in the settings.
Can't figure out how to do it without copying a lot of code.....

I have written a bit about it here: https://www.mql5.com/ru/forum/6343/page1384#comment_26447195

 
JRandomTrader #:

I have written a little on the subject here: https://www.mql5.com/ru/forum/6343/page1384#comment_26447195

Thank you, I'm off to do some research.
 

Natalya Smirnova #:

so that I can disable 1 indicator or the second indicator in the settings.
I can't figure out how to do it without copying a lot of code.....


input bool indicator_1 = true;
input bool indicator_2 = true;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool F_1()
    {
     if(!indicator_1)
          return true;
// выполнение условий

//---
     return false;
    }
bool F_2()
    {
     if(!indicator_2)
          return true;
// выполнение условий

//---
     return false;
    }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart(void)
    {
     if(F_1 && F2) /* работаем */ ;
    }

Write the condition of the indicator in the function and if it should not be checked, then the condition is fulfilled. Return TRUE.

 
Natalya Smirnova #:

Please advise how to write it nicely. So as not to duplicate code arrays.
The Expert Advisor uses 2 indicators.
and conditions for order opening look like this now:


But I would like to add filter
Use or not use 1 or 2 indicators
Only I don't know how to implement it more correctly.
It would look like this:

That I could disable 1 indicator or the second indicator in the settings.
I can't figure out how to do it without copying a lot of code.....

Still the variable for the use condition and the variable for the output value of the indicator should be different variables.
And if the variables for the use condition will be ind_1 and ind_2, then, for example, you could do this:

ind_1 = !(ind_1 && !(Indicator1>0));
ind_2 = !(ind_2 && !(Indicator2>0));
if (ind_1 && ind_2) { OrderSend... };
Just in case: Exclamation mark means inversion of bool value
 
Nikolai Semko #:

Still, the variable for the use condition and the variable for the output value of the indicator should be different variables.
And if variables for use condition will be ind_1 and ind_2, then, for example, we can do this:

ind_1 = !(ind_1 && !(Indicator1>0));

the abundance of brackets and inversions in the logical expression sort of suggests that one could simplify...

PS/ architecturally it's a slag in general. If indicator readings can be grouped without any trading factors (regardless of where you opened what), then it's an indicator and it has nothing to do with robot's trading logic. It has to be rendered and available for analysis.

 
Maxim Kuznetsov #:

The abundance of brackets and inversions in the logic expression sort of suggests that it can be simplified...

Maybe.
What are the options for logic ab
0 0 = 1
0 1 = 1
1 0 = 0
1 1 = 1
Except !(a && !b)
Can anyone find shorter logic...

 
Maxim Kuznetsov #:

PS/ Architecturally, it's a slag. If indicator readings can be grouped together without any trading factors (regardless of where you opened what), then it's an indicator and has no place in a robot's trading logic. It has to be rendered and available for analysis.

I did not understand it.
Just answering a question. Not more.
 
Nikolai Semko #:
Maybe.
What are the options for logic ab
0 0 = 1
0 1 = 1
1 0 = 0
1 1 = 1
Except !(a && !b)
Can anyone find a shorter logic...

!a || b

:)

 
PapaYozh #:

!a || b

:)

Right.
Thank you :))
Funny. Tried to attach XOR and forgot about OR.

So a shorter version:
ind_1 = !ind_1 || Indicator1>0;
ind_2 = !ind_2 || Indicator2>0;
if (ind_1 && ind_2) { OrderSend... };
or single-line version with original ind_1 and ind_2 preserved

if ((!ind_1 || Indicator1>0) && (!ind_2 || Indicator2>0)) { OrderSend... };