mirror of
https://github.com/rithsila/MT5-EA-Sniper-Strategy.git
synced 2026-07-27 18:47:57 +00:00
Update LotCal mt4 and mt5
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,53 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| NYMidnightBreak.mq5 |
|
||||
//| Copyright 2022, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2022, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property version "1.00"
|
||||
|
||||
#include <Nkanven\NYMidnightBreak\Parameters.mqh> // EA paramters
|
||||
#include <Nkanven\NYMidnightBreak\LotSizeCal.mqh> // Lot size calculator
|
||||
|
||||
#define SECONDSINADAY 86400
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//---
|
||||
|
||||
//---
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert deinitialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//---
|
||||
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert tick function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnTick()
|
||||
{
|
||||
//---
|
||||
//--- The date is on Sunday
|
||||
datetime time=D'2002.04.25 12:00';
|
||||
string symbol="GBPUSD";
|
||||
ENUM_TIMEFRAMES tf=PERIOD_H1;
|
||||
bool exact=false;
|
||||
//--- If there is no bar at the specified time, iBarShift will return the index of the nearest bar
|
||||
int bar_index=iBarShift(symbol,tf,time,exact);
|
||||
//--- Check the error code after the call of iBarShift()
|
||||
|
||||
datetime Midnight, StartOfNewYear;
|
||||
|
||||
|
||||
Midnight = TimeCurrent() - ( TimeCurrent()%SECONDSINADAY ); // midnight today as a datetime
|
||||
Print(" Hour ", dt.hour, " midnight " , Midnight);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,30 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Functions.mqh |
|
||||
//| Copyright 2022, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2022, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
|
||||
|
||||
//Check and return if the spread is not too high
|
||||
void CheckSpread()
|
||||
{
|
||||
//Get the current spread in points, the (int) transforms the double coming from MarketInfo into an integer to avoid a warning when compiling
|
||||
long SpreadCurr=(int)Spread;
|
||||
Print("Spread ", Spread);
|
||||
if(SpreadCurr<=InpMaxSpread)
|
||||
{
|
||||
IsSpreadOK=true;
|
||||
}
|
||||
else
|
||||
{
|
||||
IsSpreadOK=false;
|
||||
}
|
||||
}
|
||||
|
||||
double GetSignalBoundries()
|
||||
{
|
||||
//Get midnight high and low
|
||||
iHigh()
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| LotSizeCal.mqh |
|
||||
//| Copyright 2021, Nkondog Anselme Venceslas |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2021, Nkondog Anselme Venceslas"
|
||||
#property link "https://www.mql5.com"
|
||||
|
||||
|
||||
//Lot Size Calculator
|
||||
void LotSizeCalculate(double SL=0)
|
||||
{
|
||||
//If the position size is dynamic
|
||||
if(InpRiskDefaultSize==RISK_DEFAULT_AUTO)
|
||||
{
|
||||
//If the stop loss is not zero then calculate the lot size
|
||||
if(SL!=0)
|
||||
{
|
||||
double RiskBaseAmount=0;
|
||||
|
||||
//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);
|
||||
//Define the base for the risk calculation depending on the parameter chosen
|
||||
if(InpRiskBase==RISK_BASE_BALANCE)
|
||||
RiskBaseAmount=AccountInfoDouble(ACCOUNT_BALANCE);
|
||||
if(InpRiskBase==RISK_BASE_EQUITY)
|
||||
RiskBaseAmount=AccountInfoDouble(ACCOUNT_EQUITY);
|
||||
if(InpRiskBase==RISK_BASE_FREEMARGIN)
|
||||
RiskBaseAmount=AccountInfoDouble(ACCOUNT_FREEMARGIN);
|
||||
|
||||
//Calculate the Position Size
|
||||
LotSize=((RiskBaseAmount*InpMaxRiskPerTrade/100)/(SL*TickValue));
|
||||
}
|
||||
//If the stop loss is zero then the lot size is the default one
|
||||
if(SL==0)
|
||||
{
|
||||
LotSize=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);
|
||||
|
||||
//Limit the lot size in case it is greater than the maximum allowed by the user
|
||||
if(LotSize>InpMaxLotSize)
|
||||
LotSize=InpMaxLotSize;
|
||||
//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 the lot size is too small then set it to 0 and don't trade
|
||||
if(LotSize<InpMinLotSize || LotSize < SymbolInfoDouble(gSymbol,SYMBOL_VOLUME_MIN))
|
||||
{
|
||||
LotSize=0;
|
||||
Print("Lot size too small : ", LotSize);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Parameters.mqh |
|
||||
//| Copyright 2021, Nkondog Anselme Venceslas |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2021, Nkondog Anselme Venceslas"
|
||||
#property link "https://www.mql5.com"
|
||||
|
||||
|
||||
//Enumerative for the positioning
|
||||
enum ENUM_POSITIONING
|
||||
{
|
||||
STANDARD_BUY=1,
|
||||
TWO_SL_BUY=2,
|
||||
THREE_SL_BUY=3,
|
||||
};
|
||||
|
||||
//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
|
||||
};
|
||||
|
||||
//Enumerative for the default risk size
|
||||
enum ENUM_RISK_DEFAULT_SIZE
|
||||
{
|
||||
RISK_DEFAULT_FIXED=1, //FIXED SIZE
|
||||
RISK_DEFAULT_AUTO=2, //AUTOMATIC SIZE BASED ON RISK
|
||||
};
|
||||
|
||||
//Enumerative for the Stop Loss mode
|
||||
enum ENUM_MODE_SL
|
||||
{
|
||||
SL_FIXED=0, //FIXED STOP LOSS
|
||||
SL_AUTO=1, //AUTOMATIC STOP LOSS
|
||||
};
|
||||
|
||||
//Enumerative for the Take Profit Mode
|
||||
enum ENUM_MODE_TP
|
||||
{
|
||||
TP_FIXED=0, //FIXED TAKE PROFIT
|
||||
TP_AUTO=1, //AUTOMATIC TAKE PROFIT
|
||||
};
|
||||
|
||||
//Enumerative for the stop loss calculation
|
||||
enum ENUM_MODE_SL_BY
|
||||
{
|
||||
SL_BY_POINTS=0, //STOP LOSS PASSED IN POINTS
|
||||
SL_BY_PRICE=1, //STOP LOSS PASSED BY PRICE
|
||||
};
|
||||
|
||||
struct LastTransaction
|
||||
{
|
||||
string time;
|
||||
int type;
|
||||
double profit;
|
||||
} lt;
|
||||
|
||||
//
|
||||
// Input Section
|
||||
//
|
||||
|
||||
input string Comment_0="=========="; //Risk Management Settings
|
||||
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 ENUM_RISK_BASE InpRiskBase=RISK_BASE_BALANCE; //Risk Base
|
||||
input double InpMaxRiskPerTrade=4.5; //Percentage To Risk Each Trade
|
||||
input double InpMinLotSize=0.01; //Minimum Position Size Allowed
|
||||
input double InpMaxLotSize=100; //Maximum Position Size Allowed
|
||||
input int InpMaxSpread=10; //Maximum Spread Allowed
|
||||
input int InpSlippage=1; //Maximum Slippage Allowed in points
|
||||
input double InpDefaultSize=1.0;
|
||||
input double InpOneSlSize=3.77;
|
||||
input double InpTwoSlSize=7.55;
|
||||
input ENUM_MODE_SL InpStopLossMode=SL_FIXED; //Stop Loss Mode
|
||||
input int InpDefaultStopLoss=200; //Default Stop Loss In Points (0=No Stop Loss)
|
||||
input int InpMinStopLoss=0; //Minimum Allowed Stop Loss In Points
|
||||
input int InpMaxStopLoss=5000; //Maximum Allowed Stop Loss In Points
|
||||
input ENUM_MODE_TP InpTakeProfitMode=SL_FIXED; //Take Profit Mode
|
||||
input int InpDefaultTakeProfit=60; //Default Take Profit In Points (0=No Take Profit)
|
||||
input int InpMinTakeProfit=0; //Minimum Allowed Take Profit In Points
|
||||
input int InpMaxTakeProfit=5000; //Maximum Allowed Take Profit In Points
|
||||
input double InpTakeProfitPercent=1.0; //Take Profit percent on risk base
|
||||
|
||||
input int InpChallengePhase=1;
|
||||
|
||||
|
||||
// Some standard inputs,
|
||||
// remember to change the default magic for each EA
|
||||
//
|
||||
input double InpVolume = 0.01; // Default order size
|
||||
input string InpComment = __FILE__; // Default trade comment
|
||||
input int InpMagicNumber = 198901; // Magic Number
|
||||
|
||||
input string Comment_1="=========="; //Trading Hours Settings
|
||||
input bool InpUseTradingHours=false; //Limit Trading Hours
|
||||
input string InpTradingHourStart="01"; //Trading Start Hour (Broker Server Hour)
|
||||
|
||||
bool gIsNewCandle=false;
|
||||
bool gIsTradedThisBar=false;
|
||||
bool gIsOperatingHours=false;
|
||||
bool gIsPreChecksOk=false; //Indicates if the pre checks are satisfied
|
||||
bool gIsSpreadOK=false; //Indicates if the spread is low enough to trade
|
||||
bool IsSpreadOK=false;
|
||||
bool IsLosing=false;
|
||||
|
||||
|
||||
double gLotSize=InpDefaultLotSize;
|
||||
double gLotMultiplier=InpDefaultSize;
|
||||
|
||||
string Symb=Symbol();
|
||||
string subfolder=AccountInfoInteger(ACCOUNT_LOGIN);
|
||||
string filename = subfolder+"\\balanceStored.txt";
|
||||
int gTickValue=0;
|
||||
long Spread = SymbolInfoInteger(Symb,SYMBOL_SPREAD) / 100; //Check the impact. It's originally a double
|
||||
|
||||
int gStandardRisk[] = {3, -1, 0, -4};
|
||||
int gTwoSL = -2;
|
||||
int gOneSL[] = {1, -3};
|
||||
int gOrderOpRetry = 10;
|
||||
|
||||
string gSymbol = Symbol();
|
||||
|
||||
double LotSize=0;
|
||||
|
||||
MqlTick last_tick;
|
||||
MqlDateTime dt;
|
||||
ENUM_POSITIONING gBuyPositioning=STANDARD_BUY;
|
||||
BIN
Binary file not shown.
+11
-9
@@ -40,6 +40,10 @@ input double InpMaxLotSize=100; //Maximu
|
||||
string Symb = Symbol();
|
||||
double LotSize=InpDefaultLotSize;
|
||||
double price=0.0;
|
||||
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 |
|
||||
@@ -64,14 +68,14 @@ void OnTick()
|
||||
{
|
||||
LotSizeCalculate(price);
|
||||
//Comment("Lot size : ", LotSize);
|
||||
|
||||
string text ="Lot size for "+ InpMaxRiskPerTrade +"% = " + DoubleToString(LotSize,2);
|
||||
double StopAmount = StoplossPips * LotSize * TickValue;
|
||||
string text ="Lot size for "+ InpMaxRiskPerTrade +"% = " + DoubleToString(LotSize,2) + " lot (" + DoubleToString(StopAmount, 2) + " " + AccountInfoString(ACCOUNT_CURRENCY) + ")";
|
||||
string name = "Lot";
|
||||
ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
|
||||
ObjectSetText(name,text, 36, "Corbel Bold", YellowGreen);
|
||||
ObjectSet(name, OBJPROP_CORNER, 2);
|
||||
ObjectSet(name, OBJPROP_XDISTANCE, 15);
|
||||
ObjectSet(name, OBJPROP_YDISTANCE, 1);
|
||||
ObjectSetText(name,text, 14, "Corbel Bold", YellowGreen);
|
||||
ObjectSet(name, OBJPROP_CORNER, CORNER_RIGHT_UPPER);
|
||||
ObjectSet(name, OBJPROP_XDISTANCE, 350);
|
||||
ObjectSet(name, OBJPROP_YDISTANCE, 10);
|
||||
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -126,8 +130,6 @@ void LotSizeCalculate(double stopLoss)
|
||||
if(SL!=0)
|
||||
{
|
||||
double RiskBaseAmount=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);
|
||||
//Define the base for the risk calculation depending on the parameter chosen
|
||||
if(InpRiskBase==RISK_BASE_BALANCE)
|
||||
RiskBaseAmount=AccountInfoDouble(ACCOUNT_BALANCE);
|
||||
@@ -142,7 +144,7 @@ void LotSizeCalculate(double stopLoss)
|
||||
Print("RiskBaseAmount ", RiskBaseAmount, " MaxRiskPerTrade ", InpMaxRiskPerTrade, "Stop loss ", SL, " TickValue ", TickValue);
|
||||
|
||||
LotSize=((RiskBaseAmount*InpMaxRiskPerTrade/100)/(SL*TickValue));
|
||||
|
||||
StoplossPips = SL;
|
||||
}
|
||||
//If the stop loss is zero then the lot size is the default one
|
||||
if(SL==0)
|
||||
|
||||
Reference in New Issue
Block a user