Files
MT5-EA-Sniper-Strategy/Experts/Nkanven/Lotcal.mq5
T

198 lines
16 KiB
Plaintext
Raw Normal View History

2022-05-11 15:54:01 +01:00
//+------------------------------------------------------------------+
//| LotCal.mq4 |
//| Copyright 2022, Nkondog Anselme Venceslas. |
//| https://www.linkedin/in/nkondog.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, Nkondog Anselme Venceslas."
#property link "https://www.linkedin/in/nkondog.com "
#property version "1.00"
#property strict
//Parameters
MqlTick last_tick;
//Enumerative for the base used for risk calculation
enum ENUM_RISK_BASE
{
RISK_BASE_EQUITY=1, //EQUITY
RISK_BASE_BALANCE=2, //BALANCE
RISK_BASE_FREEMARGIN=3, //FREE MARGIN
RISK_BASE_INPUT=4, //INPUT BASE
};
2022-09-20 21:55:19 +01:00
//Enumerative for the default risk size
enum ENUM_RISK_DEFAULT_SIZE
2022-05-11 15:54:01 +01:00
{
RISK_DEFAULT_FIXED=1, //FIXED SIZE
RISK_DEFAULT_AUTO=2, //AUTOMATIC SIZE BASED ON RISK
};
input ENUM_RISK_DEFAULT_SIZE InpRiskDefaultSize=RISK_DEFAULT_AUTO; //Position Size Mode
input double InpBalance=10000.0; //Balance
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
double InpMinLotSize=0.01; //Minimum Position Size Allowed
double InpMaxLotSize=100; //Maximum Position Size Allowed
2022-09-20 21:55:19 +01:00
2022-05-11 15:54:01 +01:00
2022-09-20 21:55:19 +01:00
//+------------------------------------------------------------------+
2022-05-11 15:54:01 +01:00
//| |
//+------------------------------------------------------------------+
2022-09-20 21:55:19 +01:00
string Symb = Symbol();
2022-05-11 15:54:01 +01:00
double LotSize=InpDefaultLotSize;
2022-09-20 21:55:19 +01:00
double price=0.0;
2022-05-11 15:54:01 +01:00
double risk=0.0;
double StoplossPips=0.0;
//TickValue is the value of the individual price increment for 1 lot of the instrument, expressed in the account currenty
double TickValue=SymbolInfoDouble(Symb,SYMBOL_TRADE_TICK_VALUE);
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Print("The Expert Advisor with name ",MQLInfoString(MQL_PROGRAM_NAME)," is running");
//--- enable object create events
ChartSetInteger(ChartID(),CHART_EVENT_OBJECT_CREATE,true);
//--- enable object delete events
ChartSetInteger(ChartID(),CHART_EVENT_OBJECT_DELETE,true);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTick()
{
LotSizeCalculate(price);
//Comment("Lot size : ", LotSize);
double StopAmount = StoplossPips * LotSize * TickValue;
string text ="Lot size for "+ InpMaxRiskPerTrade +"% = " + DoubleToString(LotSize,2) + " lot (" + NormalizeDouble(StopAmount, 2) + " " + AccountInfoString(ACCOUNT_CURRENCY) + ")";
string name = "Lot";
string name2 = "risk";
ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0);
//ObjectSetText(name,text, 36, "Corbel Bold", YellowGreen);
2022-09-20 21:55:19 +01:00
2022-05-11 15:54:01 +01:00
ObjectSetInteger(0,name, OBJPROP_CORNER, CORNER_RIGHT_UPPER);
ObjectSetInteger(0,name, OBJPROP_XDISTANCE, 550);
ObjectSetInteger(0,name, OBJPROP_YDISTANCE, 10);
ObjectSetString(0,name,OBJPROP_TEXT,text);
ObjectSetString(0,name,OBJPROP_FONT,"Arial");
ObjectSetInteger(0,name,OBJPROP_FONTSIZE,14);
ObjectSetInteger(0,name,OBJPROP_COLOR,clrYellowGreen);
//LabelDelete(0, name);
}
//+------------------------------------------------------------------+
//| ChartEvent function |
//+------------------------------------------------------------------+
void OnChartEvent(const int id, // Event identifier
const long& lparam, // Event parameter of long type
const double& dparam, // Event parameter of double type
const string& sparam) // Event parameter of string type
{
//--- the object has been deleted
if(id==CHARTEVENT_OBJECT_DELETE)
{
Print("The object with name ",sparam," has been deleted");
}