diff --git a/Experts/Nkanven/HighTension.ex5 b/Experts/Nkanven/HighTension.ex5 index a02268c..2786363 100644 Binary files a/Experts/Nkanven/HighTension.ex5 and b/Experts/Nkanven/HighTension.ex5 differ diff --git a/Experts/Nkanven/HighTension.mq5 b/Experts/Nkanven/HighTension.mq5 index 816dd0a..262c038 100644 --- a/Experts/Nkanven/HighTension.mq5 +++ b/Experts/Nkanven/HighTension.mq5 @@ -25,7 +25,7 @@ const int indexColor = 1; int OnInit() { //--- - handle = iCustom(gSymbol, PERIOD_CURRENT, "MA-Slope", InpPeriods, InpMethod, InpAppliedPrice); + handle = iCustom(gSymbol, PERIOD_CURRENT, "Nkanven\MA-Slope", InpPeriods, InpMethod, InpAppliedPrice); if(handle == INVALID_HANDLE) { @@ -49,10 +49,18 @@ void OnDeinit(const int reason) void OnTick() { //--- + TimeCurrent(dt); + + SymbolInfoTick(_Symbol,last_tick); + + CheckPreChecks(); + if(!gIsPreChecksOk) + return; + + ScanPositions(); if(!newBar()) return; -//int maSlope = iCustom(Symbol(), PERIOD_CURRENT, "MA-Slope", 1000, MODE_SMA, PRICE_CLOSE); int cnt = CopyBuffer(handle, indexMA, 0, 3, bufferMA); if(cnt<3) @@ -61,10 +69,13 @@ void OnTick() currentMA = bufferMA[1]; currentColor = bufferColor[1]; - priorMA = bufferMA[0]; - priorColor = bufferColor[0]; - Print("currentMA ", currentMA, " currentColor ", currentColor, " priorMA ", priorMA, " priorColor"); + Print("Signal ", tradeSignal(), " Stop loss ", getAutoStopLoss(tradeSignal())); + + Print("currentMA ", currentMA, " currentColor ", currentColor); + + CloseTransactions(); + ExecuteEntry(); } //+------------------------------------------------------------------+ diff --git a/Include/Nkanven/HighTension/CloseTransactions.mqh b/Include/Nkanven/HighTension/CloseTransactions.mqh index ab1575d..5803a7e 100644 --- a/Include/Nkanven/HighTension/CloseTransactions.mqh +++ b/Include/Nkanven/HighTension/CloseTransactions.mqh @@ -15,8 +15,6 @@ void CloseTransactions() { bool result = true; int cts = PositionsTotal(); - ulong theTicket; - double positionProfit = 0.0; if(cts > 0) { @@ -27,10 +25,16 @@ void CloseTransactions() { if(PositionGetInteger(POSITION_MAGIC)==InpMagicNumber) { - if(positionProfit > PositionGetDouble(POSITION_PROFIT)) + if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY && currentColor == 1.0) { - positionProfit = PositionGetDouble(POSITION_PROFIT); - theTicket = ticket; + if(!trade.PositionClose(ticket)) + Print("Error (", GetLastError(), ") while deleting all buy positions"); + } + + if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL && currentColor == 0.0) + { + if(!trade.PositionClose(ticket)) + Print("Error (", GetLastError(), ") while deleting all buy positions"); } } } @@ -39,36 +43,8 @@ void CloseTransactions() 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/HighTension/EntriesManager.mqh b/Include/Nkanven/HighTension/EntriesManager.mqh index c2b6b38..535a2c1 100644 Binary files a/Include/Nkanven/HighTension/EntriesManager.mqh and b/Include/Nkanven/HighTension/EntriesManager.mqh differ diff --git a/Include/Nkanven/HighTension/Parameters.mqh b/Include/Nkanven/HighTension/Parameters.mqh index 5a87bb6..645d328 100644 --- a/Include/Nkanven/HighTension/Parameters.mqh +++ b/Include/Nkanven/HighTension/Parameters.mqh @@ -35,21 +35,7 @@ enum ENUM_MODE_TP 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 - }; -//Enumerative for trading time -enum ENUM_MODE_TRADING_TIME - { - DAY_TRADING=0, //Day trade - NIGHT_TRADING=1, //Night trade - DAY_NIGHT_TRADING=2, //Both day & night trade - ALL_DAY_TRADING=3, //Round the clock - }; //Enumerative for trading time enum ENUM_MODE_TRADE_SIGNAL @@ -76,22 +62,24 @@ input int InpSlippage=1; //Maximu input string Comment_01="----------------------"; //Stop loss settings 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 InpAutoStopLossCandlesAmount=10; //Auto SL amount of candles 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 bool InpDisableStopLoss=false; //Disable Stop Loss input string Comment_02="----------------------"; //Take profit settings input ENUM_MODE_TP InpTakeProfitMode=TP_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 double InpTakeProfitPercent=1.0; //Take Profit Multiplier -input string Comment_1="----------------------"; // Moving average slope settings +input string Comment_1="----------------------"; // Moving average slope settings input int InpPeriods = 1000; // Periods input ENUM_MA_METHOD InpMethod = MODE_SMA; // Method input ENUM_APPLIED_PRICE InpAppliedPrice = PRICE_CLOSE; // Price -input string Comment_2="----------------------"; +input string Comment_2="----------------------"; // Others +input int InpPriceToMaMarging=100; //Price to MA marging input string InpComment = __FILE__; //Default trade comment input int InpMagicNumber = 198901; //Magic Number @@ -101,14 +89,13 @@ input int InpMagicNumber = 198901; //Magic Number string gSymbol = Symbol(); double bufferMA[3]; double bufferColor[3]; -double currentMA, currentColor, priorMA, priorColor; +double currentMA, currentColor; int gTotalSellPositions, gTotalBuyPositions, gTotalPositions; -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 gEmergencyClose=false; //Urgently close losing trade +bool IsSpreadOK=false; //Urgently close losing trade double gLotSize=InpDefaultLotSize; diff --git a/Include/Nkanven/HighTension/Prechecks.mqh b/Include/Nkanven/HighTension/Prechecks.mqh index f04155e..82ff17b 100644 --- a/Include/Nkanven/HighTension/Prechecks.mqh +++ b/Include/Nkanven/HighTension/Prechecks.mqh @@ -17,13 +17,6 @@ void CheckPreChecks() Print("Live Trading is not enabled, please enable it in Metatrader and chart settings"); return; } -//Trading period verification - if(!gIsOperatingHours) - { - gIsPreChecksOk=false; - Print("Out of trading hours"); - return; - } //Check if the default stop loss you are setting in above the minimum and below the maximum if(InpDefaultStopLossInpMaxStopLoss) { @@ -68,7 +61,6 @@ void CheckPreChecks() } //Spread is acceptable long SpreadCurr=(int)Spread; - Print("Spread ", Spread); if(SpreadCurr>InpMaxSpread) { gIsPreChecksOk=false; diff --git a/Include/Nkanven/HighTension/ScanPositions.mqh b/Include/Nkanven/HighTension/ScanPositions.mqh index 02076cf..e3316cc 100644 --- a/Include/Nkanven/HighTension/ScanPositions.mqh +++ b/Include/Nkanven/HighTension/ScanPositions.mqh @@ -39,7 +39,7 @@ void ScanPositions() //If it is a sell order then increment the total count of sell orders if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL) gTotalSellPositions++; -Print("POSITION_TYPE_BUY ", POSITION_TYPE_BUY, " POSITION_TYPE_SELL ", POSITION_TYPE_SELL, " PositionGetInteger(POSITION_TYPE) ", PositionGetInteger(POSITION_TYPE)); +//Print("POSITION_TYPE_BUY ", POSITION_TYPE_BUY, " POSITION_TYPE_SELL ", POSITION_TYPE_SELL, " PositionGetInteger(POSITION_TYPE) ", PositionGetInteger(POSITION_TYPE)); } - Print("Total positions ", gTotalPositions, " - Total buys ", gTotalBuyPositions, " - Total sells ", gTotalSellPositions); + //Print("Total positions ", gTotalPositions, " - Total buys ", gTotalBuyPositions, " - Total sells ", gTotalSellPositions); } \ No newline at end of file diff --git a/Indicators/MA-Slope.mq5 b/Indicators/MA-Slope.mq5 deleted file mode 100644 index 6bb2773..0000000 Binary files a/Indicators/MA-Slope.mq5 and /dev/null differ