//+------------------------------------------------------------------+ //| SB_EMA_Cross.mq4 - free indicator by StockBook | //| https://stockbook.blvis.in | //+------------------------------------------------------------------+ #property copyright "StockBook" #property link "https://stockbook.blvis.in" #property version "1.00" #property description "Two EMAs with arrows on crossovers. For analysis only, not investment advice." #property strict #property indicator_chart_window #property indicator_buffers 4 extern int FastPeriod = 9; extern int SlowPeriod = 21; double FastB[],SlowB[],BuyB[],SellB[]; int OnInit() { SetIndexBuffer(0,FastB); SetIndexBuffer(1,SlowB); SetIndexBuffer(2,BuyB); SetIndexBuffer(3,SellB); SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,clrDodgerBlue); SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1,clrOrange); SetIndexStyle(2,DRAW_ARROW,STYLE_SOLID,1,clrLimeGreen); SetIndexArrow(2,233); SetIndexStyle(3,DRAW_ARROW,STYLE_SOLID,1,clrRed); SetIndexArrow(3,234); SetIndexLabel(0,"Fast EMA"); SetIndexLabel(1,"Slow EMA"); SetIndexLabel(2,"Cross up"); SetIndexLabel(3,"Cross down"); IndicatorShortName("SB EMA Cross ("+IntegerToString(FastPeriod)+","+IntegerToString(SlowPeriod)+")"); return(INIT_SUCCEEDED); } int start() { int counted=IndicatorCounted(); if(counted<0) return(-1); int limit=Bars-counted; if(counted>0) limit++; if(limit>Bars-1) limit=Bars-1; for(int i=limit-1;i>=0;i--) { FastB[i]=iMA(NULL,0,FastPeriod,0,MODE_EMA,PRICE_CLOSE,i); SlowB[i]=iMA(NULL,0,SlowPeriod,0,MODE_EMA,PRICE_CLOSE,i); BuyB[i]=EMPTY_VALUE; SellB[i]=EMPTY_VALUE; double f1=iMA(NULL,0,FastPeriod,0,MODE_EMA,PRICE_CLOSE,i+1); double s1=iMA(NULL,0,SlowPeriod,0,MODE_EMA,PRICE_CLOSE,i+1); double gap=iATR(NULL,0,14,i)*0.5; if(f1<=s1 && FastB[i]>SlowB[i]) BuyB[i]=Low[i]-gap; if(f1>=s1 && FastB[i]