فهرست منبع

Ticket # 1463

AhtashamShahzad3 2 سال پیش
والد
کامیت
f772e3c1cf
2فایلهای تغییر یافته به همراه193 افزوده شده و 70 حذف شده
  1. BIN
      MK_BOS_CHOCH.ex5
  2. 193 70
      MK_BOS_CHOCH.mq5

BIN
MK_BOS_CHOCH.ex5


+ 193 - 70
MK_BOS_CHOCH.mq5

@@ -13,132 +13,224 @@ input string object_name = "line";
 string trend;
 bool bearish_found = false;
 bool bullish_found = false;
+
+int index_of_low = 0;
+int high_index=0;
+double high,low,low1,high1;
 //+------------------------------------------------------------------+
 //| Expert initialization function                                   |
 //+------------------------------------------------------------------+
 void foo(int index)
   {
-   if(checkCandle(index) == "Bullish")
+
+   for(int i=index; i > 0; i--)
      {
-      trend = "uptrend";
-      double high,low = 0.0;
 
+      if(checkCandle(index) == "Bullish")
+        {
+
+         trend = "uptrend";
 
-      // to store high and low of the value after the object
-      high = iHigh(Symbol(),PERIOD_CURRENT,index-1);
+         //double high,low = 0.0;
 
-      //low =  iLow(Symbol(),PERIOD_CURRENT,index-1);
+         // to store high and low of the value after the object
+         high = iHigh(Symbol(),PERIOD_CURRENT,index);
 
-      for(int i=index - 2 ; i > 0; i--)
-        {
-         double high1 = iHigh(Symbol(),PERIOD_CURRENT,i);
+         //low =  iLow(Symbol(),PERIOD_CURRENT,index-1);
 
-         //double low1  = iLow(Symbol(),PERIOD_CURRENT,i);
 
-         if(high1 > high)
+         if(trend == "uptrend")
            {
-            high = high1;
-            int count = (index-1) - i;
 
-            Print("count",count);
 
 
-            for(int j=1; j < count; j++)
+
+            high1 = iHigh(Symbol(),PERIOD_CURRENT,i);
+
+            //double low1  = iLow(Symbol(),PERIOD_CURRENT,i);
+
+            if(high1 > high)
               {
+               high = high1;
+
+               //  Print("high break at index value",i);
+               // Print("index is ",index);
+
+               int count = (index-1) - i;
+               Print("count is ", count);
+
+               // Print("index updated ",index);
 
-               if(checkCandle(index-j) == "Bearish")
+               // Print("count",count);
+
+               for(int j=1; j <= count; j++)
                  {
-                  low =  iLow(Symbol(),PERIOD_CURRENT,index-1);
-                  bearish_found = true;
+
+                  if(checkCandle(index-j) == "Bearish")
+                    {
+                     low =  iLow(Symbol(),PERIOD_CURRENT,index-j);
+                     bearish_found = true;
+                    }
+
                  }
 
-              }
+               if(bearish_found == true)
+                 {
+                  //double low1 ;
+                  //Print("where");
+                  for(int k=1; k <= count; k++)
+                    {
 
-            if(bearish_found == true)
-              {
-               double low1;
-               for(int k=1; k <= count; k++)
+                     low1 = iLow(Symbol(),PERIOD_CURRENT,index - k);
+                     if(low1 <= low)
+                       {
+                        //Print("here");
+                        low = low1;
+                        index_of_low = index - k;
+                        Print("low is updated at index : ",index - k);
+
+                       }
+                    }
+                  bearish_found = false;
+
+                 }
+
+               Print(" high price is ", high);
+               Print("low price is ", low);
+               Print("index of low is ", index_of_low);
+
+               for(int l=index_of_low; l > 0; l--)
                  {
-                  low1 = iLow(Symbol(),PERIOD_CURRENT,index - k);
-                  if(low1 < low)
+                  // print("hi");
+                  double close = iClose(Symbol(),PERIOD_CURRENT,l);
+
+                  if(close < low)
                     {
-                     low = low1;
+                     double price_low = iLow(Symbol(),PERIOD_CURRENT,l+1);
+                     double time = iTime(Symbol(),PERIOD_CURRENT,l+1);
+                     double time1 = iTime(Symbol(),PERIOD_CURRENT,l+1);
+                     ObjectCreate(0,"tline1",OBJ_TREND,0,time,price_low,time1,price_low);
+                     trend = "downtrend";
+                     Print("choch");
+
+                     Print("close", close);
+                     break;
+
                     }
+
                  }
-               bearish_found = false;
+               index = i;
 
               }
 
-
            }
+         //
 
 
         }
 
-      Print(" high price is ", high);
-      Print("low price is ", low);
+      if(checkCandle(index) == "Bearish")
+        {
 
-     }
+         trend = "downtrend";
 
-   if(checkCandle(index) == "Bearish")
-     {
-      trend = "downtrend";
-      double high,low = 0.0;
+         // double high,low = 0.0;
 
+         // to store high and low of the value after the object
+         low = iLow(Symbol(),PERIOD_CURRENT,index);
 
-      // 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);
 
-      //low =  iLow(Symbol(),PERIOD_CURRENT,index-1);
+         if(trend == "downtrend")
+           {
 
-      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);
+            low1 = iLow(Symbol(),PERIOD_CURRENT,i);
 
+            //double low1  = iLow(Symbol(),PERIOD_CURRENT,i);
 
-            for(int j=1; j < count; j++)
+            if(low1 < low)
               {
+               low = low1;
+
+               //  Print("high break at index value",i);
+               // Print("index is ",index);
+
+               int count = (index-1) - i;
+               Print("count is ", count);
+
+               // Print("index updated ",index);
+
+               // Print("count",count);
 
-               if(checkCandle(index-j) == "Bullish")
+               for(int j=1; j <= count; j++)
                  {
-                  high =  iHigh(Symbol(),PERIOD_CURRENT,index-1);
-                  bullish_found = true;
+
+                  if(checkCandle(index-j) == "Bullish")
+                    {
+                     high =  iHigh(Symbol(),PERIOD_CURRENT,index-j);
+                     bullish_found = true;
+                    }
+
                  }
 
-              }
+               if(bullish_found == true)
+                 {
+                  high1;
+                  //Print("where");
+                  for(int k=1; k <= count; k++)
+                    {
 
-            if(bullish_found == true)
-              {
-               double high1;
-               for(int k=1; k <= count; k++)
+                     high1 = iHigh(Symbol(),PERIOD_CURRENT,index - k);
+                     if(high1 > high)
+                       {
+                        //Print("here");
+                        high = high1;
+                        index_of_low = index - k;
+                        Print("high is updated at index : ",index - k);
+
+                       }
+                    }
+                  bullish_found = false;
+
+                 }
+
+               Print(" high price is ", high);
+               Print("low price is ", low);
+               Print("index of low is ", index_of_low);
+
+               for(int l=index_of_low; l > 0; l--)
                  {
-                  high1 = iHigh(Symbol(),PERIOD_CURRENT,index - k);
-                  if(high1 > high)
+                  // print("hi");
+                  double close = iClose(Symbol(),PERIOD_CURRENT,l);
+                  if(close > high)
                     {
-                     high = high1;
+
+                     double price_high = iLow(Symbol(),PERIOD_CURRENT,l+1);
+                     double time = iTime(Symbol(),PERIOD_CURRENT,l+1);
+                     double time1 = iTime(Symbol(),PERIOD_CURRENT,l+1);
+                     ObjectCreate(0,"tline2",OBJ_TREND,0,time,price_high,time1,price_high);
+
+                     trend = "uptrend";
+                     Print("choch");
+                     Print(l);
+
+                     Print("close", close);
+                     break;
+
                     }
+
                  }
-               bullish_found = false;
+               index = i;
 
               }
 
-
            }
-
+         //
 
         }
-      Print(" high price is ", high);
-      Print("low price is ", low);
-
      }
 
   }
@@ -148,19 +240,25 @@ void foo(int index)
 int OnInit()
   {
 
-   //ObjectCreate(0,"line",OBJ_VLINE,0,D'2023.08.01 10:00:27',0);
+   ObjectCreate(0,"line",OBJ_VLINE,0,D'2023.07.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);
+      Print("line time: ",time_of_candle);
+      int index = iBarShift(Symbol(), PERIOD_CURRENT, time_of_candle, false);
+      Print(index);
+
+      //      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);
 
      }
@@ -186,12 +284,35 @@ void OnDeinit(const int reason)
 //+------------------------------------------------------------------+
 void OnTick()
   {
+   if(NewBar())
+     {
+      ObjectSetInteger(0,"tline1",OBJPROP_TIME,iTime(Symbol(), PERIOD_CURRENT,0));
 
+      ObjectSetInteger(0,"tline2",OBJPROP_TIME,iTime(Symbol(), PERIOD_CURRENT,0));
+     }
 
 
   }
 
 
+//+------------------------------------------------------------------+
+//|                                                                  |
+//+------------------------------------------------------------------+
+bool NewBar()
+  {
+   static datetime Last_bar ;
+   datetime Current_bar = iTime(Symbol(), PERIOD_CURRENT,0);
+   if(Current_bar != Last_bar)
+     {
+      Last_bar = Current_bar;
+      return (true);
+     }
+   else
+     {
+      return (false);
+     }
+  }
+
 //+------------------------------------------------------------------+
 //|                                                                  |
 //+------------------------------------------------------------------+
@@ -224,3 +345,5 @@ string checkCandle(int i)  // to check the candle is bullish or bearish
    return "empty";
   }
 //+------------------------------------------------------------------+
+
+//+------------------------------------------------------------------+