Dear Expert,
In the attached EA, there are only 3 lines containing KL:
input double KL = 2; // увеличение лота
if(OrderProfit()<0) lot=OrderLots()*KL;
if(profit<0) lot=LastLot*KL;
How come when KL is given a value like 1, 2 or 3, the EA works fine; but if KL is given a value like 1.3, 1.5, etc. the EA become abnormal? What can I change so that the EA works still with KL set to 1.3, 1.5, etc?
Many thanks for your enlightenment.
Best,
Jim
It's because the lots function fails to return the correctly rounded value. It should instead do this.
double Lot() { double lot=LT; //--- MQL4 #ifdef __MQL4__ if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY)) { if(OrderProfit()>0) lot=LT; if(OrderProfit()<0) lot=OrderLots()*KL; } #endif //--- MQL5 #ifdef __MQL5__ if(HistorySelect(0,TimeCurrent())) { double profit=HistoryDealGetDouble(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_PROFIT); double LastLot=HistoryDealGetDouble(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_VOLUME); if(profit>0) lot=LT; if(profit<0) lot=LastLot*KL; } #endif if(lot>ML)lot=LT; double step = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_STEP); return step * floor(lot / step); }
if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
-
Using OrdersTotal directly and/or no Magic number filtering on your
OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual
trading.)
Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 and MetaTrader 4 - MQL4 programming forum - Do not assume history is ordered by date, it's not.
Could EA Really Live By Order_History Alone? (ubzen) - MQL4 and MetaTrader 4 - MQL4 programming forum
Count how many lost orders from the last profit order - MQL4 and MetaTrader 4 - MQL4 programming forum
It's because the lots function fails to return the correctly rounded value. It should instead do this.
Dear Mr. Nicholishen,
I tested your correction.
When I set KL to 1.5, I expect
position 1 lot: 0.01
position 2 lot: 0.02 (0.01x1.5)
position 3 lot: 0.02 (0.02x1.5)
position 4 lot: 0.03 (0.02x1.5)
position 5 lot: 0.05 (0.03x1.5)
position 6 lot: 0.08 (0.05x1.5)
position 7 lot: 0.11 (0.08x1.5)
etc.
Your correction makes all position lots to be 0.01. The lots do not increase by KL. Could you kindly further advise me?
Many thanks.
Jim
-
Using OrdersTotal directly and/or no Magic number filtering on your
OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual
trading.)
Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 and MetaTrader 4 - MQL4 programming forum - Do not assume history is ordered by date, it's not.
Could EA Really Live By Order_History Alone? (ubzen) - MQL4 and MetaTrader 4 - MQL4 programming forum
Count how many lost orders from the last profit order - MQL4 and MetaTrader 4 - MQL4 programming forum
Dear whroeder1,
Thank you for your advice. I am no programmer and I don't know how to turn your advice to mt5 language to solve my problem. Could you please advise me the way nicholishen does?
Many thanks.
Jim
- Search for it,
- learn to code it. If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into yours.
- Beg at Coding help - MQL4 and MetaTrader 4 - MQL4 programming forum or Need help with coding - General - MQL5 programming forum or Free MQL4 To MQL5 Converter - General - MQL5 programming forum or Requests & Ideas (MQL5 only!),
- or pay (Freelance) someone to code it.
No free help
urgent help.
Dear Mr. Nicholishen,
I tested your correction.
When I set KL to 1.5, I expect
position 1 lot: 0.01
position 2 lot: 0.02 (0.01x1.5)
position 3 lot: 0.02 (0.02x1.5)
position 4 lot: 0.03 (0.02x1.5)
position 5 lot: 0.05 (0.03x1.5)
position 6 lot: 0.08 (0.05x1.5)
position 7 lot: 0.11 (0.08x1.5)
etc.
Your correction makes all position lots to be 0.01. The lots do not increase by KL. Could you kindly further advise me?
Many thanks.
Jim
That's because the floor function in this formula rounds down to the nearest lot-step. Rounding down to step ensures that you will not exceed your calculated risk. This is only really an issue when working with micro lots... if you want to round to the nearest lot-step change floor to round.
You have only four choices:
- Search for it,
- learn to code it. If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into yours.
- Beg at Coding help - MQL4 and MetaTrader 4 - MQL4 programming forum or Need help with coding - General - MQL5 programming forum or Free MQL4 To MQL5 Converter - General - MQL5 programming forum or Requests & Ideas (MQL5 only!),
- or pay (Freelance) someone to code it.
No free help
urgent help.
Dear whroeder1,
Thanks for pointing out the ways.
Jim
That's because the floor function in this formula rounds down to the nearest lot-step. Rounding down to step ensures that you will not exceed your calculated risk. This is only really an issue when working with micro lots... if you want to round to the nearest lot-step change floor to round.
Dear Nicholishen,
Very grateful to you for your guidance! After I change "floor" in your lines to "round", the EA behaves as expected now.
Deeply appreciate your teaching and helping!
Best,
Jim
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Dear Expert,
In the attached EA, there are only 3 lines containing KL:
input double KL = 2; // увеличение лота
if(OrderProfit()<0) lot=OrderLots()*KL;
if(profit<0) lot=LastLot*KL;
How come when KL is given a value like 1, 2 or 3, the EA works fine; but if KL is given a value like 1.3, 1.5, etc. the EA become abnormal? What can I change so that the EA works still with KL set to 1.3, 1.5, etc?
Many thanks for your enlightenment.
Best,
Jim