Topic: MQL and nested if statements

I've nested 2 if-statements into 1. No matter what I do, I get entry values taken from 2 days back...

It can't be normal, can it? Because current indi value is correct, therefore when condition is satisfied, it should mark the same indi value as the entry price. But no, MT shows value, which was correct 2 days ago!

A non-working example:

if (ListParam[0].Text == "Continous entry") //entry condition
                    {
                        if (nosignal[bar] != 1) //take only first signal
                        {
                            if (Data.Open[bar] < value[bar]) //if open price below indi value, set up long
                            {
                                Component[1].Value[bar] = value[bar]; //long entry value
                            }
                            else if (Data.Open[bar] > value[bar]) //if open price above indi value, set up short
                            {
                                Component[2].Value[bar] = value[bar]; //short entry value
                            }
                        }
                    }

And this example below works as I get the correct/current numbers on dash.

if (ListParam[0].Text == "Continous entry")
                    {
                        Component[1].Value[bar] = value[bar];
                            
                    }

Re: MQL and nested if statements

The problem must not be in the "if" statements.

Please post the full code.

...

Because I'm an absolute programming maniac, I must say that the problem may be other.
The programming is an art. We have to be positive and dedicated to make it as good as possible and to expect positive results.

By looking at that line:

if (nosignal[bar] != 1) //take only first signal


I see a double negation. It is difficult to expect good results when we approach with a negativism smile.

So I would write this in that way:
nosignal can be signal or isSignalAllowed, or signalBar... where I can store values that allow the entry.
The "!=" may be replaced with "==" (of course if the logic allows)
These make the line looking as:

    if (signal[bar] == 0)

With the positive approach we will find the programming easier and will have more fun.

Re: MQL and nested if statements

smile

Experience with mql has made me prepare for the worst, that's why my approach seems to base on the negative side.

What I'm seeing - indi uses around 50 bars and the first value calculated from that point gets dragged into current bar. Why?

[url]http://s30.postimg.org/omz1laqv5/bal.jpg[/url]



Do I have to assign empty value or null to IndComponentType_OpenLongPrice and IndComponentType_OpenShortPrice if those if statements are not satisified?

Like this:

                                      if (nosignal[bar] != 1)
                        {
                            if (Data.Open[bar] < value[bar])
                            {
                                Component[1].Value[bar] = value[bar];
                            }
                            else if (Data.Open[bar] > value[bar])
                            {
                                Component[2].Value[bar] = value[bar];
                            }
                        }
                                                 else if (nosignal[bar] == 1)
                                                 {
                            Component[1].Value[bar] =  0;
                            Component[2].Value[bar] = 0;
                         }

I remember now it is not the first time I get entry price or entry allowance values dragged to next bars, even though it shouldn't do it.

Re: MQL and nested if statements

Will try this in the evening and post the code if my art is not accepted by the audience (metaquotes art critics wink )

Re: MQL and nested if statements

footon wrote:

Do I have to assign empty value or null to IndComponentType_OpenLongPrice and IndComponentType_OpenShortPrice if those if statements are not satisified?

You have to. Other option is to set the array to zero at the beginning with: ArrayInitialize(Component[1].Value,0);

In MQL when you create an array, it occupies memory with the corresponding size. However it doesn't initialize it. As a result, if there are any old numbers there left from other arrays or whatever variables, they will appear in your new array and will cause bugs.

Re: MQL and nested if statements

The only reason I touch MQL is to make FSB working with MT.
However, not the programming language is the problem but the MT API (the functions they provide for working with the orders and the environment)

Re: MQL and nested if statements

This has been like a masterclass, lessons learnt and chart-art finally corresponds to what I had in mind. Thank you, Miroslav!