| New signals service! | |
|
|||||||
| Register in Forex TSD! | |
|
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time). Click here to register and get more information |
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
||||
|
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. |
|
||||
|
Quote:
In which the same question (and answer...:-) was discussed. Cheers, Herbert
__________________
Better being out, wishing to be in than being in and wishing to be out..... |
|
||||
|
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: http://www.forex-tsd.com/132491-post25.html Thanks. |
|
||||
|
Quote:
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
__________________
Better being out, wishing to be in than being in and wishing to be out..... |
|
||||
|
I added the code as follows:
-------------------------- [other variables here] datetime Timestamp = 0; //+------------------------------------------------------------------+ //| Expert Initialization | //+------------------------------------------------------------------+ int init() { LastPrice = Bid; 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. Last edited by WNW; 10-01-2007 at 10:58 PM. |
|
||||
|
Quote:
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
__________________
Better being out, wishing to be in than being in and wishing to be out..... |
|
||||
|
Quote:
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. |
|
||||
|
Quote:
For example: Code:
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
}
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?
__________________
Better being out, wishing to be in than being in and wishing to be out..... |
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using Gannswing to open trade | gee | Expert Advisors - Metatrader 4 | 1 | 02-15-2007 09:00 PM |
| Restarting EA with current open trade | dwmcqueen | Metatrader 4 | 5 | 01-26-2007 04:29 AM |
| script open trade | BrunoFX | Tools and utilities | 6 | 05-21-2006 11:08 PM |