//+------------------------------------------------------------------+ //| SimpleEATemplatev1.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 group "Inputs Group 1" input double IL=0.1; // IL Initial Lot input double SL = 0.01; // SL Stop Loss as Percent of Balance input double TP = 150; // TP Take Profit in Points //Include Files #include CTrade trade; //Trade Class // Variables Defintions 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 void OnTick() { // Trade structures MqlTradeRequest request; MqlTradeResult result; ZeroMemory(request); //+------------------------------------------------------------------+ //| Price | //+------------------------------------------------------------------+ double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits); double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits); //+------------------------------------------------------------------+ //| 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 | //+------------------------------------------------------------------+ //string signal=""; MqlRates PriceInformation[]; ArraySetAsSeries(PriceInformation,true); int Data=CopyRates(Symbol(),Period(),0,3,PriceInformation); double PriceArray[]; int AwesomeOscillatorDefinition = iAO(_Symbol,_Period); ArraySetAsSeries(PriceArray,true); CopyBuffer(AwesomeOscillatorDefinition,0,0,3,PriceArray); double AwesomeOscillatorValue=NormalizeDouble(PriceArray[0],6); if(AwesomeOscillatorValue>0) signal =0; // Buy if(AwesomeOscillatorValue<0) signal =1; // Sell //+------------------------------------------------------------------+ //| Control | //+------------------------------------------------------------------+ if(CL==0)if(LT>=1)if(Equity=1)if(Equity=0; i--) { ulong ticket=PositionGetTicket(i); PositionSelectByTicket(ticket); if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) { trade.PositionClose(ticket); // changed i for ticket and that was giving me a lot of trouble. } } CL=0; Print("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; Print("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", "Signal:", signal, "\n" ); }