Questions from Beginners MQL4 MT4 MetaTrader 4 - page 112
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello. I wrote in my EA the calculation of the lot like this:
lot=NormalizeDouble(AccountBalance()*risk/(SL*MarketInfo(Symbol(),MODE_TICKVALUE)),2);
The purpose is to get the correct lot size regardless of the account currency and pair for the given risk and stop loss. Risk is set as a percentage of losses when Stop Loss is triggered. Stop Loss SL in pips (where pips is the smallest possible change in the price of the pair). I am going to use this EA in real account. But I have my doubts. If somebody from more experienced programmers could tell me what errors may occur, I would be very grateful.First strategy tester. Then a demo account. And only then a real one. Write a script to check the formula. Or just calculate it on a piece of paper. I took balance=100, risk=0.1 SL=100, Tick=0.00001 Lot=100*0.1 / (100*0.00001) = 10 / 0.001 = 10000 lot more than the balance? Should we consider the leverage?
MarketInfo(Symbol(),MODE_TICKVALUE)) does not return the minimum tick size. It's written in the help:
Size of minimal change of instrument's price in the deposit currency.
But in fact, it returns the value of the minimal change of the symbol price in the deposit currency of 1 lot of the contract.
In your example,MarketInfo(Symbol(),MODE_TICKVALUE)) will return 1. And then everything is correct. I tried it on real dollar and ruble accounts and it works. Here is the script I used to check it:
#property copyright "Copyright 2016, MetaQuotes Software Corp.
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property show_inputs
extern double risk=0.10;
extern int sl=1000;
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
Alert(NormalizeDouble(AccountBalance()*risk/(sl*MarketInfo(Symbol(),MODE_TICKVALUE),2))
}
//+------------------------------------------------------------------+
You are right. Checking with a script is faster and more reliable
We also need to make the accuracy in NormaliseDouble function depend on the minimum allowed lot. If you pass a lot to the OrderSend function, for example, 0.11, and the tool is traded only with lots multiple of 0.1, there will be an error.
I can't understand why open trades are not deleted all at once, i.e. EA deletes some of them, but error orderdelete 4108, market order cannot be deleted several times, and only then deletes them.
I can't understand why open trades are not deleted all at once, i.e. EA deletes some of them, but error orderdelete 4108, market order cannot be deleted several times, and only then deletes them.
This page explains how to delete. You have 2 errors.
On startup there is a constant error array out of range in 'expert1.0.mq4' (69,25)... I understood that it's about the array. I don't know what to do.
Need to see the code, or a piece of it, handling this array.
Telepaths, have a rest today.
You need to look at the code or a piece of code that handles the array.
Telepaths, have a rest today.
}
Here's the function.
I just thought the problem wasn't in the code as there are no errors in standard mode.