this is the code
//$------------------------------------------------------------------$ //| MA Crossing Magic.mq4 | //| Copyright 2018, MohamedEgyForex | //| mohamedegyforex | //$------------------------------------------------------------------$ #property copyright "Copyright 2018, MohamedEgyForex" #property link "mohamedegyforex" #property version "1.00" #property strict #property indicator_chart_window #property indicator_buffers 9 #property indicator_plots 9 //--- plot EMA1_ #property indicator_label1 "EMA1_" #property indicator_type1 DRAW_LINE #property indicator_color1 clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 2 //--- plot EMA2_ #property indicator_label2 "EMA2_" #property indicator_type2 DRAW_LINE #property indicator_color2 clrLimeGreen #property indicator_style2 STYLE_SOLID #property indicator_width2 2 //--- plot EMA3_ #property indicator_label3 "EMA3_" #property indicator_type3 DRAW_LINE #property indicator_color3 clrBlue #property indicator_style3 STYLE_SOLID #property indicator_width3 2 //--- plot BUY_ #property indicator_label4 "BUY_" #property indicator_type4 DRAW_ARROW #property indicator_color4 clrDodgerBlue #property indicator_style4 STYLE_SOLID #property indicator_width4 1 //--- plot SELL_ #property indicator_label5 "SELL_" #property indicator_type5 DRAW_ARROW #property indicator_color5 clrViolet #property indicator_style5 STYLE_SOLID #property indicator_width5 1 //--- plot Buffer_1 #property indicator_label6 "Buffer_1" #property indicator_type6 DRAW_LINE #property indicator_color6 clrRed #property indicator_style6 STYLE_SOLID #property indicator_width6 1 //--- plot Buffer_2 #property indicator_label7 "Buffer_2" #property indicator_type7 DRAW_LINE #property indicator_color7 clrRed #property indicator_style7 STYLE_SOLID #property indicator_width7 1 //--- plot Buffer_3 #property indicator_label8 "Buffer_3" #property indicator_type8 DRAW_LINE #property indicator_color8 clrRed #property indicator_style8 STYLE_SOLID #property indicator_width8 1 //--- plot Buffer_4 #property indicator_label9 "Buffer_4" #property indicator_type9 DRAW_LINE #property indicator_color9 clrRed #property indicator_style9 STYLE_SOLID #property indicator_width9 1 // Indicator parameters. input int EMA_1 = 5; input int EMA_2 = 15; input int EMA_3 = 100; //--- indicator buffers double EMA1_Buffer[]; double EMA2_Buffer[]; double EMA3_Buffer[]; double BUY_Buffer[]; double SELL_Buffer[]; double Buffer_1Buffer[]; double Buffer_2Buffer[]; double Buffer_3Buffer[]; double Buffer_4Buffer[]; //$------------------------------------------------------------------$ //| Custom indicator initialization function | //$------------------------------------------------------------------$ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,EMA1_Buffer); SetIndexBuffer(1,EMA2_Buffer); SetIndexBuffer(2,EMA3_Buffer); SetIndexBuffer(3,BUY_Buffer); SetIndexBuffer(4,SELL_Buffer); SetIndexBuffer(5,Buffer_1Buffer); SetIndexBuffer(6,Buffer_2Buffer); SetIndexBuffer(7,Buffer_3Buffer); SetIndexBuffer(8,Buffer_4Buffer); //--- setting a code from the Wingdings charset as the property of PLOT_ARROW SetIndexArrow(3,233); SetIndexArrow(4,234); //--- return(INIT_SUCCEEDED); } //$------------------------------------------------------------------$ //| Custom indicator deinitialization function | //$------------------------------------------------------------------$ int deinit() { //---- int k=0; for(k=Bars-1;k>=0;k--) { //ObjectDelete("Object_Name"+IntegerToString(k)); //ObjectsDeleteAll(); } return(0); } //$------------------------------------------------------------------$ //$------------------------------------------------------------------$ //| Custom indicator iteration function | //$------------------------------------------------------------------$ 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 limit=rates_total-prev_calculated; //--- Main Loop //if(rates_total>prev_calculated) //int limit=0; if(prev_calculated==0) limit=rates_total-1; else limit=rates_total-prev_calculated; //for(int i=1; i<limit; i++) for(int i=limit; i>=1; i--) { //---- //System EMA EMA1_Buffer[i]=EMA(i,EMA_1); EMA2_Buffer[i]=EMA(i,EMA_2); EMA3_Buffer[i]=EMA(i,EMA_3); //Buy Arrow if ( EMA(i,EMA_1)>EMA(i,EMA_2) && EMA(i+1,EMA_1)<EMA(i+1,EMA_2) && EMA(i,EMA_2)>EMA(i,EMA_3) )BUY_Buffer[i]=Low[i]-ArrowSpacer(); //---Sell Arrow if ( EMA(i,EMA_1)<EMA(i,EMA_2) && EMA(i+1,EMA_1)>EMA(i+1,EMA_2) && EMA(i,EMA_2)<EMA(i,EMA_3) )SELL_Buffer[i]=High[i]+ArrowSpacer(); Buffer_1Buffer[i]=0; Buffer_2Buffer[i]=0; Buffer_3Buffer[i]=0; Buffer_4Buffer[i]=0; //---- } //--- return value of prev_calculated for next call return(rates_total); } //$------------------------------------------------------------------$ //$------------------------------------------------------------------$ //| External function | //$------------------------------------------------------------------$ double EMA(int i,int EMA_Period){return(iMA(NULL,0,EMA_Period,0,MODE_EMA,PRICE_TYPICAL,i));} //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double ArrowSpacer() { double Arrow_Space=0; if( PERIOD_M1 == Period() ) Arrow_Space=(5*Point); if( PERIOD_M5 == Period() ) Arrow_Space=(10*Point); if( PERIOD_M15 == Period() ) Arrow_Space=(15*Point); if( PERIOD_M30 == Period() ) Arrow_Space=(20*Point); if( PERIOD_H1 == Period() ) Arrow_Space=(15*Point); if( PERIOD_H4 == Period() ) Arrow_Space=(40*Point); if( PERIOD_D1 == Period() ) Arrow_Space=(80*Point); if( PERIOD_W1 == Period() ) Arrow_Space=(150*Point); if( PERIOD_MN1 == Period() ) Arrow_Space=(200*Point); return(Arrow_Space); } //$------------------------------------------------------------------$
Eleni Anna Branou:
Please use the </> button to insert your above code.
sorry for that
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello Coder:
I want the indicator to only display buy arrow if the current arrow is higher than previous arrow,
and display sell arrow if the arrow lower than previous arrow
how to code that ?! please help
Thanks in advance