Ver Fonte

ticket # 1483

bos and third condition updated
AhtashamShahzad3 há 2 anos atrás
pai
commit
5c3d32641c
2 ficheiros alterados com 226 adições e 143 exclusões
  1. BIN
      BOS_CHOCH.ex5
  2. 226 143
      BOS_CHOCH.mq5

BIN
BOS_CHOCH.ex5


+ 226 - 143
BOS_CHOCH.mq5

@@ -64,6 +64,8 @@ int index = 0;
 
 string signal = "";
 datetime time_of_candle = 0.0;
+
+//double close1 = 0.0;
 //+------------------------------------------------------------------+
 //| Expert initialization function                                   |
 //+------------------------------------------------------------------+
@@ -76,11 +78,12 @@ void Bos(int i)
 
 
       high = iHigh(Symbol(),PERIOD_CURRENT,high_index);
-
       high1 = iHigh(Symbol(),PERIOD_CURRENT,i);
 
+      double close = iClose(Symbol(),PERIOD_CURRENT,i);
+
 
-      if(high1 > high)
+      if(close > high)
         {
 
          if(object_find("high") > 0)
@@ -91,6 +94,8 @@ void Bos(int i)
 
          high = high1;
 
+
+
          ObjectCreate(0,"high",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),high,iTime(Symbol(),PERIOD_CURRENT,0),high);
          ObjectSetInteger(0,"high",OBJPROP_RAY_RIGHT,true);
          ObjectSetInteger(0,"high",OBJPROP_COLOR,clrBlue);
@@ -105,13 +110,17 @@ void Bos(int i)
 
          int count = (high_index-1) - i;
 
-         for(int j=1; j <= count; j++)
+         //Print("count is ",count);
+
+         for(int j=0; j <= count; j++)
            {
 
             if(checkCandle(high_index-j) == "Bearish")
               {
+               //Print("bearish candle found and its low is ",low);
 
                low =  iLow(Symbol(),PERIOD_CURRENT,high_index-j);
+               //Print("bearish candle found and its low is ",low);
                bearish_found = true;
 
 
@@ -122,7 +131,7 @@ void Bos(int i)
          if(bearish_found == true)
            {
 
-            for(int k=1; k < count; k++)
+            for(int k=0; k <= count; k++)
               {
 
                low1 = iLow(Symbol(),PERIOD_CURRENT,high_index - k);
@@ -130,23 +139,52 @@ void Bos(int i)
                  {
 
                   low = low1;
-                  index_of_low =high_index- k;
+                  index_of_low = high_index- k;
+                  bearish_found = false;
+
+
 
                  }
               }
-            if(object_find("low") > 0)
-              {
-               ObjectDelete(0,"low");
 
+
+
+           }
+         if(object_find("low") > 0)
+           {
+
+            if(ObjectDelete(0,"low"))
+              {
+               Print("object deleted :");
+              }
+            else
+              {
+               Print("object deleted error: ",GetLastError());
               }
-            ObjectCreate(0,"low",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,index_of_low),low,iTime(Symbol(),PERIOD_CURRENT,0),low);
-            ObjectSetInteger(0,"low",OBJPROP_RAY_RIGHT,true);
 
-            ObjectSetInteger(0,"low",OBJPROP_COLOR,clrRed);
-            bearish_found = false;
 
            }
+         Print("low value is ", low);
+         Print("index of low ",index_of_low);
+         Print("time is ", iTime(Symbol(),PERIOD_CURRENT,index_of_low));
+         Print("time is ", iTime(Symbol(),PERIOD_CURRENT,0));
+
+         if(!ObjectCreate(0,"low",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),low,iTime(Symbol(),PERIOD_CURRENT,0),low))
+           {
+            Print("object created error:",GetLastError());
+           }
+         //else
+           {
+            Print("object created ");
+           }
+         ObjectSetInteger(0,"low",OBJPROP_RAY_RIGHT,true);
+
+         ObjectSetInteger(0,"low",OBJPROP_COLOR,clrRed);
+
+
 
+         Print("high of uptrend is ", high);
+         Print("low of uptrend is ", low);
 
 
          high_index = i;
@@ -162,10 +200,12 @@ void Bos(int i)
 
 
       low = iLow(Symbol(),PERIOD_CURRENT,low_index);
-
       low1 = iLow(Symbol(),PERIOD_CURRENT,i);
 
-      if(low1 < low)
+
+      double close1 = iClose(Symbol(),PERIOD_CURRENT,i);
+
+      if(close1 < low)
         {
 
          if(object_find("low") > 0)
@@ -212,7 +252,7 @@ void Bos(int i)
             for(int k=1; k < count; k++)
               {
 
-               high1 = iHigh(Symbol(),PERIOD_CURRENT,low_index - k);
+               double high1 = iHigh(Symbol(),PERIOD_CURRENT,low_index - k);
                if(high1 >= high)
                  {
 
@@ -236,7 +276,8 @@ void Bos(int i)
 
 
 
-
+         Print("high is ", high);
+         Print("low is ", low);
          low_index = i;
 
 
@@ -531,6 +572,7 @@ void third_Condition(int i)
    if(trend == "uptrend")
      {
       low2 = iLow(Symbol(),PERIOD_CURRENT,i);
+      high2 = iHigh(Symbol(),PERIOD_CURRENT,i);
 
       if(low2 < low)
         {
@@ -551,11 +593,34 @@ void third_Condition(int i)
 
          Print("low update due to third condition",low," time of the candle is ",iTime(Symbol(),PERIOD_CURRENT,i));
         }
+
+      if(high2 > high)
+        {
+         ObjectCreate(0,"line51"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),iHigh(Symbol(),PERIOD_CURRENT,i));
+         ObjectSetString(0,"line51"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"3_C");
+         high = high2;
+         high_index = i;        // addtion to be minus
+         if(object_find("high") > 0)
+           {
+            ObjectDelete(0,"high");
+
+           }
+
+         ObjectCreate(0,"high",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),high,iTime(Symbol(),PERIOD_CURRENT,0),high);
+         ObjectSetInteger(0,"high",OBJPROP_RAY_RIGHT,true);
+
+         ObjectSetInteger(0,"high",OBJPROP_COLOR,clrBlue);
+
+         Print("high update due to third condition",high," time of the candle is ",iTime(Symbol(),PERIOD_CURRENT,i));
+        }
+
+
      }
 
    if(trend == "downtrend")
      {
       high2 = iHigh(Symbol(),PERIOD_CURRENT,i);
+      low2 = iLow(Symbol(),PERIOD_CURRENT,i);
 
       if(high2 > high)
         {
@@ -574,6 +639,24 @@ void third_Condition(int i)
          ObjectSetInteger(0,"high",OBJPROP_COLOR,clrBlue);
          Print("high update due to third condition",high);
         }
+
+      if(low2 < low)
+        {
+         ObjectCreate(0,"line61"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),iLow(Symbol(),PERIOD_CURRENT,i));
+         ObjectSetString(0,"line61"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"3_C");
+
+         low = low2;
+         low_index = i;      // addtion to be minus
+         if(object_find("low") > 0)
+           {
+            ObjectDelete(0,"low");
+
+           }
+         ObjectCreate(0,"low",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),low,iTime(Symbol(),PERIOD_CURRENT,0),low);
+         ObjectSetInteger(0,"low",OBJPROP_RAY_RIGHT,true);
+         ObjectSetInteger(0,"low",OBJPROP_COLOR,clrBlue);
+         Print("low update due to third condition",low);
+        }
      }
 
   }
@@ -608,9 +691,9 @@ void store_value_in_structure(int i,int ind,string signal,datetime time_of_candl
 //+------------------------------------------------------------------+
 void foo(int value)
   {
-   int l = 0;
 
-   for(int i=value-1; i > 0; i--)
+
+   for(int i=value; i > 0; i--)
      {
       //Print("hi");
       //if(l < 2)
@@ -621,130 +704,130 @@ void foo(int value)
          third_Condition(i);
 
 
-         if(signal == "buy" || signal == "sell")
-           {
-            MqlDateTime  sdate,edate;
-            datetime time_to_place_trade = 0.0;
-
-            //Print("time of the candle ", time_of_candle);
-
-            int current_time_frame = Period();
-
-            string current_time_frame_String;
-
-            switch(current_time_frame)
-              {
-
-               case PERIOD_M1:
-                  current_time_frame_String = "1 Minute";
-                  break;
-               case PERIOD_M5:
-                  current_time_frame_String = "5 Minutes";
-                  break;
-               case PERIOD_M15:
-                  current_time_frame_String = "15 Minutes";
-                  break;
-               case PERIOD_M30:
-                  current_time_frame_String = "30 Minutes";
-                  break;
-               case PERIOD_H1:
-                  current_time_frame_String = "1 Hour";
-
-
-                  if(TimeToStruct(time_of_candle,edate))
-                    {
-                     edate.hour = edate.hour + 2;
-                     edate.min  = 0;
-                     edate.sec  = 0;
-                    }
-
-
-                  // Print("hour of the candle is ",StructToTime(edate));
-                  time_to_place_trade = StructToTime(edate);
-
-                  store_value_in_structure(i,ind,signal,time_of_candle,time_to_place_trade);
-
-                  //                  for(int m=0; m < orderNum; m++)
-                  //                    {
-                  //                     if(od_1[m].choch_index != -1)
-                  //                       {
-                  //                       Print("     time to match the condition : ",TimeCurrent());
-                  //
-                  //                        if(TimeCurrent() > od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "buy")
-                  //                          {
-                  //                          Print("time to match the condition : ",TimeCurrent());
-                  //
-                  //                           //if(iHigh(Symbol(),PERIOD_CURRENT,od_1[m].reversal_index) > iLow(Symbol(),PERIOD_CURRENT,0) && iClose(Symbol(),PERIOD_CURRENT,od_1[m].choch_index) < iClose(Symbol(),PERIOD_CURRENT,0))
-                  //                             {
-                  //                              ObjectCreate(0,"buy trade"+time_to_place_trade,OBJ_ARROW_BUY,0,time_to_place_trade,iHigh(Symbol(),PERIOD_CURRENT,0));
-                  //                              Print("trade placed buy at index ",0);
-                  //                              od_1[m].choch_index = -1;
-                  //
-                  //                             }
-                  //                           Print("   time to take trade is ",od_1[m].Time_of_candle_For_trade);
-                  //
-                  //
-                  //                          }
-                  //
-                  //                        if(TimeCurrent() >= od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "sell")
-                  //                          {
-                  //                          Print(TimeCurrent());
-                  //                           //
-                  //                           Print("  time to take trade is ",od_1[m].Time_of_candle_For_trade);
-                  //                           od_1[m].choch_index = -1;
-                  //
-                  //                          }
-                  //                       }
-                  //                    }
-
-
-
-                  //                  if(TimeCurrent() >= time_to_place_trade)
-                  //                    {
-                  //                     Print("hi");
-                  //                     if(signal == "buy")
-                  //                       {
-                  //                        int index = iBarShift(Symbol(), PERIOD_CURRENT, time_of_candle, false);
-                  //                        Print("index of the 2 hour plus index is ",index);
-                  //
-                  //                        Print("choch index ", i);
-                  //                        Print("reversal index ",ind);
-                  //                        Print("value to be check index ",i-3);
-                  //
-                  //                        //if(iHigh(Symbol(),PERIOD_CURRENT,ind) > iLow(Symbol(),PERIOD_CURRENT,i-2) && iClose(Symbol(),PERIOD_CURRENT,i) < iClose(Symbol(),PERIOD_CURRENT,i-2))
-                  //                        //  {
-                  //                        //   ObjectCreate(0,"buy trade"+time_to_place_trade,OBJ_ARROW_BUY,0,time_to_place_trade,iHigh(Symbol(),PERIOD_CURRENT,i-3));
-                  //                        //   Print("trade placed buy at index ",i-3);
-                  //                        //  }
-                  //                        Print(time_to_place_trade);
-                  //
-                  //                       }
-                  //                     if(signal == "sell")
-                  //                       {
-                  //                        Print("trade placed ");
-                  //                        ObjectCreate(0,"sell trade"+time_to_place_trade,OBJ_ARROW_SELL,0,time_to_place_trade,iLow(Symbol(),PERIOD_CURRENT,i-3));
-                  //
-                  //                        Print(ind);
-                  //                        Print(time_to_place_trade);
-                  //                       }
-                  //                    }
-                  //                  else
-                  //                    {
-                  //                     time_of_candle = iTime(Symbol(),PERIOD_CURRENT,i);
-                  //                    }
-
-                  break;
-
-               default:
-                  current_time_frame_String = "Unknown";
-                  break;
-              }
-
-            //Print("Current Timeframe: ", current_time_frame_String);
-
-
-            signal = "";
-           }
+         //         if(signal == "buy" || signal == "sell")
+         //           {
+         //            MqlDateTime  sdate,edate;
+         //            datetime time_to_place_trade = 0.0;
+         //
+         //            //Print("time of the candle ", time_of_candle);
+         //
+         //            int current_time_frame = Period();
+         //
+         //            string current_time_frame_String;
+         //
+         //            switch(current_time_frame)
+         //              {
+         //
+         //               case PERIOD_M1:
+         //                  current_time_frame_String = "1 Minute";
+         //                  break;
+         //               case PERIOD_M5:
+         //                  current_time_frame_String = "5 Minutes";
+         //                  break;
+         //               case PERIOD_M15:
+         //                  current_time_frame_String = "15 Minutes";
+         //                  break;
+         //               case PERIOD_M30:
+         //                  current_time_frame_String = "30 Minutes";
+         //                  break;
+         //               case PERIOD_H1:
+         //                  current_time_frame_String = "1 Hour";
+         //
+         //
+         //                  if(TimeToStruct(time_of_candle,edate))
+         //                    {
+         //                     edate.hour = edate.hour + 2;
+         //                     edate.min  = 0;
+         //                     edate.sec  = 0;
+         //                    }
+         //
+         //
+         //                  // Print("hour of the candle is ",StructToTime(edate));
+         //                  time_to_place_trade = StructToTime(edate);
+         //
+         //                  store_value_in_structure(i,ind,signal,time_of_candle,time_to_place_trade);
+         //
+         //                  //                  for(int m=0; m < orderNum; m++)
+         //                  //                    {
+         //                  //                     if(od_1[m].choch_index != -1)
+         //                  //                       {
+         //                  //                       Print("     time to match the condition : ",TimeCurrent());
+         //                  //
+         //                  //                        if(TimeCurrent() > od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "buy")
+         //                  //                          {
+         //                  //                          Print("time to match the condition : ",TimeCurrent());
+         //                  //
+         //                  //                           //if(iHigh(Symbol(),PERIOD_CURRENT,od_1[m].reversal_index) > iLow(Symbol(),PERIOD_CURRENT,0) && iClose(Symbol(),PERIOD_CURRENT,od_1[m].choch_index) < iClose(Symbol(),PERIOD_CURRENT,0))
+         //                  //                             {
+         //                  //                              ObjectCreate(0,"buy trade"+time_to_place_trade,OBJ_ARROW_BUY,0,time_to_place_trade,iHigh(Symbol(),PERIOD_CURRENT,0));
+         //                  //                              Print("trade placed buy at index ",0);
+         //                  //                              od_1[m].choch_index = -1;
+         //                  //
+         //                  //                             }
+         //                  //                           Print("   time to take trade is ",od_1[m].Time_of_candle_For_trade);
+         //                  //
+         //                  //
+         //                  //                          }
+         //                  //
+         //                  //                        if(TimeCurrent() >= od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "sell")
+         //                  //                          {
+         //                  //                          Print(TimeCurrent());
+         //                  //                           //
+         //                  //                           Print("  time to take trade is ",od_1[m].Time_of_candle_For_trade);
+         //                  //                           od_1[m].choch_index = -1;
+         //                  //
+         //                  //                          }
+         //                  //                       }
+         //                  //                    }
+         //
+         //
+         //
+         //                  //                  if(TimeCurrent() >= time_to_place_trade)
+         //                  //                    {
+         //                  //                     Print("hi");
+         //                  //                     if(signal == "buy")
+         //                  //                       {
+         //                  //                        int index = iBarShift(Symbol(), PERIOD_CURRENT, time_of_candle, false);
+         //                  //                        Print("index of the 2 hour plus index is ",index);
+         //                  //
+         //                  //                        Print("choch index ", i);
+         //                  //                        Print("reversal index ",ind);
+         //                  //                        Print("value to be check index ",i-3);
+         //                  //
+         //                  //                        //if(iHigh(Symbol(),PERIOD_CURRENT,ind) > iLow(Symbol(),PERIOD_CURRENT,i-2) && iClose(Symbol(),PERIOD_CURRENT,i) < iClose(Symbol(),PERIOD_CURRENT,i-2))
+         //                  //                        //  {
+         //                  //                        //   ObjectCreate(0,"buy trade"+time_to_place_trade,OBJ_ARROW_BUY,0,time_to_place_trade,iHigh(Symbol(),PERIOD_CURRENT,i-3));
+         //                  //                        //   Print("trade placed buy at index ",i-3);
+         //                  //                        //  }
+         //                  //                        Print(time_to_place_trade);
+         //                  //
+         //                  //                       }
+         //                  //                     if(signal == "sell")
+         //                  //                       {
+         //                  //                        Print("trade placed ");
+         //                  //                        ObjectCreate(0,"sell trade"+time_to_place_trade,OBJ_ARROW_SELL,0,time_to_place_trade,iLow(Symbol(),PERIOD_CURRENT,i-3));
+         //                  //
+         //                  //                        Print(ind);
+         //                  //                        Print(time_to_place_trade);
+         //                  //                       }
+         //                  //                    }
+         //                  //                  else
+         //                  //                    {
+         //                  //                     time_of_candle = iTime(Symbol(),PERIOD_CURRENT,i);
+         //                  //                    }
+         //
+         //                  break;
+         //
+         //               default:
+         //                  current_time_frame_String = "Unknown";
+         //                  break;
+         //              }
+         //
+         //            //Print("Current Timeframe: ", current_time_frame_String);
+         //
+         //
+         //            signal = "";
+         //           }
 
 
         }
@@ -815,7 +898,7 @@ void OnDeinit(const int reason)
 //+------------------------------------------------------------------+
 void OnTick()
   {
-  
+
 //   for(int m=0; m < orderNum; m++)
 //     {
 //      if(od_1[m].choch_index != -1)