Explorar el Código

Ticket # 1463

in progress
AhtashamShahzad3 hace 2 años
commit
ca048dba03
Se han modificado 2 ficheros con 226 adiciones y 0 borrados
  1. BIN
      MK_BOS_CHOCH.ex5
  2. 226 0
      MK_BOS_CHOCH.mq5

BIN
MK_BOS_CHOCH.ex5


+ 226 - 0
MK_BOS_CHOCH.mq5

@@ -0,0 +1,226 @@
+//+------------------------------------------------------------------+
+//|                                                 MK_BOS_CHOCH.mq5 |
+//|                                  Copyright 2023, MetaQuotes Ltd. |
+//|                                             https://www.mql5.com |
+//+------------------------------------------------------------------+
+#property copyright "Copyright 2023, MetaQuotes Ltd."
+#property link      "https://www.mql5.com"
+#property version   "1.00"
+
+sinput string              str = "<><><><><><> Object Name <><><><><><>";
+input string object_name = "line";
+
+string trend;
+bool bearish_found = false;
+bool bullish_found = false;
+//+------------------------------------------------------------------+
+//| Expert initialization function                                   |
+//+------------------------------------------------------------------+
+void foo(int index)
+  {
+   if(checkCandle(index) == "Bullish")
+     {
+      trend = "uptrend";
+      double high,low = 0.0;
+
+
+      // to store high and low of the value after the object
+      high = iHigh(Symbol(),PERIOD_CURRENT,index-1);
+
+      //low =  iLow(Symbol(),PERIOD_CURRENT,index-1);
+
+      for(int i=index - 2 ; i > 0; i--)
+        {
+         double high1 = iHigh(Symbol(),PERIOD_CURRENT,i);
+
+         //double low1  = iLow(Symbol(),PERIOD_CURRENT,i);
+
+         if(high1 > high)
+           {
+            high = high1;
+            int count = (index-1) - i;
+
+            Print("count",count);
+
+
+            for(int j=1; j < count; j++)
+              {
+
+               if(checkCandle(index-j) == "Bearish")
+                 {
+                  low =  iLow(Symbol(),PERIOD_CURRENT,index-1);
+                  bearish_found = true;
+                 }
+
+              }
+
+            if(bearish_found == true)
+              {
+               double low1;
+               for(int k=1; k <= count; k++)
+                 {
+                  low1 = iLow(Symbol(),PERIOD_CURRENT,index - k);
+                  if(low1 < low)
+                    {
+                     low = low1;
+                    }
+                 }
+               bearish_found = false;
+
+              }
+
+
+           }
+
+
+        }
+
+      Print(" high price is ", high);
+      Print("low price is ", low);
+
+     }
+
+   if(checkCandle(index) == "Bearish")
+     {
+      trend = "downtrend";
+      double high,low = 0.0;
+
+
+      // to store high and low of the value after the object
+      low = iLow(Symbol(),PERIOD_CURRENT,index-1);
+
+      //low =  iLow(Symbol(),PERIOD_CURRENT,index-1);
+
+      for(int i=index - 2 ; i > 0; i--)
+        {
+         double low1 = iLow(Symbol(),PERIOD_CURRENT,i);
+
+         //double low1  = iLow(Symbol(),PERIOD_CURRENT,i);
+
+         if(low1 < low)
+           {
+            low = low1;
+            int count = (index-1) - i;
+
+            Print("count",count);
+
+
+            for(int j=1; j < count; j++)
+              {
+
+               if(checkCandle(index-j) == "Bullish")
+                 {
+                  high =  iHigh(Symbol(),PERIOD_CURRENT,index-1);
+                  bullish_found = true;
+                 }
+
+              }
+
+            if(bullish_found == true)
+              {
+               double high1;
+               for(int k=1; k <= count; k++)
+                 {
+                  high1 = iHigh(Symbol(),PERIOD_CURRENT,index - k);
+                  if(high1 > high)
+                    {
+                     high = high1;
+                    }
+                 }
+               bullish_found = false;
+
+              }
+
+
+           }
+
+
+        }
+      Print(" high price is ", high);
+      Print("low price is ", low);
+
+     }
+
+  }
+//+------------------------------------------------------------------+
+//|                                                                  |
+//+------------------------------------------------------------------+
+int OnInit()
+  {
+
+   //ObjectCreate(0,"line",OBJ_VLINE,0,D'2023.08.01 10:00:27',0);
+   object_find(object_name);
+//Print(ObjectFind(0,"line"));  // to find the object drawn on the chart
+
+   if(object_find(object_name) == true)
+     {
+
+
+      datetime time_of_candle = (datetime)ObjectGetInteger(0,"line",OBJPROP_TIME,0);
+      Print("time is " , time_of_candle);
+
+      int index = iBarShift(0, PERIOD_CURRENT,time_of_candle, true);
+      Print("index is " , index);
+      foo(index);
+
+     }
+   else
+     {
+      Print("Object Not Found");
+     }
+
+
+
+   return(INIT_SUCCEEDED);
+  }
+//+------------------------------------------------------------------+
+//| Expert deinitialization function                                 |
+//+------------------------------------------------------------------+
+void OnDeinit(const int reason)
+  {
+//---
+
+  }
+//+------------------------------------------------------------------+
+//| Expert tick function                                             |
+//+------------------------------------------------------------------+
+void OnTick()
+  {
+
+
+
+  }
+
+
+//+------------------------------------------------------------------+
+//|                                                                  |
+//+------------------------------------------------------------------+
+bool object_find(string obj)    // to find object placed by user in the chart
+  {
+   if(ObjectFind(0,obj) >= 0)
+     {
+      return true;
+     }
+   return false;
+
+  }
+//+------------------------------------------------------------------+
+//|                                                                  |
+//+------------------------------------------------------------------+
+string checkCandle(int i)  // to check the candle is bullish or bearish
+  {
+   double  close = iClose(Symbol(),PERIOD_CURRENT,i);
+   double  open  = iOpen(Symbol(),PERIOD_CURRENT,i);
+
+   if(close > open)
+     {
+      return "Bullish";
+     }
+   else
+      if(close < open)
+        {
+         return "Bearish";
+        }
+   return "empty";
+  }
+//+------------------------------------------------------------------+