Cronex Demarker Bars

Cronex Demarker Bars
Indicators Used
DeMarker indicatorMoving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
Cronex Demarker Bars
//+------------------------------------------------------------------+
//|                                         Cronex Demarker Bars.mq4 |
//|                                         Adapted by CJA           |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|                                              Cronex DeMarker.mq4 |
//|                                        Copyright © 2007, Cronex. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2007, Cronex"
#property  link      "http://www.metaquotes.net/"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 6

#property  indicator_color4  DarkGreen
#property  indicator_color5  Maroon
#property  indicator_color6  DarkGoldenrod

#property  indicator_width4  2
#property  indicator_width5  2
#property  indicator_width6  2
//---- indicator parameters
extern int DeMarker=25;
extern int FastMA=14;
extern int SlowMA=25;

extern bool   AlertON = false;
extern bool   SoundON = false;
extern string SoundFile_UP = "Alert";
extern string SoundFile_DN = "Alert2"; 
//---- indicator buffers
double     DeMarkerBuffer[];
double     FastMABuffer[];
double     SlowMABuffer[];
double UpBuffer[];
double DnBuffer[];
double EqBuffer[];
int  TimeFrame;
string TF;
double trend;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   SetIndexStyle(0,DRAW_NONE);
   SetIndexStyle(1,DRAW_NONE);
   SetIndexStyle(2,DRAW_NONE);   
   SetIndexDrawBegin(1,SlowMA);
//   IndicatorDigits(Digits+1);
//---- indicator buffers mapping
   SetIndexBuffer(0,DeMarkerBuffer);
   SetIndexBuffer(1,FastMABuffer);
   SetIndexBuffer(2,SlowMABuffer);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("Cronex DeMarker Bars");
   SetIndexLabel(0,"");
   SetIndexLabel(1,"");
   SetIndexLabel(2,"");
   
   SetIndexStyle(3,DRAW_HISTOGRAM);
   SetIndexStyle(4,DRAW_HISTOGRAM);
   SetIndexStyle(5,DRAW_HISTOGRAM);
   
   SetIndexBuffer(3,UpBuffer);
   SetIndexBuffer(4,DnBuffer);
   SetIndexBuffer(5,EqBuffer);
   
   SetIndexLabel(3,"");
   SetIndexLabel(4,"");
   SetIndexLabel(5,"");
   
    	switch(TimeFrame)
	{
		case 1:		TF=" M1";  break;
		case 5:		TF=" M5";  break;
		case 15:		TF=" M15"; break;
		case 30:		TF=" M30"; break;
		case 60:		TF=" H1";  break;
		case 240:	TF=" H4";  break;
		case 1440:	TF=" D1";  break;
		case 10080:	TF=" W1";  break;
		case 43200:	TF=" MN1"; break;
		default:	  {TimeFrame = Period(); init(); return(0);}
	}
   
  
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Cronex DeMarker                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- DeMarker counted in the 1-st buffer

   for(int i=0; i<limit; i++)
      DeMarkerBuffer[i]=iDeMarker(NULL,0,DeMarker,i);
//---- signal line counted in the 2-nd buffer
   for(i=0; i<limit; i++)
    {  
      FastMABuffer[i]=iMAOnArray(DeMarkerBuffer,Bars,FastMA,0,MODE_LWMA,i);
      SlowMABuffer[i]=iMAOnArray(DeMarkerBuffer,Bars,SlowMA,0,MODE_LWMA,i);
     
     }
     for(i=0; i<limit; i++)
    {  
        
     if((FastMABuffer[i] > SlowMABuffer[i])&&(DeMarkerBuffer[i] > SlowMABuffer[i])&&(DeMarkerBuffer[i] > FastMABuffer[i])){trend=1;}
     else if((FastMABuffer[i] < SlowMABuffer[i])&&(DeMarkerBuffer[i] < SlowMABuffer[i])&&(DeMarkerBuffer[i] < FastMABuffer[i])){trend=-1;}
     else {trend=2;}
     
	  if (trend==1)
	  {
	  
	  UpBuffer[i]=1;
	  EqBuffer[i]=0;
	  DnBuffer[i]=0;
	  
	  
	  }
	  if (trend==2) 
	  {
	  
	  UpBuffer[i]=0;
	  EqBuffer[i]=1;
	  DnBuffer[i]=0;
	  
	  }
	  if (trend==-1) 
	  {
	    
	  UpBuffer[i]=0;
	  EqBuffer[i]=0;
	  DnBuffer[i]=1;
	 
	  }}
	  double Price = iMA(NULL,PERIOD_M1,1,0,MODE_SMA,PRICE_CLOSE,0);
	  static datetime timeprev;

     if(timeprev==Time[0]) {
     return(0); 
     } else if (timeprev==0) {
     timeprev=Time[0]; 
     return(0);
     } else {
     timeprev=Time[0];
  
   
	  if (trend==1)
	  if(AlertON){Alert(Symbol()+""+TF+" : DEM Bars X UP @ "+DoubleToStr(Price,Digits));}
     if (SoundON) PlaySound (SoundFile_UP);
     if (trend==-1)
     if(AlertON){Alert(Symbol()+""+TF+" : DEM Bars X DOWN @ "+DoubleToStr(Price,Digits));}       
     if (SoundON) PlaySound (SoundFile_DN);
	  }
	  
       
//---- done
   return(0);
  }
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---