MA Cross 3MACross Alert WarnSig Indicator For MT5
Table Of Contents:
- MA Cross 3MACross Alert WarnSig Indicator For MT5
- Installing the MA Cross 3MACross Alert WarnSig Indicator For MT5
- Parameters of the MA Cross 3MACross Alert WarnSig Indicator For MT5
- Buffers of the MA Cross 3MACross Alert WarnSig Indicator For MT5
- Main Parts Of The Code
The MA Cross 3MACross Alert WarnSig Indicator For MT5 calculates 3 moving averages with different periods. If a crossover occurs then you will get an alert. Then indictor also draws upward and downward arrows on the chart at those candles where the crossovers occur. You can configure the moving averages and the alerts according to your needs.
Installing the MA Cross 3MACross Alert WarnSig Indicator For MT5
After you downloaded the indicator via the form above you need to unzip the zip-file. Then you need to copy the file MA Cross 3MACross Alert WarnSig.mq5 into the folder MQL5\Indicators of your MT5 installation. After that please restart MT5 and then you will be able to see the indicator in the list of indicators.
Parameters of the MA Cross 3MACross Alert WarnSig Indicator For MT5
The MA Cross 3MACross Alert WarnSig Indicator For MT5 has 14 parameters to configure.
input int InpMAPeriodFirst = 5; // Period of the first Moving Average input int InpMAShiftFirst = 0; // Shift of the first Moving Average input ENUM_MA_METHOD InpMAMethodFirst = MODE_SMMA; // Method of the first Moving Average input int InpMAPeriodSecond = 13; // Period of the second Moving Average input int InpMAShiftSecond = 0; // Shift of the second Moving Average input ENUM_MA_METHOD InpMAMethodSecond = MODE_SMMA; // Method of the second Moving Average input int InpMAPeriodThird = 34; // Period of the third Moving Average input int InpMAShiftThird = 0; // Shift of the third Moving Average input ENUM_MA_METHOD InpMAMethodThird = MODE_SMMA; // Method of the third Moving Average input bool crossesOnCurrent=true; input bool alertsOn =true; input bool alertsMessage =true; input bool alertsSound =false; input bool alertsEmail =false;
Buffers of the MA Cross 3MACross Alert WarnSig Indicator For MT5
The MA Cross 3MACross Alert WarnSig Indicator For MT5 provides 4 buffers.
SetIndexBuffer(0,CrossUp,INDICATOR_DATA); SetIndexBuffer(1,CrossDown,INDICATOR_DATA); SetIndexBuffer(2,CrossGhostUp,INDICATOR_DATA); SetIndexBuffer(3,CrossGhostDown,INDICATOR_DATA);
Main Parts Of The Code
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[]) { //--- if(rates_total lt 10 || rates_total lt InpMAPeriodThird) // very few bars return(0); int limit=rates_total-prev_calculated+1; if(prev_calculated==0) limit=rates_total-1; ArraySetAsSeries(high,true); ArraySetAsSeries(low,true); ArraySetAsSeries(close,true); ArraySetAsSeries(time,true); for(int i=limit;i gt =0;i--) { //--- we look for crossing of two indicators double First[]; double Second[]; double Third[]; ArraySetAsSeries(First,true); ArraySetAsSeries(Second,true); ArraySetAsSeries(Third,true); int buffer_num=0; // indicator buffer number int start_pos=i; // start position int count=2; // amount to copy bool get_first = true; bool get_second= true; bool get_third = true; get_first = iMAGet(handle_iMA_First,buffer_num,start_pos,count,First); get_second = iMAGet(handle_iMA_Second,buffer_num,start_pos,count,Second); get_third = iMAGet(handle_iMA_Third,buffer_num,start_pos,count,Third); if(!get_first || !get_second || !get_third) continue; //--- for debug in tester: //Comment("First[0] ",DoubleToString(First[0],Digits()+1),", First[1] ",DoubleToString(First[1],Digits()+1)," ", // "Second[0] ",DoubleToString(Second[0],Digits()+1),", Second[1] ",DoubleToString(Second[1],Digits()+1)," ", // "Third[0] ",DoubleToString(Third[0],Digits()+1),", Third[1] ",DoubleToString(Third[1],Digits()+1)," "); double Range=0.0; int counter=i-9; counter=(counter lt 0)?0:counter; for(int j=counter;j lt =i;j++) Range+=MathAbs(high[j]-low[j]); Range/=10.0; // "10.0"this amount of the taken values //--- avoid current bar if not allowed to check crosses on current (i==0) if(crossesOnCurrent==false && i==0) continue; //--- int crossID = 0; double curr = 0.0; double prev = 0.0; double point = 0.0; while(true) { curr= First[0]- Second[0]; prev= First[1]- Second[1]; point=(First[0]+First[1])/2; if(curr*prev lt =0) { crossID=1; break; } curr=First[0]- Third[0]; prev=First[1]- Third[1]; if(curr*prev lt =0) { crossID=2; break; } curr=Second[0]- Third[0]; prev=Second[1]- Third[1]; point=(Second[0]+Second[1])/2; if(curr*prev lt =0) { crossID=3; break; } break; } // the interesting thing is the direction of the crossing // which MA is the primary and which one the secondary // if you do not know that you can not determine the "direction" // of the cross CrossUp[i] =EMPTY_VALUE; CrossDown[i] =EMPTY_VALUE; CrossGhostUp[i] =EMPTY_VALUE; CrossGhostDown[i] =EMPTY_VALUE; if(crossID gt 0) { if(alertsOn) { double curr_norm=NormalizeDouble(curr,Digits()); if((i==0 && crossesOnCurrent==true) || (i==1 && crossesOnCurrent==false)) { switch(crossID) { case 1: if(curr_norm gt 0.0) doAlert(" 3MACross: "First MA" crossed "Second MA" UP",time[i],close[i]); else if(curr_norm lt 0.0) doAlert(" 3MACross: "First MA" crossed "Second MA" DOWN",time[i],close[i]); break; case 2: if(curr_norm gt 0.0) doAlert(" 3MACross: "First MA" crossed "Third MA" UP",time[i],close[i]); else if(curr_norm lt 0.0) doAlert(" 3MACross: "First MA" crossed "Third MA" DOWN",time[i],close[i]); break; case 3: if(curr_norm gt 0.0) doAlert(" 3MACross: "Second MA" crossed "Third MA" UP",time[i],close[i]); else if(curr_norm lt 0.0) doAlert(" 3MACross: "Second MA" crossed "Third MA" DOWN",time[i],close[i]); break; } } //--- if(i==0) { if(curr_norm gt 0.0) CrossGhostUp[i]=point-Range*0.5; else if(curr_norm lt 0.0) CrossGhostDown[i]=point+Range*0.5; } else { if(curr_norm gt 0.0) CrossUp[i]=point-Range*0.5; else if(curr_norm lt 0.0) CrossDown[i]=point+Range*0.5; } } } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| Get value of buffers for the iMA | //+------------------------------------------------------------------+ bool iMAGet(int handle_iMA, // indicator handle int buffer_num, // indicator buffer number int start_pos, // start position int count, // amount to copy double &buffer[] // target array to copy ) { //--- reset error code ResetLastError(); //--- fill a part of the iMABuffer array with values from the indicator buffer that has 0 index if(CopyBuffer(handle_iMA,buffer_num,start_pos,count,buffer)!=count) { //--- if the copying fails, tell the error code PrintFormat("Failed to copy data from the iMA indicator, error code %d",GetLastError()); //--- quit with zero result - it means that the indicator is considered as not calculated return(false); } return(true); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void doAlert(string doWhat,datetime time_last_bar,double close) { static string previousAlert="nothing"; static datetime previousTime=0; string message; //---- if(previousAlert!=doWhat || previousTime!=time_last_bar) { previousAlert =doWhat; previousTime =time_last_bar; // if time needed : // message = StringConcatenate(Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," @",Bid," ", doWhat); message=Symbol()+" at "+DoubleToString(close,Digits())+" "+doWhat; if(alertsMessage) Alert(message); if(alertsEmail) SendMail(Symbol()+" 3MACross:"+" M"+EnumToString(Period()),message); if(alertsSound) PlaySound("alert2.wav"); } } //+------------------------------------------------------------------+