Strategy with miscalculated infinity order levels in MT5 not placing any trades

EDIT:
OK, this one is really weird. These strategies that attempt to place an order at a price level adjusted by ATR and that are run on SPX500 Dukas data every tick real ticks in the MT5 terminal specifically that start at dates before 2012 seem to crash the sqx ATR indicator immediately and then every trade tries to place an order at level infinity. If I start the test from 2014 or later it works fine. I tried fresh dukas data, the same thing happens. I tried other strategies on this data, they work fine. I ran the debugger in mt5 and I get...

a bunch of these:
2022.03.07 22:03:31.317 2012.01.30 09:00:15   Failed to copy data from the indicator with index 1, error code 4806
and then of course the margin calculation fails because the price level is "inf"
I can also see during debugging that the following function
sqGetIndicatorValue(ATR_1, 0, 3);
returns "inf" so that's how I know it is the ATR indicator.

Another weird thing is that strategies from other "batches" with ATR-adjusted price levels are working fine on this data. It is only these strategies from this "batch" on the year 2011 of Dukas data SPX500 that the ATR is not working.
Also during compilation, I get this warning:

declaration of 'ATRPeriod' hides global variable test.mq5 6660 58

I'll attach any others that I find below....

EDIT:
Changing this line to this solves the issue:
int minBars = 150;




It should probably be the "mathmax" of all the periods.... (Actually, the largest period is 148 but 148 and 149 didn't work so should be MathMax plus 2 I guess for whatever reason.)


-------------------------------------------------------------------------------


My MT5 strategies work well in general as far as position sizing, SL etc go on this symbol (SPX500) and its settings but for some reason, with this one strategy, I get errors saying the SL is infinity and then it fails to place a minlot because of insufficient margin which is nonsense (I have 1,000,000 current balance and 1000:1 leverage and like I said other strats are working fine on this data/symbol settings). 

2022.03.03 11:48:36.095 Core 01 2015.10.21 17:00:00   ---VERBOSE--- 2015.10.21 17:00 Max money to risk: 1000.00000000, SL:inf, Max 1 lot trade drawdown: nan, Point value: 10.00000000
2022.03.03 11:48:36.095 Core 01 2015.10.21 17:00:00   ---VERBOSE--- 2015.10.21 17:00 Calculated LotSize is <= 0. Using LotsIfNoMM value: 0.10000000)
2022.03.03 11:48:36.095 Core 01 2015.10.21 17:00:00   Alert: Not enough money to send order with 0.10000000 lot or Margin Calculation Error
2022.03.03 11:48:36.095 Core 01 2015.10.21 18:00:00   ---VERBOSE--- 2015.10.21 18:00 Computing Money Management for order -  Risk fixed % of account
2022.03.03 11:48:36.095 Core 01 2015.10.21 18:00:00   ---VERBOSE--- 2015.10.21 18:00 Computing Money Management - Smallest_Lot: 0.10000000, Largest_Lot: 100.00000000, Computed LotSize: 0.00000000
2022.03.03 11:48:36.095 Core 01 2015.10.21 18:00:00   ---VERBOSE--- 2015.10.21 18:00 Max money to risk: 1000.00000000, SL:inf, Max 1 lot trade drawdown: nan, Point value: 10.00000000
2022.03.03 11:48:36.095 Core 01 2015.10.21 18:00:00   ---VERBOSE--- 2015.10.21 18:00 Calculated LotSize is <= 0. Using LotsIfNoMM value: 0.10000000)
2022.03.03 11:48:36.095 Core 01 2015.10.21 18:00:00   Alert: Not enough money to send order with 0.10000000 lot or Margin Calculation Error
2022.03.03 11:48:36.095 Core 01 2015.10.21 19:00:02   ---VERBOSE--- 2015.10.21 19:00 Computing Money Management for order -  Risk fixed % of account
2022.03.03 11:48:36.095 Core 01 2015.10.21 19:00:02   ---VERBOSE--- 2015.10.21 19:00 Computing Money Management - Smallest_Lot: 0.10000000, Largest_Lot: 100.00000000, Computed LotSize: 0.00000000
2022.03.03 11:48:36.095 Core 01 2015.10.21 19:00:02   ---VERBOSE--- 2015.10.21 19:00 Max money to risk: 1000.00000000, SL:inf, Max 1 lot trade drawdown: nan, Point value: 10.00000000
2022.03.03 11:48:36.095 Core 01 2015.10.21 19:00:02   ---VERBOSE--- 2015.10.21 19:00 Calculated LotSize is <= 0. Using LotsIfNoMM value: 0.10000000)
2022.03.03 11:48:36.095 Core 01 2015.10.21 19:00:02   Alert: Not enough money to send order with 0.10000000 lot or Margin Calculation Error
2022.03.03 11:48:36.095 Core 01 2015.10.21 20:00:00   ---VERBOSE--- 2015.10.21 20:00 Computing Money Management for order -  Risk fixed % of account
2022.03.03 11:48:36.095 Core 01 2015.10.21 20:00:00   ---VERBOSE--- 2015.10.21 20:00 Computing Money Management - Smallest_Lot: 0.10000000, Largest_Lot: 100.00000000, Computed LotSize: 0.00000000
2022.03.03 11:48:36.095 Core 01 2015.10.21 20:00:00   ---VERBOSE--- 2015.10.21 20:00 Max money to risk: 1000.00000000, SL:inf, Max 1 lot trade drawdown: nan, Point value: 10.00000000
2022.03.03 11:48:36.095 Core 01 2015.10.21 20:00:00   ---VERBOSE--- 2015.10.21 20:00 Calculated LotSize is <= 0. Using LotsIfNoMM value: 0.10000000)
2022.03.03 11:48:36.095 Core 01 2015.10.21 20:00:00   Alert: Not enough money to send order with 0.10000000 lot or Margin Calculation Error
2022.03.03 11:48:36.095 Core 01 2015.10.21 21:00:00   ---VERBOSE--- 2015.10.21 21:00 Computing Money Management for order -  Risk fixed % of account
2022.03.03 11:48:36.095 Core 01 2015.10.21 21:00:00   ---VERBOSE--- 2015.10.21 21:00 Computing Money Management - Smallest_Lot: 0.10000000, Largest_Lot: 100.00000000, Computed LotSize: 0.00000000
2022.03.03 11:48:36.095 Core 01 2015.10.21 21:00:00   ---VERBOSE--- 2015.10.21 21:00 Max money to risk: 1000.00000000, SL:inf, Max 1 lot trade drawdown: nan, Point value: 10.00000000
2022.03.03 11:48:36.095 Core 01 2015.10.21 21:00:00   ---VERBOSE--- 2015.10.21 21:00 Calculated LotSize is <= 0. Using LotsIfNoMM value: 0.10000000)
2022.03.03 11:48:36.095 Core 01 2015.10.21 21:00:00   Alert: Not enough money to send order with 0.10000000 lot or Margin Calculation Error


Commenting out the margin check I simply get an invalid price because of the infinity order levels, so probably the infinity order levels were causing a false negative for the margin calculation.


2022.03.03 12:02:04.426 Core 01 2015.09.17 19:00:01   failed buy stop 0.1 SPX500_duk at inf sl: inf [Invalid price]
2022.03.03 12:02:04.426 Core 01 2015.09.17 19:00:01   Alert: The order request could not be completed. Error no.: 4756
2022.03.03 12:02:04.426 Core 01 2015.09.17 19:00:01   Alert: Error description: Trade request sending failed
2022.03.03 12:02:04.426 Core 01 2015.09.17 20:00:00   ---VERBOSE--- 2015.09.17 20:00 Computing Money Management for order -  Risk fixed % of account
2022.03.03 12:02:04.426 Core 01 2015.09.17 20:00:00   ---VERBOSE--- 2015.09.17 20:00 Computing Money Management - Smallest_Lot: 0.10000000, Largest_Lot: 100.00000000, Computed LotSize: 0.00000000
2022.03.03 12:02:04.426 Core 01 2015.09.17 20:00:00   ---VERBOSE--- 2015.09.17 20:00 Max money to risk: 1000.00000000, SL:-inf, Max 1 lot trade drawdown: inf, Point value: 10.00000000
2022.03.03 12:02:04.426 Core 01 2015.09.17 20:00:00   ---VERBOSE--- 2015.09.17 20:00 Calculated LotSize is <= 0. Using LotsIfNoMM value: 0.10000000)
2022.03.03 12:02:04.426 Core 01 2015.09.17 20:00:00   failed sell stop 0.1 SPX500_duk at -inf sl: -inf [Invalid price]
2022.03.03 12:02:04.426 Core 01 2015.09.17 20:00:00   Alert: The order request could not be completed. Error no.: 4756
2022.03.03 12:02:04.426 Core 01 2015.09.17 20:00:00   Alert: Error description: Trade request sending failed
2022.03.03 12:02:04.426 Core 01 2015.09.17 21:00:00   ---VERBOSE--- 2015.09.17 21:00 Computing Money Management for order -  Risk fixed % of account
2022.03.03 12:02:04.426 Core 01 2015.09.17 21:00:00   ---VERBOSE--- 2015.09.17 21:00 Computing Money Management - Smallest_Lot: 0.10000000, Largest_Lot: 100.00000000, Computed LotSize: 0.00000000
2022.03.03 12:02:04.426 Core 01 2015.09.17 21:00:00   ---VERBOSE--- 2015.09.17 21:00 Max money to risk: 1000.00000000, SL:-inf, Max 1 lot trade drawdown: inf, Point value: 10.00000000
2022.03.03 12:02:04.426 Core 01 2015.09.17 21:00:00   ---VERBOSE--- 2015.09.17 21:00 Calculated LotSize is <= 0. Using LotsIfNoMM value: 0.10000000)
2022.03.03 12:02:04.426 Core 01 2015.09.17 21:00:00   failed sell stop 0.1 SPX500_duk at -inf sl: -inf [Invalid price]
2022.03.03 12:02:04.426 Core 01 2015.09.17 21:00:00   Alert: The order request could not be completed. Error no.: 4756
2022.03.03 12:02:04.426 Core 01 2015.09.17 21:00:00   Alert: Error description: Trade request sending failed


Oddly this strategy seems to work on EURUSD but not SPX500 but all other strategies seem working on SPX500...

Attachments
Bugged_Strategy 1212258.sqx
(1.24 MiB)
  • Votes +3
  • Project StrategyQuant X
  • Type Bug
  • Status Fixed
  • Priority Normal

History

b
#1

bentra

03.03.2022 18:12

Task created

b
#2

bentra

03.03.2022 18:23
Voted for this task.
b
#3

bentra

03.03.2022 20:23

Attachment 2022-03-03 5.png added

Attachment 2022-03-03 6.png added

2022-03-03 6.png
(47.22 KiB)
2022-03-03 5.png
(35.03 KiB)
o
#4

Enric

05.03.2022 10:24
Voted for this task.
b
#5

bentra

07.03.2022 22:16

Description changed:

EDIT:
Better put a pin in this one. I found a few more with this problem but it goes away when I change the start date of the test in mt5 terminal. It's starting to look like my mt5 data is corrupted. I'll keep you updated.

My MT5 strategies work well in general as far as position sizing, SL etc go on this symbol (SPX500) and its settings but for some reason, with this one strategy, I get errors saying the SL is infinity and then it fails to place a minlot because of insufficient margin which is nonsense (I have 1,000,000 current balance and 1000:1 leverage and like I said other strats are working fine on this data/symbol settings). 

2022.03.03 11:48:36.095 Core 01 2015.10.21 17:00:00   ---VERBOSE--- 2015.10.21 17:00 Max money to risk: 1000.00000000, SL:inf, Max 1 lot trade drawdown: nan, Point value: 10.00000000
2022.03.03 11:48:36.095 Core 01 2015.10.21 17:00:00   ---VERBOSE--- 2015.10.21 17:00 Calculated LotSize is <= 0. Using LotsIfNoMM value: 0.10000000)
2022.03.03 11:48:36.095 Core 01 2015.10.21 17:00:00   Alert: Not enough money to send order with 0.10000000 lot or Margin Calculation Error
2022.03.03 11:48:36.095 Core 01 2015.10.21 18:00:00   ---VERBOSE--- 2015.10.21 18:00 Computing Money Management for order -  Risk fixed % of account
2022.03.03 11:48:36.095 Core 01 2015.10.21 18:00:00   ---VERBOSE--- 2015.10.21 18:00 Computing Money Management - Smallest_Lot: 0.10000000, Largest_Lot: 100.00000000, Computed LotSize: 0.00000000
2022.03.03 11:48:36.095 Core 01 2015.10.21 18:00:00   ---VERBOSE--- 2015.10.21 18:00 Max money to risk: 1000.00000000, SL:inf, Max 1 lot trade drawdown: nan, Point value: 10.00000000
2022.03.03 11:48:36.095 Core 01 2015.10.21 18:00:00   ---VERBOSE--- 2015.10.21 18:00 Calculated LotSize is <= 0. Using LotsIfNoMM value: 0.10000000)
2022.03.03 11:48:36.095 Core 01 2015.10.21 18:00:00   Alert: Not enough money to send order with 0.10000000 lot or Margin Calculation Error
2022.03.03 11:48:36.095 Core 01 2015.10.21 19:00:02   ---VERBOSE--- 2015.10.21 19:00 Computing Money Management for order -  Risk fixed % of account
2022.03.03 11:48:36.095 Core 01 2015.10.21 19:00:02   ---VERBOSE--- 2015.10.21 19:00 Computing Money Management - Smallest_Lot: 0.10000000, Largest_Lot: 100.00000000, Computed LotSize: 0.00000000
2022.03.03 11:48:36.095 Core 01 2015.10.21 19:00:02   ---VERBOSE--- 2015.10.21 19:00 Max money to risk: 1000.00000000, SL:inf, Max 1 lot trade drawdown: nan, Point value: 10.00000000
2022.03.03 11:48:36.095 Core 01 2015.10.21 19:00:02   ---VERBOSE--- 2015.10.21 19:00 Calculated LotSize is <= 0. Using LotsIfNoMM value: 0.10000000)
2022.03.03 11:48:36.095 Core 01 2015.10.21 19:00:02   Alert: Not enough money to send order with 0.10000000 lot or Margin Calculation Error
2022.03.03 11:48:36.095 Core 01 2015.10.21 20:00:00   ---VERBOSE--- 2015.10.21 20:00 Computing Money Management for order -  Risk fixed % of account
2022.03.03 11:48:36.095 Core 01 2015.10.21 20:00:00   ---VERBOSE--- 2015.10.21 20:00 Computing Money Management - Smallest_Lot: 0.10000000, Largest_Lot: 100.00000000, Computed LotSize: 0.00000000
2022.03.03 11:48:36.095 Core 01 2015.10.21 20:00:00   ---VERBOSE--- 2015.10.21 20:00 Max money to risk: 1000.00000000, SL:inf, Max 1 lot trade drawdown: nan, Point value: 10.00000000
2022.03.03 11:48:36.095 Core 01 2015.10.21 20:00:00   ---VERBOSE--- 2015.10.21 20:00 Calculated LotSize is <= 0. Using LotsIfNoMM value: 0.10000000)
2022.03.03 11:48:36.095 Core 01 2015.10.21 20:00:00   Alert: Not enough money to send order with 0.10000000 lot or Margin Calculation Error
2022.03.03 11:48:36.095 Core 01 2015.10.21 21:00:00   ---VERBOSE--- 2015.10.21 21:00 Computing Money Management for order -  Risk fixed % of account
2022.03.03 11:48:36.095 Core 01 2015.10.21 21:00:00   ---VERBOSE--- 2015.10.21 21:00 Computing Money Management - Smallest_Lot: 0.10000000, Largest_Lot: 100.00000000, Computed LotSize: 0.00000000
2022.03.03 11:48:36.095 Core 01 2015.10.21 21:00:00   ---VERBOSE--- 2015.10.21 21:00 Max money to risk: 1000.00000000, SL:inf, Max 1 lot trade drawdown: nan, Point value: 10.00000000
2022.03.03 11:48:36.095 Core 01 2015.10.21 21:00:00   ---VERBOSE--- 2015.10.21 21:00 Calculated LotSize is <= 0. Using LotsIfNoMM value: 0.10000000)
2022.03.03 11:48:36.095 Core 01 2015.10.21 21:00:00   Alert: Not enough money to send order with 0.10000000 lot or Margin Calculation Error


Commenting out the margin check I simply get an invalid price because of the infinity order levels, so probably the infinity order levels were causing a false negative for the margin calculation.


2022.03.03 12:02:04.426 Core 01 2015.09.17 19:00:01   failed buy stop 0.1 SPX500_duk at inf sl: inf [Invalid price]
2022.03.03 12:02:04.426 Core 01 2015.09.17 19:00:01   Alert: The order request could not be completed. Error no.: 4756
2022.03.03 12:02:04.426 Core 01 2015.09.17 19:00:01   Alert: Error description: Trade request sending failed
2022.03.03 12:02:04.426 Core 01 2015.09.17 20:00:00   ---VERBOSE--- 2015.09.17 20:00 Computing Money Management for order -  Risk fixed % of account
2022.03.03 12:02:04.426 Core 01 2015.09.17 20:00:00   ---VERBOSE--- 2015.09.17 20:00 Computing Money Management - Smallest_Lot: 0.10000000, Largest_Lot: 100.00000000, Computed LotSize: 0.00000000
2022.03.03 12:02:04.426 Core 01 2015.09.17 20:00:00   ---VERBOSE--- 2015.09.17 20:00 Max money to risk: 1000.00000000, SL:-inf, Max 1 lot trade drawdown: inf, Point value: 10.00000000
2022.03.03 12:02:04.426 Core 01 2015.09.17 20:00:00   ---VERBOSE--- 2015.09.17 20:00 Calculated LotSize is <= 0. Using LotsIfNoMM value: 0.10000000)
2022.03.03 12:02:04.426 Core 01 2015.09.17 20:00:00   failed sell stop 0.1 SPX500_duk at -inf sl: -inf [Invalid price]
2022.03.03 12:02:04.426 Core 01 2015.09.17 20:00:00   Alert: The order request could not be completed. Error no.: 4756
2022.03.03 12:02:04.426 Core 01 2015.09.17 20:00:00   Alert: Error description: Trade request sending failed
2022.03.03 12:02:04.426 Core 01 2015.09.17 21:00:00   ---VERBOSE--- 2015.09.17 21:00 Computing Money Management for order -  Risk fixed % of account
2022.03.03 12:02:04.426 Core 01 2015.09.17 21:00:00   ---VERBOSE--- 2015.09.17 21:00 Computing Money Management - Smallest_Lot: 0.10000000, Largest_Lot: 100.00000000, Computed LotSize: 0.00000000
2022.03.03 12:02:04.426 Core 01 2015.09.17 21:00:00   ---VERBOSE--- 2015.09.17 21:00 Max money to risk: 1000.00000000, SL:-inf, Max 1 lot trade drawdown: inf, Point value: 10.00000000
2022.03.03 12:02:04.426 Core 01 2015.09.17 21:00:00   ---VERBOSE--- 2015.09.17 21:00 Calculated LotSize is <= 0. Using LotsIfNoMM value: 0.10000000)
2022.03.03 12:02:04.426 Core 01 2015.09.17 21:00:00   failed sell stop 0.1 SPX500_duk at -inf sl: -inf [Invalid price]
2022.03.03 12:02:04.426 Core 01 2015.09.17 21:00:00   Alert: The order request could not be completed. Error no.: 4756
2022.03.03 12:02:04.426 Core 01 2015.09.17 21:00:00   Alert: Error description: Trade request sending failed


Oddly this strategy seems to work on EURUSD but not SPX500 but all other strategies seem working on SPX500...

E
#6

Emmanuel

10.03.2022 04:06
Voted for this task.
g
#7

Lee Guan Chuan

13.10.2022 11:57

Status changed from New to Fixed

Hi Bentra,


The sqATR indicator is the culprit. I have solved the indicator.


For the minBars, I cannot generate based on the period. This is because the user can modify the period. We cannot control what period the user going to set. I have updated the minBars to become an input. So the user can modify the minBars from the input list.


Thank you.

b
#8

bentra

13.10.2022 14:48
I think you could use the mathmax function for all the input periods.... I mean in MQL. MQL also has mathmax. so whatever the user enters the mql code can take the biggest one. I use this technique in my home made mql EA all the time.
g
#9

Lee Guan Chuan

13.10.2022 15:06
Hi Bentra,


Thanks for the advice. I will try that out.


Thank you.


Votes: +3

Drop files to upload

or

choose files

Max size: 5MB

Not allowed: exe, msi, application, reg, php, js, htaccess, htpasswd, gitignore

...
Wait please