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
MQL II Code.
========
For shift=Bars-1 Downto 0 Begin
val1=0;
val2=0;
iMaSlowPrevious = iMAEx(SlowPeriod, MODE_EMA, 0, PRICE_CLOSE, shift);
iMaSlowCurrent = iMAEx(SlowPeriod, MODE_EMA, 0, PRICE_CLOSE, shift+1);
iMaFastPrevious = iMAEx(FastPeriod, MODE_EMA, 0, PRICE_CLOSE, shift);
iMaFastCurrent = iMAEx(FastPeriod, MODE_EMA, 0, PRICE_CLOSE, shift+1);
If iMaFastPrevious<iMaSlowPrevious and iMaFastCurrent>iMASlowCurrent Then val1=Close[shift+1];
If iMaFastPrevious>iMaSlowPrevious and iMaFastCurrent<iMASlowCurrent Then val2=Close[shift+1];
SetIndexValue(shift,val1+5*point);
SetIndexValue2(shift,val2-5*point);
End;
MQL4 Code
=======
//+------------------------------------------------------------------+
//| FirstIndicator.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net/"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
//---- input parameters
extern int FastPeriod=5;
extern int SlowPeriod=20;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double iMaSlowPrevious;
double iMaSlowCurrent;
double iMaFastPrevious;
double iMaFastCurrent;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_ARROW,EMPTY);
SetIndexArrow(0,233);
SetIndexBuffer(0, ExtMapBuffer1);
SetIndexStyle(1,DRAW_ARROW,EMPTY);
SetIndexArrow(1,234);
SetIndexBuffer(1, ExtMapBuffer2);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
for(int i=0; i<limit; i++)
{
iMaSlowPrevious = iMA(NULL,0,SlowPeriod,MODE_EMA,0,PRICE_CLOSE,i+1);
iMaSlowCurrent = iMA(NULL,0,SlowPeriod,MODE_EMA,0,PRICE_CLOSE,i);
iMaFastPrevious = iMA(NULL,0,FastPeriod,MODE_EMA,0,PRICE_CLOSE,i+1);
iMaFastCurrent = iMA(NULL,0,FastPeriod,MODE_EMA,0,PRICE_CLOSE,i);
if ((iMaFastPrevious<iMaSlowPrevious) && (iMaFastCurrent>iMaSlowCurrent))
ExtMapBuffer1[i]=Close[i+1];
if ((iMaFastPrevious>iMaSlowPrevious) && (iMaFastCurrent<iMaSlowCurrent))
ExtMapBuffer2[i]=Close[i+1];
}
//----
return(0);
}
//+------------------------------------------------------------------+