Hi, been working on my first EA and it presents this problem, sometimes, the price is moving wildly and, it matches the EAs parameters to open trades (since the price is passing the same bid or ask multiple times in a matter of minutes) So, i was thinking of a way of programming the expert advisor to only place a new order if the last order opened more than for example two hours ago.
been trying to figure it out on reference via order select, but just cant get it to work, any ideas? thanks in advance
hi, you can use the iTime.
First step is to determine on what time frame and how many candle backwards to filter. Here we use PreviousTimeFrame
and MinPreviousCandle.
Then we get the iTime value with TIME_MINUTES format and change iTime (which is
datetime) to string with TimeToStr.
After that we substract the string, because we just want the hour digit, using StringSubstr.
Then
we change the hour digit (which is still in string type) to Integer with StringToInteger so we can substract current time with
previous time.
This is what i have in mind, didn't try yet...
The problem is when : now is 1am, 2 hour before is 11pm, so
the result is -22 (1-23).. still don't know how to solve that
input int MinPreviousCandle = 2; input ENUM_TIMEFRAMES PreviousTimeFrame = PERIOD_H1; int wkt = 0; //in your buy or sell criteria if( **buy criteria* && StringToInteger(StringSubstr (TimeToStr (iTime (NULL,PreviousTimeFrame,0),TIME_MINUTES),0,2)) - wkt >= MinPreviousCandle ) ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, sl, tp, comment, MagicNumber, 0, clrBlue); wkt = StringToInteger(StringSubstr (TimeToStr (iTime (NULL,PreviousTimeFrame,0),TIME_MINUTES),0,2));
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi, been working on my first EA and it presents this problem, sometimes, the price is moving wildly and, it matches the EAs parameters to open trades (since the price is passing the same bid or ask multiple times in a matter of minutes) So, i was thinking of a way of programming the expert advisor to only place a new order if the last order opened more than for example two hours ago.
been trying to figure it out on reference via order select, but just cant get it to work, any ideas? thanks in advance