Ставь лайки и следи за новостями
Поставь на него ссылку - пусть другие тоже оценят
Оцени его работу в терминале MetaTrader 5
Basic Money Management code - эксперт для MetaTrader 5
- Просмотров:
- 1343
- Рейтинг:
- Опубликован:
- 2021.02.24 07:37
- Нужен робот или индикатор на основе этого кода? Закажите его на бирже фрилансеров Перейти на биржу
Description
The presented script represents the main tools for money and risk management when trading an advisor.
The presented code allows:
- Dynamically change position volume relative to balance
- Set the minimum and maximum position volume
- Use whole volumes (for example, for trading stocks where only whole volumes are allowed)
- Compulsory close ( Margin Call ) all positions upon reaching a certain percentage drawdown relative to the initial account
- Create a ban on opening long positions
- Create a ban on opening short positions
I recommend dynamically changing the used volume and handling forced closing of a position in the OnTick () method.
Volume control
By default, the volume is calculated using the formula: Volume = MathFloor (Balance / InpCoefficient) * InpVolumeStep
where, MathFloor - Round the value down (to the nearest integer)
If the maximum allowable (InpInpMaximumVolume) or minimum allowable (InpMinimumVolume) is exceeded, then the volume is set in accordance with the limit specified in the settings.
If the calculated volume exceeds the required collateral, then the volume will be recalculated in accordance with the admissible level of collateral for the position, the code implementation is presented below.
//--- if ( SymbolInfoDouble ( _Symbol , SYMBOL_TRADE_LIQUIDITY_RATE ) * Volume > Balance) { Volume = MathFloor (Balance/( SymbolInfoDouble ( _Symbol , SYMBOL_TRADE_LIQUIDITY_RATE ) * Volume)) * InpVolumeStep; if (InpUseIntegerVolume) { Volume = MathFloor (Volume); } if (Volume < InpMinimumVolume) { Print ( "" ); Print ( "Error!" ); Print ( "Used unavailable volume: " ,Volume); Print ( "Minimum volume is: " ,InpMinimumVolume); Print ( "" ); Volume = 0 ; } } //---
Using restrictions on opening long or short positions
When you enable the prohibition on the use of long or short positions ( InpUseLong , InpUseShort ), use the following insert when opening a position:
// use InpUseLong example if (InpUseLong) { OpenOrder( "long" ); } else { Print ( "" ); Print ( "Error!" ); Print ( "Expert have no access for open Long position" ); Print ( "" ); } // use InpUseLong example if (InpUseShort) { OpenOrder( "short" ); } else { Print ( "" ); Print ( "Error!" ); Print ( "Expert have no access for open Short position" ); Print ( "" ); }
The OpenOrder and CloseOrder methods are provided as examples. They are described at the end of the file.
For the OpenOrder method, you must write a condition that prohibits opening a position after the forced closing of a position, as shown in the following insert:
//+------------------------------------------------------------------+ //| Empty OpenOrder method | //+------------------------------------------------------------------+ void OpenOrder( string type) { if (CanOpenOrder) { // some code for open position } }
Индикатор iWPR (Williams’ Percent Range, WPR) сглаженный при помощи iMA (Moving Average, MA)
ZigZag RSIZigZag Rsi построен на базе осциллятора RSI.
Информационный индикатор: выводит три графики (M5, H1 и D1) и на каждом два пользовательских индикатора 'Custom Moving Average Inputs'
Elder iForce Strategy Pending 2На основе стратегии А. Элдера. Используются пользовательские индикаторы MA Color N Bars и Force Color