소스 검색

Ticket: 4750 InProgress

Huzaifa-MQLDev 1 년 전
부모
커밋
8c1952c387
2개의 변경된 파일134개의 추가작업 그리고 0개의 파일을 삭제
  1. BIN
      atr_momentum_indicator_mt4.ex4
  2. 134 0
      atr_momentum_indicator_mt4.mq4

BIN
atr_momentum_indicator_mt4.ex4


+ 134 - 0
atr_momentum_indicator_mt4.mq4

@@ -0,0 +1,134 @@
+//+------------------------------------------------------------------+
+//|                                   atr_momentum_indicator_mt4.mq4 |
+//|                                  Copyright 2025, MQL Development |
+//|                                  https://www.mqldevelopment.com/ |
+//+------------------------------------------------------------------+
+#property copyright "Copyright 2025, MQL Development"
+#property link      "https://www.mqldevelopment.com/"
+#property version   "1.00"
+#property strict
+#property indicator_separate_window
+#property  indicator_buffers 3
+#property  indicator_minimum 0.0
+//+------------------------------------------------------------------+
+//| Custom indicator initialization function                         |
+//+------------------------------------------------------------------+
+
+input       string                string_1              = "<><><><><><> General SETTINGS <><><><><><>";   //__
+input       double                threshold             = 0.00001;          // Threshold Value
+
+sinput      string                atrSettings           = " <><><><><>  Atr Settings <><><><><>  "; //_
+input       int                   atrPeriod             = 14;            // ATR Period
+
+input       string                string_2_2            = "<><><><><><> Color Setting <><><><><><>";   //__
+input       color                 atr_line_color        = clrAqua;                 // Atr Line Color
+input       color                 signal_color          = clrLimeGreen;            // Signal Color
+input       color                 no_signal_color       = clrSlateGray;            // No Signal Color
+
+// Global Variables
+double         atrPercentageBuffer[];
+double         signalBuffer[];
+double         noSignalBuffer[];
+string short_name="";
+int OnInit()
+  {
+//--- indicator buffers mapping
+   SetIndexBuffer(0, atrPercentageBuffer);
+   SetIndexBuffer(1, signalBuffer);
+   SetIndexBuffer(2, noSignalBuffer);
+
+//--- Set buffer names
+   SetIndexLabel(0, "Atr %");
+   SetIndexLabel(1, "Signal");
+   SetIndexLabel(2, "No Signal");
+
+   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2, atr_line_color);
+   SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, 4, signal_color);
+   SetIndexStyle(2, DRAW_HISTOGRAM, STYLE_SOLID, 4, no_signal_color);
+
+   short_name = "atr_momentum_indicator_mt4";
+   IndicatorShortName(short_name);
+//---
+   return(INIT_SUCCEEDED);
+  }
+//+------------------------------------------------------------------+
+//| Custom indicator iteration function                              |
+//+------------------------------------------------------------------+
+int OnCalculate(const int rates_total,
+                const int prev_calculated,
+                const datetime &time[],
+                const double &open[],
+                const double &high[],
+                const double &low[],
+                const double &close[],
+                const long &tick_volume[],
+                const long &volume[],
+                const int &spread[])
+  {
+//---
+   int i, Counted_bars;
+   Counted_bars=IndicatorCounted(); // Number of counted bars
+   if(prev_calculated == 0)
+      i=Bars-Counted_bars-10;
+   else
+      i=Bars-Counted_bars-1;
+
+   while(i >= 0)
+     {
+      double atrValueIs =  atrValue(i);
+      double candle_0 = iClose(Symbol(), PERIOD_CURRENT, 0);
+      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 totalSum = value_1 + value_2 + value_3;
+
+      atrPercentageBuffer[i] = ((atrValueIs / candle_1) * 100);
+
+      if(totalSum > threshold)
+        {
+         signalBuffer[i] = totalSum;
+        }
+      else
+        {
+         noSignalBuffer[i] = totalSum;
+        }
+
+      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--;
+     }
+//--- return value of prev_calculated for next call
+   return(rates_total);
+  }
+//+------------------------------------------------------------------+
+//+------------------------------------------------------------------+
+//|                                                                  |
+//+------------------------------------------------------------------+
+double atrValue(int index)
+  {
+   return NormalizeDouble(iATR(Symbol(), PERIOD_CURRENT, atrPeriod, index), Digits());
+  }
+//+------------------------------------------------------------------+
+//|                                                                  |
+//+------------------------------------------------------------------+
+double atrPercentageValue(int index)
+  {
+   return (iATR(Symbol(), PERIOD_CURRENT, atrPeriod, index) / iClose(Symbol(), PERIOD_CURRENT, index)) * 100;
+  }
+//+------------------------------------------------------------------+
+//|                                                                  |
+//+------------------------------------------------------------------+
+
+//+------------------------------------------------------------------+