forked from e187038/SP_GVA1
189 lines
15 KiB
MQL5
189 lines
15 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| SimpleEATemplatev1.2.mq5 coded on DELL-SP3|
|
|
//| Copyright 2024, Singularity Partners Sarl. |
|
|
//| https://www.SingularityPartners.ch |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Copyright 2024, Singularity Partners Sarl."
|
|
#property link "https://www.SingularityPartners.ch"
|
|
#property version "1.0" // based on A6.16.4
|
|
// Idea of this EA is (Describe the intention of this EA)
|
|
// Results from 1 Jan 2017 until 1 Jan 2024: UR:3 RDD:22% Sharpe Ratio:2.08 %Profit:33% or so. T=980 R7=36,529
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Input Variables |
|
|
//+------------------------------------------------------------------+
|
|
//Input Variables
|
|
input group "Copyright 2024, www.SingularityPartners.ch "
|
|
input double IL = 0.1; // IL Initial Lot
|
|
input double SL = 0.05; // SL Stop Loss as Percent of Balance
|
|
//input double TP = 0.03; // TP Take Profit as Percent of Balance
|
|
input double TPP = 1000; // TPP Take Profit in Points
|
|
input double SLP = 2600; // SLP Stop Loss in Points
|
|
|
|
input group "Signal Inputs"
|
|
input uint Period = 67; // Period iMA
|
|
input uint Shift = 6; // Shift iMA
|
|
|
|
input ENUM_MA_METHOD METHOD = MODE_LWMA;
|
|
input ENUM_APPLIED_PRICE APPLIED_PRICE = PRICE_WEIGHTED;
|
|
input uint CBA =9; // CBA CopyBufferAmount
|
|
input uint EMAFirst = 2 ;
|
|
input uint EMASecond = 4 ;
|
|
|
|
//Include Files
|
|
#include<Trade\Trade.mqh>
|
|
CTrade trade; //Trade Class
|
|
|
|
// Variables Definitions
|
|
bool signal;
|
|
bool CS; // Close Shorts
|
|
bool CL; // Close Longs
|
|
int LT; // Counter of Long Trades
|
|
int ST; // Counter of Short Trades
|
|
int T; // Counter of Total Trades
|
|
int L; // Code Line
|
|
double EMAArray[];
|
|
|
|
|
|
|
|
|
|
|
|
void OnTick()
|
|
{
|
|
|
|
// Trade structures
|
|
MqlTradeRequest request;
|
|
MqlTradeResult result;
|
|
ZeroMemory(request);
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Price |
|
|
//+------------------------------------------------------------------+
|
|
|
|
// Price
|
|
double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
|
|
double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Balance, Equity, Profit |
|
|
//+------------------------------------------------------------------+
|
|
|
|
// Balance, Equity, Profit
|
|
double Balance=NormalizeDouble(AccountInfoDouble(ACCOUNT_BALANCE),0);
|
|
double Equity=NormalizeDouble(AccountInfoDouble(ACCOUNT_EQUITY),0);
|
|
double Profit=NormalizeDouble(AccountInfoDouble(ACCOUNT_PROFIT),0);
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Longs Shorts Counter |
|
|
//+------------------------------------------------------------------+
|
|
|
|
LT=0; ST=0; T=0;
|
|
for(int i = 0; i < PositionsTotal(); i++)
|
|
{
|
|
ulong ticket = PositionGetTicket(i);
|
|
PositionSelectByTicket(ticket);
|
|
|
|
if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) // if it's a long'
|
|
{
|
|
LT ++;
|
|
}
|
|
else if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL) // if it's short
|
|
{
|
|
ST ++;
|
|
}
|
|
T=(LT+ST);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Sensing |
|
|
//+------------------------------------------------------------------+
|
|
|
|
int EMA = iMA(_Symbol,_Period,Period,Shift,METHOD,PRICE_CLOSE);
|
|
ArraySetAsSeries(EMAArray,true);
|
|
CopyBuffer(EMA,0,0,CBA,EMAArray);
|
|
if(EMAArray[EMAFirst]>EMAArray[EMASecond]) signal=0;L=__LINE__; // Signal Long or Buy is Zero
|
|
if(EMAArray[EMAFirst]<EMAArray[EMASecond]) signal=1;L=__LINE__; // Signal Short or Sell is One
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Control |
|
|
//+------------------------------------------------------------------+
|
|
|
|
if(CL==0)if(LT>=1)if(Equity<Balance*(1-SL)){CL=1;L=__LINE__;Print("************ CL=1 L:",L);} // Stop Loss when Equity goes below (1-SL)
|
|
if(CS==0)if(ST>=1)if(Equity<Balance*(1-SL)){CS=1;L=__LINE__;Print("************ CS=1 L:",L);}
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Actuation |
|
|
//+------------------------------------------------------------------+
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| OPENING LONGS |
|
|
//+------------------------------------------------------------------+
|
|
|
|
if(signal==0 && PositionsTotal()<1)
|
|
trade.Buy(IL,NULL,Ask,(Ask-SLP*_Point),(Ask+TPP*_Point),NULL);L=__LINE__;Print("############ OL=1 L:",__LINE__);
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| OPENING SHORTS |
|
|
//+------------------------------------------------------------------+
|
|
|
|
if(signal==1 && PositionsTotal()<1)
|
|
trade.Sell(IL,NULL,Bid,(Bid+SLP*_Point),(Bid-TPP*_Point),NULL);L=__LINE__;Print("########### OS=1 L:",__LINE__);
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| CLOSING LONGS |
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
|
if(CL==1)
|
|
{
|
|
for(int i=PositionsTotal()-1;i>=0; i--)
|
|
{
|
|
ulong ticket=PositionGetTicket(i);
|
|
PositionSelectByTicket(ticket);
|
|
if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
|
|
{
|
|
trade.PositionClose(ticket);
|
|
}
|
|
}
|
|
CL=0;
|
|
L=__LINE__;Print("CL=1 CONFIRMED. L:",__LINE__);
|
|
}
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| CLOSING SHORTS |
|
|
//+------------------------------------------------------------------+
|
|
|
|
if(CS==1)
|
|
{
|
|
for(int i=PositionsTotal()-1;i>=0; i--)
|
|
{
|
|
ulong ticket2=PositionGetTicket(i);
|
|
PositionSelectByTicket(ticket2);
|
|
if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
|
|
{
|
|
trade.PositionClose(ticket2);
|
|
}
|
|
}
|
|
CS=0;
|
|
L=__LINE__;Print("CS=1 CONFIRMED. L:",__LINE__);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Dashboard |
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
|
Comment("© Singularity Partners 2024","\n",
|
|
"CODE LINE:",L,"\n",
|
|
"Balance:",DoubleToString(Balance,0)," Equity:",DoubleToString(Equity,0)," Profit:",DoubleToString(Profit,0),"\n",
|
|
|
|
"LT: ",LT," ST: ",ST," T:",PositionsTotal(),"\n",
|
|
"CL:",CL," CS:",CS,"\n",
|
|
" EMAFirst:",NormalizeDouble(EMAArray[EMAFirst],_Digits)," EMASecond:",NormalizeDouble(EMAArray[EMASecond],_Digits)," signal:",signal, "\n"
|
|
|
|
);
|
|
|
|
|
|
}
|