Your code detects no open buy orders, so it returns Start_LotSize.
It actually does detect multiple open Buy orders:
From Journal:
2022.08.08 16:31:01.145 2021.08.04 03:04:06 Profit (2) EURUSD,M15: LotSize is 0.01 Buy is 4
The variable Buy is set to "0" right at the start of the code. (See below) So it cannot be changed to "0" after calculation when it reaches my lot calculation code.
Also, I have tested the formula on my calculator and it gives the correct value.
void OnTick() { //Count number of open trades Buy = 0; Sell = 0; BuyLimit = 0; SellLimit = 0; BuyTrade = false; SellTrade = false; Count = 0; for(Count = OrdersTotal()-1; Count >= 0; Count--) { if(OrderSelect(Count, SELECT_BY_POS, MODE_TRADES) && OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol()) //&& OrderCloseTime() == 0) { if(OrderType()== OP_SELL) Sell++; if(OrderType()== OP_BUY) Buy++; if(OrderType() == OP_SELLLIMIT) SellLimit++; if(OrderType() == OP_BUYLIMIT) BuyLimit++; } }
The proble lies with the following expression
MathPow((LotMultiplier/100),Buy+1)
that keeps on returning 1.0 no matter what the value of Buy is!
It actually does detect multiple open Buy orders:
From Journal:
2022.08.08 16:31:01.145 2021.08.04 03:04:06 Profit (2) EURUSD,M15: LotSize is 0.01 Buy is 4
-
Your posted code has no such Print statement. Always post all relevant code.
-
input int LotMultiplier = 150; ⋮ BuyLimitLotSize = Start_LotSize * MathPow((LotMultiplier/100),Buy+1);
150/100=1. 1^5=1. Start_LotSize * 1 = Start_LotSize
On MT4 v434, division quotient don't give floating point values(Bug??) - MQL4 programming forum (2012)
build 2504 & 2506 Bug - General - MQL5 programming forum - Page 2 #17 (2020)
Thank you so much WH Roeder!
I discovered the problem a few minutes a go. I changed the type of the LotMultiplier variable from "int" to "double" and now it works!
MAY I SAY THAT YOU ARE A GENIUS!!
Thank you again!
The proble lies with the following expression
that keeps on returning 1.0 no matter what the value of Buy is!
Thanks Dominik and Roeder!
Your help greatly appreciated!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am increasing the lot size with each subsequent Limit transaction but my code/formula just keeps on returning my starting lot size.
Here is the code to calculate the lot sizes with each subsequent limit trade that is generated: