//+------------------------------------------------------------------+ //| GDeaLite.mq5 | //| Copyright 2021, Nkondog Anselme Venceslas | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2021, Nkondog Anselme Venceslas" #property link "https://www.mql5.com" #property version "1.00" #include #include CiMA* fsma; CiMA* ssma; CiATR* atr; #include // Description of variables #include // Error library #include // Prechecks #include // #include #include // Scan for opened positions #include //Check transaction history #include //Manage trade dynamic open and close conditions #include // Check buy and sell entries signals and execute them #include // Lot size calculate #include // Close opened positions //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- fsma = new CiMA(); ssma = new CiMA(); fsma.Create(gSymbol, PERIOD_CURRENT, InpFastPeriods, InpFastAppliedPrice, InpFastMethod, PRICE_CLOSE); ssma.Create(gSymbol, PERIOD_CURRENT, InpSlowPeriods, InpFastAppliedPrice, InpSlowMethod, PRICE_CLOSE); atr = new CiATR(); atr.Create(gSymbol, PERIOD_CURRENT, InpAtrPeriod); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- fsma.Refresh(-1); ssma.Refresh(-1); gSsma = ssma.Main(1); //isQualifiedCandle(0); OrderClose(); if(!ScanPositions()) return; if(OrdersTotal()>0) return; CheckSpread(); entryConditions(); EvaluateEntry(); ExecuteEntry(); Comment( "Expert Advisor by Anselme Nkondog (c) 2021\n"); } //+------------------------------------------------------------------+ //Initialize variables void InitializeVariables() { gIsNewCandle=false; gIsTradedThisBar=false; gIsOperatingHours=false; gIsSpreadOK=false; gLotSize=InpDefaultLotSize; gTickValue=0; gTotalOpenBuy=0; gTotalOpenSell=0; gSignalEntry=SIGNAL_ENTRY_NEUTRAL; gSignalExit=SIGNAL_EXIT_NEUTRAL; Print("Variables intialized"); } //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=SymbolInfoInteger(gSymbol, SYMBOL_SPREAD); Print("Spread ", SpreadCurr); if(SpreadCurr<=InpMaxSpread) { gIsSpreadOK=true; } else { gIsSpreadOK=false; } } //+------------------------------------------------------------------+