[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 29
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello...
I wrote an EA, but ran into this problem:
I have opposite orders and e.g. for BUY I have 150 pips stop and 150 pips profit, for SELL the same levels are set, but only reversed (i.e. what is for buy profit, then for sell stop), i.e. actually I have to close everything simultaneously, both sell with buy and buy with sell..... but there is another thing, spread!))) And from those two opposite orders the other 8 are already opened (of course if all eight are needed, the conditions are different for them, they are also opposite 4/4)
How can I correctly program the code to close all the orders when they reach the same price simultaneously? For in the tester, when I test, the price sometimes reaches a desired level, for example, sell closed (not reaching a predetermined level, I believe it is a spread) and buy hanging and after a short time falls and buy closed at the stop, so I can not see the correct result.
I would be grateful if you could express your idea programmatically, i.e. code.
In order to understand it in more detail, I give you the part where my two opposite (first) orders are opened.
Hi all.
The question is, do you have a function that detects the opening of a new bar(no matter what timeframe), or, more precisely, different variants of finding a new bar.
Hi all.
The question is, do you have a function that detects the opening of a new bar (no matter what timeframe), or, more precisely, can different variants (trailers) find a new bar.
Remember time oldtime = Time[0] and compare the remembered time if( oldtime !=Time[0])Print("Hurray for a new bar!!!");
SZY: trailers are in iTime() function.
:)
IgorM, the problem is that this f-fi is on a synthetic chart where iTime[0] may be equal to iTime[1], so how can we get rid of time so that the EA opens only one trade on a new bar?
if the time of bars 0 and 1 cannot be matched for some unknown reason - datetime type stores data in seconds, change the bar time by at least 1 second
then try to remember all characteristics of the first closed bar, i.e. OHLC, volume and open time - if you change even one parameter, it means a new bar
iBars() will show the number of bars in the current timeframe, and will be limited by the terminal settings, you can try to compare the number of bars with the stored bar number and at the moment of a new bar appearance, these values are different - but not always, it worked for me this way, but probably because of the MT4 build number this option may not work
You don't have a ready piece of code, do you? I can't figure out how to memorize OHLC[1] and compare it with OHLC[0]...
OHLC is a common acronym for Open,High,Low,Close
compare not with zero, but the first one with the one memorised earlier, i.e.
init(){
oldHigh = High[1];
///
}
start(){
double tmp = High[1];
if(tmp !=oldHigh) {oldHigh = tmp;
//check the rest of the bar parameters
}
}
Thanks for the tip I'll look into it...
Please advise how to set the correct check in the position opening condition - whether there is an open position for this instrument or not. And if there is a position for the symbol (any sell or buy), then the opening does not take place, otherwise the signal to open the position is triggered?
Here is the code (I think it is responsible for opening positions):
It seems to be correct by logic, but it still opens several positions for one symbol.
P.S. I am not the programmer. If it is possible in more details explain to the dummie.