//+------------------------------------------------------------------+ //| mkfxvolumes | //| Copyright 2022, mkfxvolumes | //| mkfxvolumes@gmail.com | //+------------------------------------------------------------------+ #property copyright "Created with MOHAMED KOURTAM"; #property link "mkfxvolumes@gmail.com"; #property version "1.4"; #property description "This Indicator is protected by proprietary rights \nCopyrights MOHAMED KOURTAM\nContact Us: mkfxvolumes@gmail.com"; #property indicator_separate_window #property indicator_buffers 4 #property indicator_color1 1966335 #property indicator_label1 "Sell" #property indicator_style1 STYLE_SOLID #property indicator_type1 DRAW_HISTOGRAM #property indicator_width1 5 #property indicator_color2 1769216 #property indicator_label2 "Buy" #property indicator_style2 STYLE_SOLID #property indicator_type2 DRAW_HISTOGRAM #property indicator_width2 5 #property indicator_label3 "LastSignal" #property indicator_type3 DRAW_NONE #property indicator_label4 "Signal" #property indicator_type4 DRAW_NONE enum Strategy_Check { Strategy_1=1, //Strategy 1 Strategy_2=2, //Strategy 2 Strategy_3=3, //Strategy 3 }; extern Strategy_Check Strategy=Strategy_2; extern bool Show_One_Signal_Per_Confirmation=false; extern ENUM_TIMEFRAMES TC_Time_Frame=PERIOD_CURRENT; extern int TC_ChannelPeriod=5; extern int TC_MaxChannelPeriod=30; extern int TC_MinChannelWidth=10; extern bool Use_HTF_OAAO_Trend_Confirmation=false; extern ENUM_TIMEFRAMES TC_HTF_Time_Frame=PERIOD_H4; extern int TC_HTF_ChannelPeriod=5; extern int TC_HTF_MaxChannelPeriod=30; extern int TC_HTF_MinChannelWidth=10; extern bool Use_X_Candles=false; extern int HTF1_X_Candles=1; int MaxBars=500; int Arrow_Distance=0; long Current_Bar; int Bars_count; int TF1_Bar_shifted; int TF2_Bar_shifted; double Buy_Buffer[]; double Sell_Buffer[]; double Last_Buffer[]; double Signal_Buffer[]; double _point; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int init() { Current_Bar = 0; if(!Use_HTF_OAAO_Trend_Confirmation) TC_HTF_Time_Frame=TC_Time_Frame; SetIndexBuffer(0, Sell_Buffer); SetIndexBuffer(1, Buy_Buffer); SetIndexBuffer(2, Last_Buffer); SetIndexBuffer(3, Signal_Buffer); SetIndexEmptyValue(0, 2147483647); SetIndexEmptyValue(1, 2147483647); SetIndexEmptyValue(2, 2147483647); SetIndexEmptyValue(3, 2147483647); _point = Point*MathPow(10,Digits%2); //--- return 0; } int Last_Trade=0; int Last_Trade_HTF1=0; int Last_Trade_HTF2=0; bool NewSignal_HTF=false; int last=0; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ 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 Remaining_Bars,i; int TC_Bar,TC_HTF_Bar; Remaining_Bars = rates_total - prev_calculated; ArraySetAsSeries(Buy_Buffer, true); ArraySetAsSeries(Sell_Buffer, true); ArraySetAsSeries(Last_Buffer, true); ArraySetAsSeries(Signal_Buffer, true); if(prev_calculated < 1) { ArrayInitialize(Buy_Buffer, 2147483647); ArrayInitialize(Sell_Buffer, 2147483647); ArrayInitialize(Last_Buffer, 2147483647); ArrayInitialize(Signal_Buffer, 2147483647); } else { Remaining_Bars = Remaining_Bars + 1; } i = Remaining_Bars - 1; if(i < 0) return rates_total; do { Bars_count = rates_total - 1; if(i < Bars_count) { if(Use_X_Candles) { TC_Bar = iBarShift(_Symbol, TC_Time_Frame, Time[i], false); TC_HTF_Bar = iBarShift(_Symbol, TC_HTF_Time_Frame, Time[i], false)+HTF1_X_Candles; } else { TC_Bar = iBarShift(_Symbol, TC_Time_Frame, Time[i], false); TC_HTF_Bar = iBarShift(_Symbol, TC_HTF_Time_Frame, Time[i], false); } if(TC_Bar<0 || TC_HTF_Bar<0) { Sell_Buffer[i]=0; Buy_Buffer[i]=0; } bool t1,t2,t3,t4; if(TC_Bar>=0 && TC_HTF_Bar>=0 && !Use_HTF_OAAO_Trend_Confirmation) { t1=CheckBuyTC(TC_Bar); if(t1) { Buy_Buffer[i] = iLow(NULL, Period(), i)-Arrow_Distance*Point(); Last_Buffer[i] = 1; Signal_Buffer[i] = 1; } else { Buy_Buffer[i] = 2147483647; } t3=CheckSellTC(TC_Bar); if(t3) { Sell_Buffer[i] = iHigh(NULL, Period(), i)+Arrow_Distance*Point(); Last_Buffer[i] = -1; Signal_Buffer[i] = -1; } else { Sell_Buffer[i] = 2147483647; } if(Buy_Buffer[i]==2147483647 && Sell_Buffer[i] == 2147483647) Last_Buffer[i] = Last_Buffer[i+1]; } if(TC_Bar>=0 && TC_HTF_Bar>=0 && Strategy==Strategy_1 && Use_HTF_OAAO_Trend_Confirmation) { t1=CheckBuyTC(TC_Bar); t2=CheckBuyTCHTF1(TC_HTF_Bar); if(t1 && t2) { Buy_Buffer[i] = iLow(NULL, Period(), i)-Arrow_Distance*Point(); Last_Buffer[i] = 1; Signal_Buffer[i] = 1; } else { Buy_Buffer[i] = 2147483647; } t3=CheckSellTC(TC_Bar); t4=CheckSellTCHTF1(TC_HTF_Bar); if(t3 && t4) { Sell_Buffer[i] = iHigh(NULL, Period(), i)+Arrow_Distance*Point(); Last_Buffer[i] = -1; Signal_Buffer[i] = -1; } else { Sell_Buffer[i] = 2147483647; } if(Buy_Buffer[i]==2147483647 && Sell_Buffer[i] == 2147483647) Last_Buffer[i] = Last_Buffer[i+1]; } if(TC_Bar>=0 && TC_HTF_Bar>=0 && Strategy==Strategy_2 && Show_One_Signal_Per_Confirmation && Use_HTF_OAAO_Trend_Confirmation) { t1=CheckBuyTC(TC_Bar); t2=CheckBuyTCHTF1(TC_HTF_Bar); t3=CheckSellTC(TC_Bar); t4=CheckSellTCHTF1(TC_HTF_Bar); if(t2) {NewSignal_HTF=true; last=1;} if(t4) {NewSignal_HTF=true; last=-1;} if(t1 && NewSignal_HTF && last==1) { NewSignal_HTF=false; Buy_Buffer[i] = iLow(NULL, Period(), i)-Arrow_Distance*Point(); Last_Buffer[i] = 1; Signal_Buffer[i] = 1; } else { Buy_Buffer[i] = 2147483647; } if(t3 && NewSignal_HTF && last==-1) { NewSignal_HTF=false; Sell_Buffer[i] = iHigh(NULL, Period(), i)+Arrow_Distance*Point(); Last_Buffer[i] = -1; Signal_Buffer[i] = -1; } else { Sell_Buffer[i] = 2147483647; } if(Buy_Buffer[i]==2147483647 && Sell_Buffer[i] == 2147483647) Last_Buffer[i] = Last_Buffer[i+1]; } if(TC_Bar>=0 && TC_HTF_Bar>=0 && Strategy==Strategy_2 && !Show_One_Signal_Per_Confirmation && Use_HTF_OAAO_Trend_Confirmation) { t1=CheckBuyTC(TC_Bar); t2=CheckBuyTCHTF2(TC_HTF_Bar); t3=CheckSellTC(TC_Bar); t4=CheckSellTCHTF2(TC_HTF_Bar); if(t1 && t2) { Buy_Buffer[i] = iLow(NULL, Period(), i)-Arrow_Distance*Point(); Last_Buffer[i] = 1; Signal_Buffer[i] = 1; } else { Buy_Buffer[i] = 2147483647; } if(t3 && t4) { Sell_Buffer[i] = iHigh(NULL, Period(), i)+Arrow_Distance*Point(); Last_Buffer[i] = -1; Signal_Buffer[i] = -1; } else { Sell_Buffer[i] = 2147483647; } if(Buy_Buffer[i]==2147483647 && Sell_Buffer[i] == 2147483647) Last_Buffer[i] = Last_Buffer[i+1]; } if(TC_Bar>=0 && TC_HTF_Bar>=0 && Strategy==Strategy_3 && Show_One_Signal_Per_Confirmation && Use_HTF_OAAO_Trend_Confirmation) { t1=CheckBuyTC(TC_Bar); t2=CheckBuyTCHTF3(TC_HTF_Bar); t3=CheckSellTC(TC_Bar); t4=CheckSellTCHTF3(TC_HTF_Bar); if(t2) {NewSignal_HTF=true; last=1;} if(t4) {NewSignal_HTF=true; last=-1;} if((last==1 && t3) || (last==-1 && t1)) {last=0; NewSignal_HTF=false;} if(t1 && NewSignal_HTF && last==1) { NewSignal_HTF=false; Buy_Buffer[i] = iLow(NULL, Period(), i)-Arrow_Distance*Point(); Last_Buffer[i] = 1; Signal_Buffer[i] = 1; } else { Buy_Buffer[i] = 2147483647; } if(t3 && NewSignal_HTF && last==-1) { NewSignal_HTF=false; Sell_Buffer[i] = iHigh(NULL, Period(), i)+Arrow_Distance*Point(); Last_Buffer[i] = -1; Signal_Buffer[i] = -1; } else { Sell_Buffer[i] = 2147483647; } if(Buy_Buffer[i]==2147483647 && Sell_Buffer[i] == 2147483647) Last_Buffer[i] = Last_Buffer[i+1]; } if(TC_Bar>=0 && TC_HTF_Bar>=0 && Strategy==Strategy_3 && !Show_One_Signal_Per_Confirmation && Use_HTF_OAAO_Trend_Confirmation) { t1=CheckBuyTC(TC_Bar); t2=CheckBuyTCHTF3(TC_HTF_Bar); t3=CheckSellTC(TC_Bar); t4=CheckSellTCHTF3(TC_HTF_Bar); if(t2) {NewSignal_HTF=true; last=1;} if(t4) {NewSignal_HTF=true; last=-1;} if((last==1 && t3) || (last==-1 && t1)) {last=0; NewSignal_HTF=false;} if(t1 && last==1 && NewSignal_HTF) { Buy_Buffer[i] = iLow(NULL, Period(), i)-Arrow_Distance*Point(); Last_Buffer[i] = 1; Signal_Buffer[i] = 1; } else { Buy_Buffer[i] = 2147483647; } if(t3 && last==-1 && NewSignal_HTF) { Sell_Buffer[i] = iHigh(NULL, Period(), i)+Arrow_Distance*Point(); Last_Buffer[i] = -1; Signal_Buffer[i] = -1; } else { Sell_Buffer[i] = 2147483647; } if(Buy_Buffer[i]==2147483647 && Sell_Buffer[i] == 2147483647) Last_Buffer[i] = Last_Buffer[i+1]; } } i = i - 1; } while(i >= 0); return rates_total; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CheckBuyTC(int x) { bool Buy_Now=false; bool Sell_Now=false; double haMedian = HeikenAshi_TC(TC_Time_Frame,x); double donchian_Upper=DC_Channel(TC_Time_Frame,x+1,2,MaxBars+TC_ChannelPeriod,TC_ChannelPeriod,TC_MaxChannelPeriod,TC_MinChannelWidth); if(haMedian>donchian_Upper && (Last_Trade==0 || Last_Trade==2)) {Buy_Now=true; Last_Trade=1; Sell_Now=false;} else Buy_Now=false; if(Buy_Now) return(true); return(false); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CheckSellTC(int x) { bool Buy_Now=false; bool Sell_Now=false; double haMedian = HeikenAshi_TC(TC_Time_Frame,x); double donchian_Lower=DC_Channel(TC_Time_Frame,x+1,1,MaxBars+TC_ChannelPeriod,TC_ChannelPeriod,TC_MaxChannelPeriod,TC_MinChannelWidth); if(haMediandonchian_Upper && (Last_Trade_HTF1==0 || Last_Trade_HTF1==2)) {Buy_Now=true; Last_Trade_HTF1=1; Sell_Now=false;} else Buy_Now=false; if(Buy_Now) return(true); return(false); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CheckSellTCHTF1(int x) { bool Buy_Now=false; bool Sell_Now=false; double haMedian = HeikenAshi_HTF1(TC_HTF_Time_Frame,x); double donchian_Lower=DC_Channel(TC_HTF_Time_Frame,x+1,1,MaxBars+TC_HTF_ChannelPeriod,TC_HTF_ChannelPeriod,TC_HTF_MaxChannelPeriod,TC_HTF_MinChannelWidth); //Comment(HeikenAshi_HTF1(TC_HTF_Time_Frame,x)+" | "+donchian_Lower); if(haMediandonchian_Upper && (Last_Trade_HTF1==0 || Last_Trade_HTF1==2)) {Buy_Now=true; Last_Trade_HTF1=1; Sell_Now=false;} else Buy_Now=false; if(Buy_Now) return(true); return(false); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CheckSellTCHTF3(int x) { bool Buy_Now=false; bool Sell_Now=false; double haMedian = HeikenAshi_HTF1(TC_HTF_Time_Frame,x); double donchian_Lower=DC_Channel(TC_HTF_Time_Frame,x+1,1,MaxBars+TC_HTF_ChannelPeriod,TC_HTF_ChannelPeriod,TC_HTF_MaxChannelPeriod,TC_HTF_MinChannelWidth); //Comment(HeikenAshi_HTF1(TC_HTF_Time_Frame,x)+" | "+donchian_Lower); if(haMediandonchian_Upper) {Buy_Now_HTF=true; Last_Trade_HTF2=1; Sell_Now_HTF=false;} if(Buy_Now_HTF) return(true); return(false); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CheckSellTCHTF2(int x) { double haMedian = HeikenAshi_HTF1(TC_HTF_Time_Frame,x); double donchian_Lower=DC_Channel(TC_HTF_Time_Frame,x+1,1,MaxBars+TC_HTF_ChannelPeriod,TC_HTF_ChannelPeriod,TC_HTF_MaxChannelPeriod,TC_HTF_MinChannelWidth); if(haMedian= MinChannelWidth*_point) break; else { if(channel >= maxperiod && i + channel < limit) maxperiod = maxperiod + 1; else continue; } } } if(type==1) return(hh - width); if(type==2) return(ll + width); return(0); } //+------------------------------------------------------------------+