Re: MT4 Indicator requests and ideas
Posted: Thu May 07, 2020 11:38 pm
Could an indicator be coded that compares the value of DEMA to SMMA? EG: when the DEMA is xx points away from SMMA it will draw a vertical line on screen to show the extreme movement and warn of immediate exit.
OR, if that is not achievable, code an indicator that does the comparison with ema's only? I already hold an indicator that did this but it has stopped working on all charts and all MT4 platforms - but I have copied and pasted the code below in case it can be fixed and adapted to different ma's.
Thanks
TEAMTRADER
COPY
OR, if that is not achievable, code an indicator that does the comparison with ema's only? I already hold an indicator that did this but it has stopped working on all charts and all MT4 platforms - but I have copied and pasted the code below in case it can be fixed and adapted to different ma's.
Thanks
TEAMTRADER
COPY
Code: Select all
//+------------------------------------------------------------------+
//| EMA_Gap.mq4 |
//| EB |
//| |
//+------------------------------------------------------------------+
#property copyright "EB"
#property link ""
#property version "1.00"
#property strict
extern int EMA1=6;
extern int EMA2=8;
extern int Gap=144;
int LineCounter=0;
datetime last_time;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
for(int i=1000; i>1; i--)
{
PlotSignal(i);
}
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
for(int i=0; i<=LineCounter; i++)
{
ObjectDelete("EMA Gap Buy Signal "+i);
ObjectDelete("EMA Gap Sell Signal "+i);
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
if(last_time!=Time[0])
{
PlotSignal(1);
last_time=Time[0];
}
}
//+------------------------------------------------------------------+
void PlotSignal(int bar)
{
int digits;
double ema1, ema2, gap,diff;
digits=SymbolInfoInteger(Symbol(),SYMBOL_DIGITS);
if(digits==3 || digits==5) gap=10*Gap;
else gap=Gap;
gap=NormalizeDouble(MathPow(0.1,digits)*gap,digits);
Print("GAP: ",gap);
ema1=iMA(NULL,0,EMA1,0,MODE_EMA,PRICE_CLOSE,bar);
ema2=iMA(NULL,0,EMA2,0,MODE_EMA,PRICE_CLOSE,bar);
diff=NormalizeDouble(MathAbs(ema1-ema2),digits);
//Short: ema above long ema by gap pips, sell sinal for reversal
if(diff>=gap && ema1>ema2)
{
ObjectCreate(ChartID(),"EMA Gap Sell Signal "+LineCounter,OBJ_VLINE,0,Time[bar],Bid);
ObjectSetInteger(ChartID(),"EMA Gap Sell Signal "+LineCounter,OBJPROP_COLOR,Red);
LineCounter++;
}
else if(diff>=gap && ema1<ema2)
{
ObjectCreate(ChartID(),"EMA Gap Buy Signal "+LineCounter,OBJ_VLINE,0,Time[bar],Bid);
ObjectSetInteger(ChartID(),"EMA Gap Buy Signal "+LineCounter,OBJPROP_COLOR,Blue);
LineCounter++;
}
}