Huckleberry:
Hello everyone,
Problem with liquidateing positions when the price moves against the position by two times the ATR.
The following portion of code describes the situation.
Where the ?????????????????? is where the problem is. There are two possible closing conditions. The first condition is OK. It was when I added on this new ATR condition is when the code breakdowns.
Any help out there please. Thank you in advance.
Regards
Huckleberry
Hi,
I think you should try the conditions with Bid/Ask instead of OrderClosePrice().
I'm not a programmer but it seems to me as a "logical bug". How do you "know" the Close order price if you haven't closed it yet?
Hi,
I think you should try the conditions with Bid/Ask instead of OrderClosePrice().
I'm not a programmer but it seems to me as a "logical bug". How do you "know" the Close order price if you haven't closed it yet?
Hello xrafix,
Sorry it took so long to check out your reply.
I'm no programmer myself. But the incoorect code I had posted is close to being correct. I remember an (OrderClosePrice() - OrderOpenPrice() >= ??????? used before in a different code which made a correct code.
The answer to the (OrderClosePrice blah,blah().... 2*iATR ..... I have not correctly coded.
I'll have a look around and post that correct code when I locate it.
Huckleberry
Hi,
Another try... :-)
2*iATR(NULL,0,24,0)*Point)??? why multiply in point? the values of iATR are already 0.00xx...
- ATR is already a double no need for *point
OrderClosePrice() - OrderOpenPrice(),5) >= 2*iATR
OrderClosePrice() usage is fine. It's either Bid (Buy order) or Ask(sell). The normalizeDouble isn't necessary since you're not comparing equality.- You must adjust for 5 digit brokers, TP, SL, and slippage
double pips2points, // slippage 3 pips 3=points 30=points pips2dbl; // Stoploss 15 pips 0.0015 0.00150 int Digits.pips; // DoubleToStr(dbl/pips2dbl, Digits.pips) int init(){ if (Digits == 5 || Digits == 3){ // Adjust for five (5) digit brokers. pips2dbl = Point*10; pips2points = 10; Digits.pips = 1; } else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; } // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
Further moreif (Digits == 3 || Digits == 5) Profit = Profit*10;
is unsafe. Each time you refresh, change timeframes or pairs, this code will increase the variable 10X. extern variables do not get reset on deinit/init cycles. - You orderSelect twice the second is redundant and potentially a problem. In the presence of other EAs or manual trading or if your EA opens multiple orders, you must count down when closing or deleteing.
for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) if ( OrderSelect(pos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == Magic.Number // my magic number && OrderSymbol() == Symbol() ){ // and period and symbol
// double ma8; // ma8=iMA(NULL,0,8,0,MODE_SMA,PRICE_CLOSE,0); // simplify double ma8=iMA(NULL,0,8,0,MODE_SMA,PRICE_CLOSE,0);

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello everyone,
Problem with liquidateing positions when the price moves against the position by two times the ATR.
The following portion of code describes the situation.
Where the ?????????????????? is where the problem is. There are two possible closing conditions. The first condition is OK. It was when I added on this new ATR condition is when the code breakdowns.
Any help out there please. Thank you in advance.
Regards
Huckleberry