EA only opens a trade at the opening in a new bar and not during a bar

 

Hello everybody,

I'm making a EA atm but I have a small problem and I can't figure it out where the problem is.

The is EA working with a two rules and the second rule is that it must wait until the current price has crossed a price in the history what is been saved in a variable.

But the EA isn't doing that I doesn't wait until the current price has crossed the price in the history but opens the trade when the first rule is met and opens then a trade when a new bar has been opened. But the chance that the opening bar is the crossing of the price in history is 1%. So the EA should open a trade somewhere in a bar.

Files:
fabje.mq4  40 kb
 

F

> what is been saved in a variable

Which variable?

Might be quicker to ask whoever coded this to confirm the intended strategy?

-BB-

 
BarrowBoy:

F

> what is been saved in a variable

Which variable?

Might be quicker to ask whoever coded this to confirm the intended strategy?

-BB-


I don't know what you mean?

Anyway I added the compleet code.

At line 288 the the rules of the EA begin.

Files:
fabje_2.mq4  41 kb
 

After a quick read through this amount of code...

I would say the problem is that piviot_low_hit is declared and initialized (i.e. as false) every tick but is only set to true on a new bar

FWIW

-BB-

 
BarrowBoy:

After a quick read through this amount of code...

I would say the problem is that piviot_low_hit is declared and initialized (i.e. as false) every tick but is only set to true on a new bar

FWIW

-BB-

Well for the first rule it must check everything when a new bar opens as soon as everything is ok for rule1 I set the piviot_low_hit on true.

And also it sets the price of the lower low of bar 5 in the variable price_low_5.

After that it needs to wait until the current price crossed the price in the variable price_low_5.

When that happens it needs to open a SELL. And it will reset the piviot_low_hit to false.

I also edited the code a little bit so it will reset piviot_low_hit back to false, I forget that :p

Files:
fabje_3.mq4  41 kb
 

> And it will reset the piviot_low_hit to false.

Thats needed but is not the basic problem which remains that piviot_low_hit is set to false by being declared every tick and hence is false until the first tick of the new bar and is only true for the first tick of that new bar

-BB-

 
BarrowBoy:

> And it will reset the piviot_low_hit to false.

Thats needed but is not the basic problem which remains that piviot_low_hit is set to false by being declared every tick and hence is false until the first tick of the new bar and is only true for the first tick of that new bar

-BB-

I don't agree with you about that.

Because piviot_low_hit will be true until the sell order has been started. When this is done piviot_low_hit will be set on false.

Can you maybe edit the code as you think it must be? Or someone else :p

 

So declare the variable up with the other statics at the top of the EA, prior to the init() function

static bool piviot_low_hit;

-BB-

 
BarrowBoy:

So declare the variable up with the other statics at the top of the EA, prior to the init() function

-BB-

That doesn't solve the problem :(
Files:
fabje_5.mq4  41 kb
 
BarrowBoy:

So declare the variable up with the other statics at the top of the EA, prior to the init() function

-BB-


& u have to take care

void reset() {
        bool piviot_low_hit = false;
}
 
qjol:


& u have to take care


What do you mean? What should I do with that? I set piviot_low_hit already before the init() function.

Reason: