diff --git a/Experts/Nkanven/CandleCount.mq5 b/Experts/Nkanven/CandleCount.mq5 index 4dcaa4d..3a7afb9 100644 --- a/Experts/Nkanven/CandleCount.mq5 +++ b/Experts/Nkanven/CandleCount.mq5 @@ -14,22 +14,20 @@ #include //Trading conditions checks #include //Lot size calculator #include //Lot size calculator -#include //Emergency close of transaction //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ +#include -#include -CiATR* atr; - +CiMA* sma; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int OnInit() { //--- - atr = new CiATR(); - atr.Create(gSymbol, InpTimeFrame, InpAtrPeriod); + sma = new CiMA(); + sma.Create(gSymbol, InpTimeFrame, InpPeriods, InpAppliedPrice, InpMethod, PRICE_CLOSE); //--- return(INIT_SUCCEEDED); } @@ -49,24 +47,20 @@ void OnTick() //--- TimeCurrent(dt); - SymbolInfoTick(_Symbol,last_tick); + SymbolInfoTick(InpInstrument1,last_tick); + SymbolInfoTick(InpInstrument2, blast_tick); + + sma.Refresh(-1); + gSma = sma.Main(1); CheckOperationHours(); CheckPreChecks(); ScanPositions(); - //Get ATR values - atr.Refresh(-1); - gAtr = atr.Main(1); - if(!gIsPreChecksOk) return; - if(InpActivateRiskWatcher) - { - drawdownWatcher(); - CloseTransactions(); - } + Print("Good for trading..."); ExecuteEntry(); } //+------------------------------------------------------------------+ diff --git a/Include/Nkanven/CandleCount/CloseTransactions.mqh b/Include/Nkanven/CandleCount/CloseTransactions.mqh index ab1575d..e69de29 100644 --- a/Include/Nkanven/CandleCount/CloseTransactions.mqh +++ b/Include/Nkanven/CandleCount/CloseTransactions.mqh @@ -1,74 +0,0 @@ -//+------------------------------------------------------------------+ -//| CloseTransactions.mqh | -//| Copyright 2021, Nkondog Anselme Venceslas | -//| https://www.mql5.com | -//+------------------------------------------------------------------+ -#property copyright "Copyright 2021, Nkondog Anselme Venceslas" -#property link "https://www.mql5.com" - -CTrade trade; - -//+------------------------------------------------------------------+ -//| | -//+------------------------------------------------------------------+ -void CloseTransactions() - { - bool result = true; - int cts = PositionsTotal(); - ulong theTicket; - double positionProfit = 0.0; - - if(cts > 0) - { - for(int i = cts-1; i>=0; i--) - { - ulong ticket = PositionGetTicket(i); - if(PositionSelectByTicket(ticket)) - { - if(PositionGetInteger(POSITION_MAGIC)==InpMagicNumber) - { - if(positionProfit > PositionGetDouble(POSITION_PROFIT)) - { - positionProfit = PositionGetDouble(POSITION_PROFIT); - theTicket = ticket; - } - } - } - else - { - Print("Error (", GetLastError(), ") while selecting position by ticket"); - } - } - if(gEmergencyClose) - { - if(!trade.PositionClose(theTicket)) - Print("Error (", GetLastError(), ") while deleting all buy positions"); - } - } - } -//+------------------------------------------------------------------+ - -//+------------------------------------------------------------------+ -//| | -//+------------------------------------------------------------------+ -void drawdownWatcher() - { - double amountDiff, equity, balance, percentDiff; - balance=AccountInfoDouble(ACCOUNT_BALANCE); - equity=AccountInfoDouble(ACCOUNT_EQUITY); - gEmergencyClose = false; - - if(equity < balance) - { - amountDiff = balance - equity; - percentDiff = (amountDiff*100)/balance; - - Print("amountDiff ", amountDiff, " percentDiff ", percentDiff, " InpMaxDrawdown ", InpMaxDrawdown); - - if(InpMaxDrawdown < percentDiff) - { - gEmergencyClose = true; - } - } - } -//+------------------------------------------------------------------+ diff --git a/Include/Nkanven/CandleCount/EntriesManager.mqh b/Include/Nkanven/CandleCount/EntriesManager.mqh index 0651068..4767f92 100644 Binary files a/Include/Nkanven/CandleCount/EntriesManager.mqh and b/Include/Nkanven/CandleCount/EntriesManager.mqh differ diff --git a/Include/Nkanven/CandleCount/Parameters.mqh b/Include/Nkanven/CandleCount/Parameters.mqh index 7d511d9..e4cc00c 100644 --- a/Include/Nkanven/CandleCount/Parameters.mqh +++ b/Include/Nkanven/CandleCount/Parameters.mqh @@ -73,26 +73,17 @@ input double InpMinLotSize=0.01; //Minimu 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 bool InpActivateRiskWatcher=false; //Active risk watcher -input string Comment_00="----------------------"; //Stop loss settings -input ENUM_MODE_SL InpStopLossMode=SL_FIXED; //Stop Loss Mode +input string Comment_01="----------------------"; //Stop loss settings 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 double InpMaxDrawdown=2.5; //Max DD level -input string Comment_01="----------------------"; //Take profit settings -input ENUM_MODE_TP InpTakeProfitMode=TP_FIXED; //Take Profit Mode +input string Comment_02="----------------------"; //Take profit settings 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 string Comment_1="========="; //ATR settings -// Average True Range -input int InpAtrPeriod = 14; //ATR period -input int InpAtrMultiplier = 3; //ATR multiplier - -input string Comment_2="=========="; //Trading Hours Settings +input string Comment_03="----------------------"; //Trading Hours Settings input bool InpUseTradingHours=false; //Limit Trading Hours input ENUM_MODE_TRADING_TIME InpTradingPeriods=ALL_DAY_TRADING; //Select trading periods input int InpDayTradingHourStart=7; //Day Trading Start Hour (Broker Server Hour) @@ -100,18 +91,26 @@ input int InpDayTradingHourEnd=21; //Day Tr input int InpNightTradingHourStart=1; //Night Trading Start Hour (Broker Server Hour) input int InpNightTradingHourEnd=5; //Night Trading End Hour (Broker Server Hour) -input string Comment_02="----------------------"; //Stop loss settings +input string Comment_04="----------------------"; //DCA settings +input bool InpActivateDCAHedging=false; //Active DCA Hedging +input string InpInstrument1="EURUSD.i"; //Instrument 1 +input string InpInstrument2="USDCHF.i"; //Instrument 2 + +input string Comment_05="----------------------"; //Stop loss settings +// Fast moving average +input int InpPeriods = 21; // Fast periods +input ENUM_MA_METHOD InpMethod = MODE_SMA; // Fast method +input ENUM_APPLIED_PRICE InpAppliedPrice = PRICE_CLOSE; // Fast price input string InpComment = __FILE__; //Default trade comment input int InpMagicNumber = 198901; //Magic Number input ENUM_TIMEFRAMES InpTimeFrame = PERIOD_CURRENT; -input double InpMinCandleLenght = 25.0; //Min candle length -input int InpCandleWickPercent = 75; //Candle wick percent +input int InpSameCandleCount= 2; //Same Candle in a row //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ string gSymbol = Symbol(); -double gAtr; +double gSma; int gTotalSellPositions, gTotalBuyPositions, gTotalPositions; bool gIsOperatingHours=false; @@ -128,6 +127,6 @@ long Spread = SymbolInfoInteger(gSymbol,SYMBOL_SPREAD) / 100; //Check t int gOrderOpRetry = 10; -MqlTick last_tick; +MqlTick last_tick, blast_tick; MqlDateTime dt; //+------------------------------------------------------------------+