Done for backtest with initial configuration

This commit is contained in:
Nkondog Anselme
2022-03-10 22:57:14 +01:00
parent 8fef962788
commit 14ceb7afe6
4 changed files with 20 additions and 17 deletions
Binary file not shown.
Binary file not shown.
+19 -14
View File
@@ -17,6 +17,7 @@ void LotSizeCalculate(double SL=0)
if(SL!=0)
{
double RiskBaseAmount=0;
Print("Compute lot size");
//TickValue is the value of the individual price increment for 1 lot of the instrument, expressed in the account currenty
double TickValue=SymbolInfoDouble(gSymbol,SYMBOL_TRADE_TICK_VALUE);
@@ -29,28 +30,32 @@ void LotSizeCalculate(double SL=0)
RiskBaseAmount=AccountInfoDouble(ACCOUNT_FREEMARGIN);
//Calculate the Position Size
LotSize=((RiskBaseAmount*InpMaxRiskPerTrade/100)/(SL*TickValue));
gLotSize=((RiskBaseAmount*InpMaxRiskPerTrade/100)/(SL*TickValue));
Print("(RiskBaseAmount ", RiskBaseAmount, " InpMaxRiskPerTrade ", InpMaxRiskPerTrade, " SL ", SL, " TickValue ", TickValue);
}
//If the stop loss is zero then the lot size is the default one
if(SL==0)
/*if(SL==0)
{
LotSize=InpDefaultLotSize;
}
gLotSize=InpDefaultLotSize;
}*/
}
//Normalize the Lot Size to satisfy the allowed lot increment and minimum and maximum position size
LotSize=MathFloor(LotSize/SymbolInfoDouble(gSymbol,SYMBOL_VOLUME_STEP))*SymbolInfoDouble(gSymbol,SYMBOL_VOLUME_STEP);
gLotSize=MathFloor(gLotSize/SymbolInfoDouble(gSymbol,SYMBOL_VOLUME_STEP))*SymbolInfoDouble(gSymbol,SYMBOL_VOLUME_STEP);
//Limit the lot size in case it is greater than the maximum allowed by the user
if(LotSize>InpMaxLotSize)
LotSize=InpMaxLotSize;
Print("LotSize ", gLotSize);
//Limit the lot size in case it is greater than the maximum allowed by the broker
if(LotSize>SymbolInfoDouble(gSymbol,SYMBOL_VOLUME_MAX))
LotSize=SymbolInfoDouble(gSymbol,SYMBOL_VOLUME_MAX);
Print("Lot ", LotSize, " Max lot ", SymbolInfoDouble(gSymbol,SYMBOL_VOLUME_MAX));
if(gLotSize>SymbolInfoDouble(gSymbol,SYMBOL_VOLUME_MAX))
gLotSize=SymbolInfoDouble(gSymbol,SYMBOL_VOLUME_MAX);
Print("Lot ", gLotSize, " Max lot ", SymbolInfoDouble(gSymbol,SYMBOL_VOLUME_MAX));
Print("LotSize2 ", gLotSize);
//If the lot size is too small then set it to 0 and don't trade
if(LotSize<InpMinLotSize || LotSize < SymbolInfoDouble(gSymbol,SYMBOL_VOLUME_MIN))
if(gLotSize<InpMinLotSize || gLotSize < SymbolInfoDouble(gSymbol,SYMBOL_VOLUME_MIN))
{
LotSize=0;
Print("Lot size too small : ", LotSize);
gLotSize=0;
Print("Lot size too small : ", gLotSize);
}
Print("LotSize3 ", gLotSize);
}
+1 -3
View File
@@ -74,7 +74,7 @@ input string Comment_0="=========="; //Risk M
input double InpVolume = 0.01; //Default order size
input ENUM_RISK_DEFAULT_SIZE InpRiskDefaultSize=RISK_DEFAULT_AUTO; //Position Size Mode
input double InpDefaultLotSize=1; //Position Size (if fixed or if no stop loss defined)
input double InpDefaultLotSize=0.01; //Position Size (if fixed or if no stop loss defined)
input ENUM_RISK_BASE InpRiskBase=RISK_BASE_BALANCE; //Risk Base
input double InpMaxRiskPerTrade=0.5; //Percentage To Risk Each Trade
input double InpMinLotSize=0.01; //Minimum Position Size Allowed
@@ -129,8 +129,6 @@ long Spread = SymbolInfoInteger(gSymbol,SYMBOL_SPREAD) / 100; //Check the impac
int gOrderOpRetry = 10;
double LotSize=0;
MqlTick last_tick;
MqlDateTime dt;