|
|
@@ -7,10 +7,35 @@
|
|
|
#property link "https://www.mql5.com"
|
|
|
#property version "1.00"
|
|
|
|
|
|
+#define orderNum 200
|
|
|
+
|
|
|
+struct tradeOrder
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ int choch_index;
|
|
|
+ int reversal_index;
|
|
|
+ string Signal;
|
|
|
+ datetime Time_OF_Candle;
|
|
|
+ datetime Time_of_candle_For_trade;
|
|
|
+
|
|
|
+ tradeOrder()
|
|
|
+ {
|
|
|
+ choch_index = -1;
|
|
|
+ Signal = "";
|
|
|
+ reversal_index = 0;
|
|
|
+ Time_OF_Candle = 0.0;
|
|
|
+ Time_of_candle_For_trade = 0.0;
|
|
|
+ }
|
|
|
+
|
|
|
+ };
|
|
|
+tradeOrder od_1[orderNum];
|
|
|
+
|
|
|
+
|
|
|
sinput string str = "<><><><><><> Object Name <><><><><><>";
|
|
|
input string object_name = "line";
|
|
|
|
|
|
-
|
|
|
+int reversal_candle_index = 0;
|
|
|
int ind = 0;
|
|
|
string trend;
|
|
|
|
|
|
@@ -36,6 +61,9 @@ int Store_bos_last_index = 0;
|
|
|
|
|
|
bool choch = false;
|
|
|
int index = 0;
|
|
|
+
|
|
|
+string signal = "";
|
|
|
+datetime time_of_candle = 0.0;
|
|
|
//+------------------------------------------------------------------+
|
|
|
//| Expert initialization function |
|
|
|
//+------------------------------------------------------------------+
|
|
|
@@ -256,6 +284,8 @@ void Entry_Action_1_down(int Store_bos_last_index, int i,int diff)
|
|
|
{
|
|
|
if(iOpen(Symbol(),PERIOD_CURRENT,ind) > iOpen(Symbol(),PERIOD_CURRENT,i) && iClose(Symbol(),PERIOD_CURRENT,ind) < iClose(Symbol(),PERIOD_CURRENT,i))
|
|
|
{
|
|
|
+ signal = "buy";
|
|
|
+ time_of_candle = iTime(Symbol(),PERIOD_CURRENT,i);
|
|
|
Print("Place buy order -----------------------------------------------------------------------: ");
|
|
|
}
|
|
|
|
|
|
@@ -297,12 +327,13 @@ void Entry_Action_1_up(int Store_bos_last_index, int i,int diff)
|
|
|
if(checkCandle(j) == "Bearish")
|
|
|
{
|
|
|
ind = j; // reversal candle index
|
|
|
+
|
|
|
bearish_found = true;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- Print("diff is ", diff);
|
|
|
+//Print("diff is ", diff);
|
|
|
|
|
|
Print("condition satisfied : ",check_values_less_than_choch_low(diff,i));
|
|
|
|
|
|
@@ -313,6 +344,8 @@ void Entry_Action_1_up(int Store_bos_last_index, int i,int diff)
|
|
|
{
|
|
|
if(iOpen(Symbol(),PERIOD_CURRENT,ind) < iOpen(Symbol(),PERIOD_CURRENT,i) && iClose(Symbol(),PERIOD_CURRENT,ind) > iClose(Symbol(),PERIOD_CURRENT,i))
|
|
|
{
|
|
|
+ signal = "sell";
|
|
|
+ time_of_candle = iTime(Symbol(),PERIOD_CURRENT,i);
|
|
|
Print("Place sell order -----------------------------------------------------------------------: ");
|
|
|
}
|
|
|
|
|
|
@@ -378,7 +411,7 @@ bool check_values_less_than_choch_low(int diff,int i) // uptrend
|
|
|
{
|
|
|
bool found = false;
|
|
|
int value = (diff + i) - 1; // from which it start to check value is less in index
|
|
|
- Print("value to be start is ",value);
|
|
|
+//Print("value to be start is ",value);
|
|
|
for(int k=value; k>i; k--)
|
|
|
{
|
|
|
|
|
|
@@ -416,10 +449,10 @@ void choch(int i)
|
|
|
ObjectCreate(0,"line8"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_ARROW_DOWN,0,iTime(Symbol(),PERIOD_CURRENT,i),iHigh(Symbol(),PERIOD_CURRENT,i)+100*Point());
|
|
|
ObjectSetInteger(0,"line8"+iTime(Symbol(),PERIOD_CURRENT,i),OBJPROP_COLOR,clrRed);
|
|
|
|
|
|
- Print("last bos index is ",Store_bos_last_index);
|
|
|
+ //Print("last bos index is ",Store_bos_last_index);
|
|
|
|
|
|
int diff1 = Store_bos_last_index - (i);
|
|
|
- Print("diff between bos and last choch is ",diff1);
|
|
|
+ // Print("diff between bos and last choch is ",diff1);
|
|
|
|
|
|
Entry_Action_1_up(Store_bos_last_index,i,diff1);
|
|
|
|
|
|
@@ -504,10 +537,9 @@ void third_Condition(int i)
|
|
|
ObjectCreate(0,"line5"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),iLow(Symbol(),PERIOD_CURRENT,i));
|
|
|
ObjectSetString(0,"line5"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"3_C");
|
|
|
low = low2;
|
|
|
- //low_index = i;
|
|
|
+ low_index = i; // addtion to be minus
|
|
|
if(object_find("low") > 0)
|
|
|
{
|
|
|
- Print("object deleted ");
|
|
|
ObjectDelete(0,"low");
|
|
|
|
|
|
}
|
|
|
@@ -531,7 +563,7 @@ void third_Condition(int i)
|
|
|
ObjectSetString(0,"line6"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"3_C");
|
|
|
|
|
|
high = high2;
|
|
|
- //high_index = i;
|
|
|
+ high_index = i; // addtion to be minus
|
|
|
if(object_find("high") > 0)
|
|
|
{
|
|
|
ObjectDelete(0,"high");
|
|
|
@@ -547,7 +579,30 @@ void third_Condition(int i)
|
|
|
}
|
|
|
|
|
|
|
|
|
+//+------------------------------------------------------------------+
|
|
|
+//| |
|
|
|
+//+------------------------------------------------------------------+
|
|
|
+void store_value_in_structure(int i,int ind,string signal,datetime time_of_candle,datetime time_to_place_trade)
|
|
|
+ {
|
|
|
+
|
|
|
+ for(int l=0; l<200; l++)
|
|
|
+ {
|
|
|
+ if(od_1[l].choch_index == -1)
|
|
|
+ {
|
|
|
+ od_1[l].choch_index = i;
|
|
|
+ od_1[l].reversal_index = ind;
|
|
|
+ od_1[l].Signal = signal;
|
|
|
+ od_1[l].Time_OF_Candle = time_of_candle;
|
|
|
+ Print("saved time in the structure ",time_of_candle);
|
|
|
+ od_1[l].Time_of_candle_For_trade = time_to_place_trade;
|
|
|
+ Print("saved time in the structure ",time_to_place_trade);
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
+ }
|
|
|
+ }
|
|
|
//+------------------------------------------------------------------+
|
|
|
//| |
|
|
|
//+------------------------------------------------------------------+
|
|
|
@@ -566,10 +621,133 @@ void foo(int value)
|
|
|
third_Condition(i);
|
|
|
|
|
|
|
|
|
- l++;
|
|
|
+ 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 = "";
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|
|
|
- //Bos(i);
|
|
|
|
|
|
|
|
|
|
|
|
@@ -637,7 +815,39 @@ void OnDeinit(const int reason)
|
|
|
//+------------------------------------------------------------------+
|
|
|
void OnTick()
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
+// 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"+TimeCurrent(),OBJ_ARROW_BUY,0,TimeCurrent(),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;
|
|
|
+//
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
}
|
|
|
|