Browse Source

Ticket: 4750 Complete

Huzaifa-MQLDev 1 year ago
parent
commit
839cf7a356
2 changed files with 26 additions and 14 deletions
  1. BIN
      atr_momentum_indicator_mt4.ex4
  2. 26 14
      atr_momentum_indicator_mt4.mq4

BIN
atr_momentum_indicator_mt4.ex4


+ 26 - 14
atr_momentum_indicator_mt4.mq4

@@ -15,7 +15,7 @@
 //+------------------------------------------------------------------+
 
 input       string                string_1              = "<><><><><><> General SETTINGS <><><><><><>";   //__
-input       double                threshold             = 0.00001;          // Threshold Value
+input       double                threshold             = 30.0;          // Threshold Value
 
 sinput      string                atrSettings           = " <><><><><>  Atr Settings <><><><><>  "; //_
 input       int                   atrPeriod             = 14;            // ATR Period
@@ -80,32 +80,43 @@ int OnCalculate(const int rates_total,
       double candle_1 = iClose(Symbol(), PERIOD_CURRENT, 0 + 1);
       double candle_2 = iClose(Symbol(), PERIOD_CURRENT, 0 + 2);
 
-      double value_1 = ((atrPercentageValue(i + 1) - atrPercentageValue(i + 2)) / atrPercentageValue(i + 2));
-      double value_2 = ((atrPercentageValue(i) - atrPercentageValue(i + 1)) / atrPercentageValue(i + 1));
-      double value_3 = ((atrPercentageValue(i) - atrPercentageValue(i + 2)) / atrPercentageValue(i + 2));
+      double candle_percentage_0 = atrPercentageValue(i);
+      double candle_percentage_1 = atrPercentageValue(i + 1);
+      double candle_percentage_2 = atrPercentageValue(i + 2);
 
+      double value_1 = 0, value_2 = 0, value_3 = 0;
+
+      if(candle_percentage_0 != 0 && candle_percentage_1 != 0 && candle_percentage_2 != 0)
+        {
+         value_1 = (((candle_percentage_1 - candle_percentage_2) / candle_percentage_2) * 100);
+         value_2 = (((candle_percentage_0 - candle_percentage_1) / candle_percentage_1) * 100);
+         value_3 = (((candle_percentage_0 - candle_percentage_2) / candle_percentage_2) * 100);
+        }
       double totalSum = value_1 + value_2 + value_3;
 
       atrPercentageBuffer[i] = ((atrValueIs / candle_1) * 100);
+      atrPercentageBuffer[i] = atrPercentageBuffer[i] * 100;
 
       if(totalSum > threshold)
         {
          signalBuffer[i] = totalSum;
+         noSignalBuffer[i] = 0;
         }
       else
         {
          noSignalBuffer[i] = totalSum;
+         signalBuffer[i] = 0;
         }
 
-      Print("Time Current Candle: ", iClose(Symbol(), PERIOD_CURRENT,0),
-            " | Time Candle 1: ", iClose(Symbol(), PERIOD_CURRENT, 0 + 1),
-            " | Time Candle 2: ", iClose(Symbol(), PERIOD_CURRENT, 0 + 2),
-            " | ATR Value: ", atrValueIs,
-            " | value_1: ", value_1,
-            " | value_2: ", value_2,
-            " | value_3: ", value_3,
-            " | Sum: ", NormalizeDouble(totalSum, Digits()),
-            " | i: ", i);
+      //Print("Time Current Candle: ", iClose(Symbol(), PERIOD_CURRENT,0),
+      //      " | Time Candle 1: ", iClose(Symbol(), PERIOD_CURRENT, 0 + 1),
+      //      " | Time Candle 2: ", iClose(Symbol(), PERIOD_CURRENT, 0 + 2),
+      //      " | ATR Value: ", atrValueIs,
+      //      " | value_1: ", value_1,
+      //      " | value_2: ", value_2,
+      //      " | value_3: ", value_3,
+      //      " | Sum: ", NormalizeDouble(totalSum, Digits()),
+      //      " | i: ", i);
 
       i--;
      }
@@ -125,7 +136,8 @@ double atrValue(int index)
 //+------------------------------------------------------------------+
 double atrPercentageValue(int index)
   {
-   return (iATR(Symbol(), PERIOD_CURRENT, atrPeriod, index) / iClose(Symbol(), PERIOD_CURRENT, index)) * 100;
+// Print(" Atr Percentage: ", (iATR(Symbol(), PERIOD_CURRENT, atrPeriod, index) / iClose(Symbol(), PERIOD_CURRENT, index)) * 100, " i: ", index);
+   return (iATR(Symbol(), PERIOD_CURRENT, atrPeriod, index) / iClose(Symbol(), PERIOD_CURRENT, index + 1)) * 100;
   }
 //+------------------------------------------------------------------+
 //|                                                                  |