The presented script represents the main tools for money and risk management when trading an advisor.
The presented code allows:
I recommend dynamically changing the used volume and handling forced closing of a position in the OnTick () method.
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 ; } } //---
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 } }
WPR Custom Smoothing
Индикатор iWPR (Williams’ Percent Range, WPR) сглаженный при помощи iMA (Moving Average, MA)
ZigZag RSI
ZigZag Rsi построен на базе осциллятора RSI.
Three information charts MA
Информационный индикатор: выводит три графики (M5, H1 и D1) и на каждом два пользовательских индикатора 'Custom Moving Average Inputs'
Elder iForce Strategy Pending 2
На основе стратегии А. Элдера. Используются пользовательские индикаторы MA Color N Bars и Force Color