Help with an EA - one variable seems to counteract another statement - page 2

 
RaptorUK:
You can't do anything simultaneously with mql4,  it is purely serial.  Have you checked if BarCheck is returning true and false correctly ?


Yes I think it is.

In the example of the Print variables in my first post, I am expecting a buy trade.

The first two lines where the Ask is less than the EL Barcheck = true (as expected)

then when Ask does become greater then EL, which would be needed for the 2nd criteria, it also invalidates the 1st criteria as is resets Barcheck to false.

 

Kinda catch22 :)

 
simoncs:


Yes I think it is.

In the example of the Print variables in my first post, I am expecting a buy trade.

The first two lines where the Ask is less than the EL Barcheck = true (as expected)

then when Ask does become greater then EL, which would be needed for the 2nd criteria, it also invalidates the 1st criteria as is resets Barcheck to false.

If your strategy says  if  Ask< EL  and Ask > EL  Buy then you aren't ever going to Buy.  Are you clear on what your strategy is ? many people are not and wonder why they lack consistency . . . 
 
RaptorUK:
If your strategy says  if  Ask< EL  and Ask > EL  Buy then you aren't ever going to Buy.  Are you clear on what your strategy is ? many people are not and wonder why they lack consistency . . . 


yup, pretty clear. Just must be the way I am explaining this, sorry

Price has to first move into the zone to validate the trade (BarCheck) then once this has been fulfilled, the moment price leaves the zone again I want to take a trade.

Have drawn a quick pic if that helps? 

In this example it would be a buy trade and the top of the box is EL.

Therefore initially for barcheck to be true the Ask must be less than EL.

And then the 2nd criteria is when Ask is greater than EL.

Can this be achieved if i have these criteria separate? I was trying to put most of the code in functions and then just bring it together in the start function, but I am getting the feeling, these two criteria need to either be in the same function, or just laid out sequentially in the start function? Is it because I have created a bool function for part of the criteria, it is just making it difficult for myself, or can this all be bought together somehow using a loop?

 

 
simoncs:


yup, pretty clear. Just must be the way I am explaining this, sorry

Price has to first move into the zone to validate the trade (BarCheck) then once this has been fulfilled, the moment price leaves the zone again I want to take a trade.

After BarCheck is validated what invalidates it ? 
 
RaptorUK:
After BarCheck is validated what invalidates it ? 


Price again.

I need the ask price to be less than EL to confirm the zone in the first instance.

But as soon as it is greater than  EL, which it needs to be to fulfill the 2nd criteria, it then invalidates Barcheck. -hence the catch22

 
simoncs:


Price again.

I need the ask price to be less than EL to confirm the zone in the first instance.

But as soon as it is greater than  EL, which it needs to be to fulfill the 2nd criteria, it then invalidates Barcheck. -hence the catch22

Well you have an unworkable strategy . . .  if it is indeed as you have just described.  You can't code an unworkable strategy . . . I suspect that you aren't describing your strategy correctly though.   It's easy enough to set a bool and keep it set for the BarCheck condition . . .  but you need a condition that tells you to un check it otherwise it is permanently true and pointless.
 
RaptorUK:
Well you have an unworkable strategy . . .  if it is indeed as you have just described.  You can't code an unworkable strategy . . . I suspect that you aren't describing your strategy correctly though.   It's easy enough to set a bool and keep it set for the BarCheck condition . . .  but you need a condition that tells you to un check it otherwise it is permanently true and pointless.

Sorry for delayed response the forum seemed to stop working last night - i just got a bunch of Russian text?


The strategy is workable, and I am sure others have similar. It's just the way that I have coded it, and that is my question. How can I have these two conditions work together.

I need to meet the first condition, and then as soon as that is met I need to meet the second condition. 

 
simoncs:

Sorry for delayed response the forum seemed to stop working last night - i just got a bunch of Russian text?


The strategy is workable, and I am sure others have similar. It's just the way that I have coded it, and that is my question. How can I have these two conditions work together.

I need to meet the first condition, and then as soon as that is met I need to meet the second condition. 

Draw a flowchart and code from that.
 
RaptorUK:
Draw a flowchart and code from that.


That's what i did initially. After reading several courses and watching the tutorials on youtube, i decided to try to use the approach of setting everything in functions, that could just be called.

That seems to have worked against me with this Barcheck function, So i have spent the whole day trying various options without the function. So basically a series of if statements based on the flowchart I drew, but that still doesn't seem to help me.

This was my latest attempt...

I just can't work out how logically I can go from validating the trade by price moving into the zone (Ask being less than the EL line), and then taking the trade when Ask is greater than the EL line all potentially on the same bar. 

if(Trend == UpTrend && OrdersTotal()<1 && OrdersTotal()!= -1 )
    {
    if (OrderOpened <1)
      
       if (EL - buyprice > Point/2 && Fib73Line - buyprice <Point/2) // price is in this zone to validate the setup
      
         if (EL - buyprice < Point/2) //price moves out of the zone to initiate a buy
            OpenBuyOrder(LotSize,SL,TP);
    }
    if (OrdersTotal()>0){OrderOpened=1;}
 
simoncs:


That's what i did initially. After reading several courses and watching the tutorials on youtube, i decided to try to use the approach of setting everything in functions, that could just be called.

That seems to have worked against me with this Barcheck function, So i have spent the whole day trying various options without the function. So basically a series of if statements based on the flowchart I drew, but that still doesn't seem to help me.

You seem to be missing my point . . .

You said . . .

 // price is in this zone to validate the setup
      
 //price moves out of the zone to initiate a buy

  . . .   you need to remember that price has passed into and out of the zone to initiate a buy,  but this may have happened 4 days ago so you need to know when to forget that the price has passed into and out of the zone,  hence my question earlier in this thread about when the condition is invalided so that you can "forget" that price went into and out of the zone.  Don't think about code,  get the logic right first . . .

Reason: