-
Why did you post your MT4
question in the Root / MT5 EA
section instead of the MQL4 section, (bottom of the Root page?)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon. - basophil: I check the journal find this strange, it closed at price 0.00000: I feel like this is a very simple error.Message from the terminal, not your code. Not an error since it is followed by a valid result and not your error message. ECN brokers ignore price and slippage.
- basophil: The EA I write is very simple, I want to practice using Martigale for lot.dMartingale, guaranteed to blow your account eventually. If it's not profitable without, it is definitely not profitable with.
Martingale vs. Non Martingale (Simplified RoR vs Profit and the Illusions) - MQL5 programming forum
Why it won't work: Calculate Loss from Lot Pips - MQL5 programming forum - basophil: If the price reaches TP -> close trade at TPTake profit automatically closed the trade.
- basophil:I limited the EA with buy order only and not setting SL.No SL means infinite risk — you can't compute your lot size without it. Never risk more than a small percentage of your account, certainly less than 2% per trade, 6% total to the account. Risk depends on your initial stop loss, lot size, and the value of the pair. It does not depend on margin and leverage.
- You place the stop where it needs to be — where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
- AccountBalance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the spread, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
- Do NOT use TickValue by itself - DeltaPerLot
and verify that MODE_TICKVALUE is returning a value in your deposit currency, as promised by the documentation, or
whether it is returning a value in the instrument's base currency.
MODE_TICKVALUE is not reliable on non-fx instruments with many brokers - MQL4 programming forum 2017.10.10
Is there an universal solution for Tick value? - Currency Pairs - General - MQL5 programming forum 2018.02.11
Lot value calculation off by a factor of 100 - MQL5 programming forum 2019.07.19 - You must normalize lots properly and check against min and max.
- You must also check FreeMargin to avoid stop out
Most pairs are worth about $10 per PIP. A $5 risk with a (very small) 5 PIP SL is $5/$10/5 or 0.1 Lots maximum.
Hello, William,
Thank you for your reply. Sorry I didn't realize that EA section is for MT5 only. Will keep that in mind next time!
I have experience of use EA and understand it's dangerous using martingale also not setting SL. I just wanted to code something quickly and see how home-build EA runs like.
Can you explain a little more? I know it' not an error message but I think this is the clue of why the trade closed unexpectedly.
I want to know the reason why the trade is closed. They are not closed at certain profit/loss or some specific time interval.
More curious is why it works in backtest.
MODE_TICKVALUE is not reliable on non-fx instruments with many brokers - MQL4 programming forum 2017.10.10
Is there an universal solution for Tick value? - Currency Pairs - General - MQL5 programming forum 2018.02.11
Lot value calculation off by a factor of 100 - MQL5 programming forum 2019.07.19
Thank you for the tips!! I will check into these articles.
And also the suggestion of money management is much appreciated! Never really think too deep about this and always try with 1000 USD / 0.01 lot every time using a new EA.
Cheers!
basophil:
Can you explain a little more? I know it' not an error message but I think this is the clue of why the trade closed unexpectedly.
Never really think too deep about this and always try with 1000 USD / 0.01 lot every time using a new EA.Your EA opened 0.03 lots, with only $1K balance. Likely free margin was exhausted and the order closed. See #1 № 5.5
Hello, William,
Thank you for your reply. Sorry I didn't realize that EA section is for MT5 only. Will keep that in mind next time!
I have experience of use EA and understand it's dangerous using martingale also not setting SL. I just wanted to code something quickly and see how home-build EA runs like.
Can you explain a little more? I know it' not an error message but I think this is the clue of why the trade closed unexpectedly.
I want to know the reason why the trade is closed. They are not closed at certain profit/loss or some specific time interval.
More curious is why it works in backtest.
Thank you for the tips!! I will check into these articles.
And also the suggestion of money management is much appreciated! Never really think too deep about this and always try with 1000 USD / 0.01 lot every time using a new EA.
Cheers!
Your order was not closed at a price = 0.00000. It's the way the Terminal output an order with a Market Execution as the price at which it will be
executed is unknown.
2020.02.27 21:28:20.981 '13003601': close order #27115967 buy 0.03 EURUSD at 1.09468 sl: 0.00000 tp: 1.09558 at price 0.00000 => order to close send
Your EA request to close the order, as there is only 1 place in your code when it can be done :
if(TotalOpenProfit(1) > MartTakeProfit * OpenTradeSize() //Total Open Profit (Long) > fixed value * Open Trade Size ) { if(IsTradeAllowed()) myOrderClose(OP_BUY, 100, ""); else //not autotrading => only send alert myAlert("order", ""); }
That means this condition was true and the myOrderClose() was executed.
This condition doesn't make sense, you are comparing a value in $ (or whatever the account currency) from TotalOpenProfit(), with a number of lots (returned by OpenTradeSize) multiplied by some factor.
Most probably your MartTakeProfit was equal to 1.
Fix your coding logic.
Your EA opened 0.03 lots, with only $1K balance. Likely free margin was exhausted and the order closed. See #1 № 5.5
Hello, Willam.
This also happen when I use 0.01 lost and with 10K usd balance. And the equity is always much more than the margin required.
But you are totally right, I should definitely add money management in my EA.
Your order was not closed at a price = 0.00000. It's the way the Terminal output an order with a Market Execution as the price at which it will
be executed is unknown.
2020.02.27 21:28:20.981 '13003601': close order #27115967 buy 0.03 EURUSD at 1.09468 sl: 0.00000 tp: 1.09558 at price 0.00000 => order to close send
Your EA request to close the order, as there is only 1 place in your code when it can be done :
That means this condition was true amd the myOrderClose() was executed.
This condition doesn't make sense, you are comparing a value in $ (or whatever the account currency) fron TotalOpenProfit(), with a number of lots (returned by OpenTradeSize) multiplied by some factor.
Most probably your MartTakeProfit was equal to 1.
Fix your coding logic.
Hello, Alain
You are right! this profit part is the problem.
When I remove or modify the writing there, the trades doesn't close for unknown reason.
I use USD account and trade with EURUSD, so I think by calculating total profit and compare with ((desired profit points/0.01 lots) * total lots) can achieve what I want. (and it does in the backtest! this is the most strange thing!) Maybe using different type of integrates (currency/value) is really a bad idea as you said.
I will try to modify the profit part into modifying TP in all trades when new trade opens.
Thank you sososo much!
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- 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, I am very new in coding EA.
The EA I write is very simple, I want to practice using Martigale for lot.
I limited the EA with buy order only and not setting SL.
The stradegy is:
Entry when there is no current trade. (No matter the price.)
Set the TP from inputs for the first trade.
If the price reaches TP -> close trade at TP
If dropped certain pips -> open another trade
If there is more than one trade, the TP will not be modified but will be defined by another code.
TP will be [total trade lots * take profit value from imput]
So the scenario should be like:
open buy 0.01 at 1.09000, set TP at 1.09090
next should close trade at 1.09090
or open buy 0.03 at 1.08350 and close both trades at 1.8612
The code:
Anyone has any idea?
Thank you!