How to open 1 trade per bar - page 2

 

Coding question: 1 trade per bar?

I'm working on an EA.

When I receive an entry signal, is there a simple way to limit that entry to

only 1 per bar? Some kind of global command?

Oftentimes there are multiple trades around the same area when price continues to retrigger the entry.

Any help appreciated,

Thanks.

 
WNW:
I'm working on an EA.

When I receive an entry signal, is there a simple way to limit that entry to

only 1 per bar? Some kind of global command?

Oftentimes there are multiple trades around the same area when price continues to retrigger the entry.

Any help appreciated,

Thanks.

Hi, take a look in this thread: https://www.mql5.com/en/forum/177514

In which the same question (and answer...:-) was discussed.

Cheers,

Herbert

 

Thanks for your reply.

In reference to your post #3, where is this code placed?

datetime Timestamp = 0;

if(Timestamp != iTime(NULL,0,0))

{

Timestamp = iTime(NULL,0,0);

..your code here..

}

Is it placed jsut before the trading logic?

You referenced this link in the other thread for an example, but it appears to be a dead link:

https://www.mql5.com/en/forum

Thanks.

 
WNW:
Thanks for your reply.

In reference to your post #3, where is this code placed?

datetime Timestamp = 0;

if(Timestamp != iTime(NULL,0,0))

{

Timestamp = iTime(NULL,0,0);

..your code here..

}

Is it placed jsut before the trading logic?

You referenced this link in the other thread for an example, but it appears to be a dead link:

https://www.mql5.com/en/forum

Thanks.

It's a bit difficult to tell you where to put this because I don't know the structure of your expert, but most likely you want this in your Start() body.

Put the "datetime TimeStamp = 0" into the global variables at the top of the EA.

The thread with the example coding has been removed, but if you want an example sent or you want me to look at your Expert, just send me a PM with your email address.

Cheers

 

I'll give that a try, thanks again.

 
WNW:
I added the code as follows:

--------------------------

[other variables here]

datetime Timestamp = 0;

//+------------------------------------------------------------------+

//| Expert Initialization |

//+------------------------------------------------------------------+

int init()

{

LastPrice = Bid;

Anchor = (Ask+Bid)/2;

return(0);

}

//+------------------------------------------------------------------+

//| Expert start |

//+------------------------------------------------------------------+

int start()

{

if(Timestamp != iTime(NULL,0,0))

Timestamp = iTime(NULL,0,0);

------------------------------------

and it's not working; still generating multiple trades.

Have I entered it correctly?

The trade logic comes much farther down in the code; unfortunately the code is copyrighted and I cannot disclose it.

Keep in mind that the example code I provided will restrict only the enclosed portion of your code which then is being handled once every new bar.

If you enclose ALL of the Start() code inside it will not only trigger new trades every new bar, but it will also execute your code looking for breakeven, trailingstop etc. only once a new bar starts.

The simple recepy for using this method is: Enclose only the part of your coding logic that needs to be handled once every new bar.

I understand your copyright situation, but you have to realise mine as well:

I cannot help you any further than this without any insight in (part of) the coding.

Maybe the code snippets in this merged thread will give you new ideas.

Cheers

 
HerbertH:
If you enclose ALL of the Start() code inside it will not only trigger new trades every new bar, but it will also execute your code looking for breakeven, trailingstop etc. only once a new bar starts. The simple recepy for using this method is: Enclose only the part of your coding logic that needs to be handled once every new bar.

Thanks again for your reply.

I'm not a coder and am not familiar with MQL syntax.

When you say "enclose" what does that mean in terms of which characters to use? Can you provide an example?

Thanks.

 
WNW:
Thanks again for your reply.

I'm not a coder and am not familiar with MQL syntax.

When you say "enclose" what does that mean in terms of which characters to use? Can you provide an example?

Thanks.

With enclose I mean putting your code in between the { } brackets of the code snippet I showed you.

For example:

int start()

{

if(Timestamp != iTime(NULL,0,0))

{

Timestamp = iTime(NULL,0,0);

CheckForNewTradeSetup(); // This will be where you put your code which is only allowed to run once every new bar

}

CheckOpenTrades(); // This will be where your code is placed, which will run every tick

}

The example shown above will check to open new trades once every new bar,

but will check existing open trades (e.g. to handle breakeven etc) every tick.

Hope this helps

PS. If you are not a coder and this expert is not functioning properly, why don't you just have the original coder have a look at this?

 
HerbertH:
With enclose I mean putting your code in between the { } brackets of the code snippet I showed you.

For example:

int start()

{

if(Timestamp != iTime(NULL,0,0))

{

Timestamp = iTime(NULL,0,0);

CheckForNewTradeSetup(); // This will be where you put your code which is only allowed to run once every new bar

}

CheckOpenTrades(); // This will be where your code is placed, which will run every tick

}

The example shown above will check to open new trades once every new bar,

but will check existing open trades (e.g. to handle breakeven etc) every tick.

Hope this helps

PS. If you are not a coder and this expert is not functioning properly, why don't you just have the original coder have a look at this?

Thanks much for the explanation, that helps a lot.

Unfortunately the original coder is not interested in making modifications.

 
WNW:
Unfortunately the original coder is not interested in making modifications.

I assume you have asked him/her for a refund then......

Cheers

Reason: