Unexpected order

 

Hello,

Among other conditions this condition has to be true in order for the EA to place an order. However, this condition isn't true and the order is placed while testing!

iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,1)==0

What is wrong?!! Result picture is attached to further illustrate

Files:
Capture.PNG  4 kb
 
matrixyb: Among other conditions this condition has to be true in order for the EA to place an order. However, this condition isn't true and the order is placed while testing! What is wrong?!! Result picture is attached to further illustrate

You will never find a fractal at bar shift 0 nor 1. Sometimes you may find it at 2, but not always. The only correct shift to search for a fractal is at bar shift 3.

That is because the definition of a fractal is that be at least 2 bars on each shoulder and bar 0 is the current bar which is still incomplete and does not count.

Also you should detect for a non "EMPTY_VALUE" and not for 0.

EDIT: Corrected my post in accordance with posts #11 and #12
 
Fernando Carreiro #:

You will never find a fractal at bar shift 0 nor 1. Sometimes you may find it at 2, but not always. The only correct shift to search for a fractal is at bar shift 3.

That is because the definition of a fractal is that be at least 2 bars on each shoulder and bar 0 is the current bar which is still incomplete and does not count.

Also you should detect for a non "EMPTY_VALUE" and not for 0.


Should I go like this?

iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,1)==EMPTY_VALUE
 
Fernando Carreiro #:

You will never find a fractal at bar shift 0 nor 1. Sometimes you may find it at 2, but not always. The only correct shift to search for a fractal is at bar shift 3.

That is because the definition of a fractal is that be at least 2 bars on each shoulder and bar 0 is the current bar which is still incomplete and does not count.

Also you should detect for a non "EMPTY_VALUE" and not for 0.

What about the ones that has values??

iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,1)>0

??

 
matrixyb #: Should I go like this?

Did I not just say that you will never find a fractal at bar shift 1?

if( iFractals( _Symbol, _Period, MODE_LOWER, 3 ) != EMPTY_VALUE )
{
   // Lower fractal found
};

However, since doubles don't always "equal", I prefer the following, but the choice is yours:

if( iFractals( _Symbol, _Period, MODE_LOWER, 3 ) < EMPTY_VALUE )
{
   // Lower fractal found
};

EDIT: Corrected my post in accordance with posts #11 and #12

if( iFractals( _Symbol, _Period, MODE_LOWER, 3 ) > 0 )
{
   // Lower fractal found
};

Unexpected order
Unexpected order
  • 2022.06.26
  • www.mql5.com
Hello, Among other conditions this condition has to be true in order for the EA to place an order...
 
Fernando Carreiro #:

Did I not just say that you will never find a fractal at bar shift 1?

However, since double don't always "equal", I prefer the following, but the choice is yours:

Still didn't work as expected.


if((iFractals(_Symbol,PERIOD_CURRENT,MODE_UPPER,1)>EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,1)!=EMPTY_VALUE)
            || (iFractals(_Symbol,PERIOD_CURRENT,MODE_UPPER,2)>EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,1)!=EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,2)!=EMPTY_VALUE)
            || (iFractals(_Symbol,PERIOD_CURRENT,MODE_UPPER,3)>EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,1)!=EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,2)!=EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,3)!=EMPTY_VALUE)
            || (iFractals(_Symbol,PERIOD_CURRENT,MODE_UPPER,4)>EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,1)!=EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,2)!=EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,3)!=EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,4)!=EMPTY_VALUE)
            || (iFractals(_Symbol,PERIOD_CURRENT,MODE_UPPER,5)>EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,1)!=EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,2)!=EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,3)!=EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,4)!=EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,5)!=EMPTY_VALUE)))
{
OrderSend ....
}

Still sends an order while fractal shift 1 has value. Same picture as before

 
matrixyb #: Still didn't work as expected. Still sends an order while fractal shift 1 has value. Same picture as before

You are not paying attention. Look at my code again. Read it properly.

It is bar shift 3, not 1 and it is "less than"/"<" not "greater than"/">".

if( ( iFractals( _Symbol, _Period, MODE_UPPER, 3 ) < EMPTY_VALUE ) ||
    ( iFractals( _Symbol, _Period, MODE_LOWER, 3 ) < EMPTY_VALUE )    )
{
   // OrderSend ....
};

It is also "or"/"||" and not "and"/"&&".

EDIT: Corrected my post in accordance with posts #11 and #12

if( ( iFractals( _Symbol, _Period, MODE_UPPER, 3 ) > 0 ) ||
    ( iFractals( _Symbol, _Period, MODE_LOWER, 3 ) > 0 )    )
{
   // OrderSend ....
};
 
Fernando Carreiro #:

You are not paying attention. Look at my code again. Read it properly.

It is bar shift 3, not 1 and it is "less than"/"<" not "greater than"/">".

It is also "or"/"||" and not "and"/"&&".

I understood you pefectly and everything should go fine however I still didn't get the result I wants. Maybe the error elsewhere. Maybe the way I use || is wrong!

Now If I want to check weather I have one of the two conditions (A>B and B>C) or (A<B and B>C) is this the correct way to type it?

if( (A>B && B>C)
  || (A<B && B>C))
{
OrderSend ....
}
 
matrixyb #: I understood you pefectly and everything should go fine however I still didn't get the result I wants.

No, your code example was clearly wrong and I gave you the correction.

matrixyb #: Maybe the error elsewhere. Maybe the way I use || is wrong!

There may be, but that is besides the point I have already pointed out.

EDIT: You will have to show your complete code if you want further guidance.

matrixyb #: Now If I want to check weather I have one of the two conditions (A>B and B>C) or (A<B and B>C) is this the correct way to type it?

Yes, I would assume so, but that is an abstract example and I have no ideia what you are really testing for. So my "yes" answer is based on limited information.

 

Ok one more time again and extra details.

For a selling signal, I want to write a code to check if a fractal downward signal was appeared sometime during the last 4 candles and no upward signals in between.

I have this code for it, which I believe is perfect.

if(((iFractals(_Symbol,PERIOD_CURRENT,MODE_UPPER,1)< EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,1)!=EMPTY_VALUE)
            || (iFractals(_Symbol,PERIOD_CURRENT,MODE_UPPER,2)< EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,1)!=EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,2)!=EMPTY_VALUE)
            || (iFractals(_Symbol,PERIOD_CURRENT,MODE_UPPER,3)< EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,1)!=EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,2)!=EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,3)!=EMPTY_VALUE)
            || (iFractals(_Symbol,PERIOD_CURRENT,MODE_UPPER,4)< EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,1)!=EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,2)!=EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,3)!=EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,4)!=EMPTY_VALUE)
            || (iFractals(_Symbol,PERIOD_CURRENT,MODE_UPPER,5)< EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,1)!=EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,2)!=EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,3)!=EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,4)!=EMPTY_VALUE && iFractals(_Symbol,PERIOD_CURRENT,MODE_LOWER,5)!=EMPTY_VALUE)))
{
OrderSend....
}

But if I run the EA and have the situation on the attachment picture a selling order is placed while a fractal downward signal is appeared which unsatisfies the conditions in above code. Why is this? the selling order is placed.

Files:
Capture.PNG  4 kb
 
matrixyb #:

Ok one more time again and extra details.

For a selling signal, I want to write a code to check if a fractal downward signal was appeared sometime during the last 4 candles and no upward signals in between.

I have this code for it, which I believe is perfect.

But if I run the EA and have the situation on the attachment picture a selling order is placed while a fractal downward signal is appeared which unsatisfies the conditions in above code. Why is this? the selling order is placed.

How many times do I have to say this! You will NEVER find a fractal at bar shift 0 or 1.

At 2 — it is tentative and not confirmed.

At 3 — it is confirmed and you should use it at 3.

At 4,5,... etc. — You have already confirmed it at 3 and there no longer any need to test for it again.

Don't use "&&" (and), for both the upper and lower fractal test, because it seldom happens. It is rare. Use "||" (or) if you want to test for both.

Don't use "&&" (and) for fractals of the same type at consecutive bar shifts. That will not happen as that would violate the definition of a fractal.

If you want to detect a fractal in the opposite direction of a previous fractal within a certain bar count, then keep a running track record of previous detections. Don't just lump everything up in "&&"s and "||"s. which is messy and easily results in the wrong logic.

Reason: