|
|||||||
| 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 |
|
|||
|
Multiple trades per bar?
Hi Everyone! I am working on learning MQ4, and I had a couple of questions I hope someone can help me out with.
I have been studying the great MQL4 Course by the Guru, and I have been experimenting with backtesting. When I look at the chart of a backtest I see several bars that have multiple open and close triangles on them. For example (on the same bar) it will have open buy#3, close buy#3, and then open buy#4. I am assuming that what is happening is that the price has an up tick and then a down tick which makes the cross positive, then uncrossed, then crossed again which results in the multiple buys and closes. Is this what is actually happening? If that is what is occurring, how can I make the EA wait until the finish of a bar to initiate a trade, or how can I make it only initiate one trade per bar? Thanks very much for your help! Trep |
|
|||
|
What you need to do is to have a "static" variable which is something like
"bool ITradedOnThisBar;" Which is cleared to 'false' every time you have a new bar, and set to "true" whenever each new trade is signaled. You check for a new bar by saving the Bar time, e.g. Time[0]; into a variable (check for the right data type) also static or declared globally. Then when you enter start(), which happens on each new tick, you then check the present Time[0] and compare---if unequal there is a new bar. You can set a boolean variable for that too. I |
|
|||
|
Hi! Thanks for your reply.
I have been working on adding what you suggested, but this whole thing is becoming frustrating! Look at the attached picture: it is the EA that Coders’ Guru used for his lesson, and it does not work at all. It opens and closes multiple trades next to each other, and it opens shorts when it should be opening longs. Am I doing something wrong, or does this code not work on backtest? Thanks, Trep |
|
|||
|
Quote:
Code:
// Go trading only for first tick of new bar if(Volume[0]>1) return(0); // or else exit I notice that when the short EMA and the long EMA hover near each other for a period of time, it would be nice to have a crossover system wait before making a change until there is a significant breakout either up or down.
__________________
Regards, Dean |
|
||||
|
Quote:
when we get a buy signal, the fastEMA crossed the SLowEMA from down, so the close time would be whenever FastEMA cross SlowEMA from up for simpler coding i write a few code for checking EMA direction, when the EA wants to close the order, EMA direction must be Oposite Open condition
__________________
there wil be nothig for a person exept his efforts (Emam Ali Alayhesalam) M.A.Gh |
|
|||
|
Great! Anyone knows the coding for opening a trade from the first inital cross of the fast EMA with the Slow EMA until the next opposite crossing; anyone figured out the coding for that one...
Impressive, thanx for your input; brilliant! |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Multiple charts | CiTiFx | Metatrader 4 | 2 | 10-30-2007 08:21 PM |
| Multiple sessions of MT4 | pip-gandalf | Metatrader 4 | 4 | 07-03-2006 12:35 PM |
| Multiple EAs on the same account | einvestor | Metatrader 4 | 2 | 06-14-2006 04:13 PM |
| having trouble with multiple EAs | ycomp | Expert Advisors - Metatrader 4 | 6 | 03-03-2006 04:41 AM |
| multiple timeframes | sailor | Suggestions for Trading Systems | 20 | 02-21-2006 04:04 AM |