I find the problem but I don´t know why happens.
PositionGetDouble(POSITION_VOLUME) return 0.0 in real time demo test when all positions are closed.
In back-test return 0.1 even if position is closed, example:
2016.02.01 01:02:00 Positions open detected in EURUSD VOLUME: 0.01
2016.02.01 01:02:20 Positions open detected in EURUSD VOLUME: 0.01
Trade 2016.02.01 01:02:40 stop loss triggered buy 0.01 EURUSD 1.08335 sl: 1.08235 tp: 1.08435 [#3 sell 0.01 EURUSD at 1.08235]
Trades 2016.02.01 01:02:40 deal #3 sell 0.01 EURUSD at 1.08235 done (based on order #3)
Trade 2016.02.01 01:02:40 deal performed [#3 sell 0.01 EURUSD at 1.08235]
Trade 2016.02.01 01:02:40 order performed sell 0.01 at 1.08235 [#3 sell 0.01 EURUSD at 1.08235]
2016.02.01 01:02:40 Positions open detected in EURUSD VOLUME: 0.01
2016.02.01 01:02:59 Positions open detected in EURUSD VOLUME: 0.01
I find the problem but I don´t know why happens.
PositionGetDouble(POSITION_VOLUME) return 0.0 in real time demo test when all positions are closed.
In back-test return 0.1 even if position is closed, example:
...You should check the documentation more carefully, you have to check the return value of PositionSelect() if it's false, PositionGetDouble() results are unreliable.
void OnTick() { if(PositionSelect(_Symbol)) { if(PositionGetDouble(POSITION_PROFIT)==0) { Print("Positions open NOT detected in " + _Symbol); openTrade(); } else { Print("Positions open detected in " + _Symbol + " PROFIT: " + PositionGetDouble(POSITION_PROFIT)); } } else { Print("OnTick() called, but PositionSelect() return false. Error: " + GetLastError()); } }
I make this change and result are the same. When all operations are closed "PositionGetDouble()" return data of last closed operation. And documentation say "The function returns the requested property of an open position". Instead of "POSITION_PROFIT" I check which other parameters, and all return data of last closed operation. In real test work OK I only have this problem in back-test.
Example:
MH 0 12:45:07.976 forum (EURUSD,M1) 2016.02.01 00:59:00 Positions open detected in EURUSD PROFIT: -1.14
HH 0 12:45:07.976 forum (EURUSD,M1) 2016.02.01 00:59:20 Positions open detected in EURUSD PROFIT: -1
IR 0 12:45:07.976 forum (EURUSD,M1) 2016.02.01 00:59:40 Positions open detected in EURUSD PROFIT: -1.16
MH 0 12:45:07.976 Trade 2016.02.01 01:00:40 stop loss triggered buy 0.02 EURUSD 1.08343 sl: 1.08251 tp: 1.08451 [#4 sell 0.02 EURUSD at 1.08251]
GK 0 12:45:07.976 Trades 2016.02.01 01:00:40 deal #4 sell 0.02 EURUSD at 1.08251 done (based on order #4)
RE 0 12:45:07.976 Trade 2016.02.01 01:00:40 deal performed [#4 sell 0.02 EURUSD at 1.08251]
QE 0 12:45:07.976 Trade 2016.02.01 01:00:40 order performed sell 0.02 at 1.08251 [#4 sell 0.02 EURUSD at 1.08251]
ML 0 12:45:07.977 forum (EURUSD,M1) 2016.02.01 01:00:40 Positions open detected in EURUSD PROFIT: -1.16 (this line is repeated in all next data 100 000 times in all month back-test)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
This is my 1º EA.
Does nothing useful, it's just to practice programming.
When there is no open trade, open an operation with TP and SL low for closing fast.
I test this EA which demo account in real time and it works as Expected. But when I use in Back-test don´t work. Only open 1 trade. In real time in 1 real hour open like 25 operations.
Only one position is open. But I don´t see "Print("openTradeCalled()");" in log. Also I don´t see
Print("OnInit()");
In log I only see repeated like 200 times:
Print("Positions open detected in " + _Symbol);