trendtest_OHLC

Author: Copyright � 2005, Jason Robinson (jnrtrading)
trendtest_OHLC
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1It plays sound alerts
0 Views
0 Downloads
0 Favorites
trendtest_OHLC
//+------------------------------------------------------------------+
//|                                         EMA-Crossover_Signal.mq4 |
//|         Copyright © 2005, Jason Robinson (jnrtrading)            |
//|                   http://www.jnrtading.co.uk                     |
//+------------------------------------------------------------------+

/*
  +------------------------------------------------------------------+
  | Allows you to enter two ma periods and it will then show you at |
  | Which point they crossed over. It is more usful on the shorter   |
  | periods that get obscured by the bars / candlesticks and when    |
  | the zoom level is out. Also allows you then to remove the emas   |
  | from the chart.               |
  +------------------------------------------------------------------+
*/   
#property copyright "Copyright © 2005, Jason Robinson (jnrtrading)"
#property link      "http://www.jnrtrading.co.uk"

#property  indicator_separate_window
#property indicator_buffers 6
#property indicator_color1 Yellow
#property indicator_color2 SkyBlue
#property indicator_color3 Red
#property indicator_color4 White

//---- input parameters
/*************************************************************************
---------------------------------------
PRICE_CLOSE    0 Close price. 
PRICE_OPEN     1 Open price. 
PRICE_HIGH     2 High price. 
PRICE_LOW      3 Low price. 
PRICE_MEDIAN   4 Median price, (high+low)/2. 
PRICE_TYPICAL  5 Typical price, (high+low+close)/3. 
PRICE_WEIGHTED 6 Weighted close price, (high+low+close+close)/4. 
You must use the numeric value of the Applied Price that you want to use
when you set the 'applied_price' value with the indicator inputs.
---------------------------------------
**************************************************************************/

double CrossUp[];
double CrossDown[];
extern int FasterMode = 3; //0=sma, 1=ema, 2=smma, 3=lwma
extern int FasterMA =   3;
extern int Faster_applied_price=PRICE_OPEN;
extern int SlowerMode = 3; //0=sma, 1=ema, 2=smma, 3=lwma
extern int SlowerMA =   3;
extern int Slower_applied_price=PRICE_CLOSE;
double ExtMapBuffer1[];
double ExtMapBuffer2[];
extern bool SoundON=true;
double alertTag;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID,3);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID,3);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, CrossDown);
   //---- indicators
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,ExtMapBuffer1);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,ExtMapBuffer2);
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
   int limit, i, counter;
   double fasterMAnow, slowerMAnow, fasterMAprevious, slowerMAprevious, 
fasterMAafter, slowerMAafter;
   double Range, AvgRange;
   int counted_bars=IndicatorCounted();
   int counted_bars1=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;
   
   for(i = 0; i <= limit; i++) {
   
      counter=i;
      Range=0;
      AvgRange=0;
      for (counter=i ;counter<=i+9;counter++)
      {
         AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
      }
      Range=AvgRange/10;
       
      fasterMAnow = iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, 
i);
      fasterMAprevious = iMA(NULL, 0, FasterMA, 0, FasterMode, 
PRICE_CLOSE, i+1);
      fasterMAafter = iMA(NULL, 0, FasterMA, 0, FasterMode, 
PRICE_CLOSE, i-1);

      slowerMAnow = iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_CLOSE, 
i);
      slowerMAprevious = iMA(NULL, 0, SlowerMA, 0, SlowerMode, 
PRICE_CLOSE, i+1);
      slowerMAafter = iMA(NULL, 0, SlowerMA, 0, SlowerMode, 
PRICE_CLOSE, i-1);
      
      if ( (fasterMAnow > slowerMAnow) && (fasterMAprevious < 
slowerMAprevious) && (fasterMAafter > slowerMAafter)) {
         CrossUp[i] = Low[i] - Range*0.5;
         if (SoundON==true && alertTag!=Time[0]){
  //     Alert("EMA Cross Trend going UP on ",Symbol(),Period());
        PlaySound("trendup.wav");
        alertTag = Time[0];}
      }
      else if ((fasterMAnow < slowerMAnow) && (fasterMAprevious > 
slowerMAprevious) && (fasterMAafter < slowerMAafter)) {
         CrossDown[i] = High[i] + Range*0.5;
         if (SoundON==true && alertTag!=Time[0]){
  //        Alert("EMA Cross Trend going Down on ",Symbol(),Period());
          PlaySound("trendn.wav");
          alertTag = Time[0];
        }
      }
   }


//---- check for possible errors
   if (counted_bars1<0) return(-1);
//---- last counted bar will be recounted
   if (counted_bars1>0) counted_bars1--;
   
   int pos=Bars-counted_bars1;
   
     
 
   while(pos>=0)
     {
         ExtMapBuffer1[pos]= iMA(NULL,0,FasterMA,0,FasterMode,Faster_applied_price,pos);

         ExtMapBuffer2[pos]= iMA(NULL,0,SlowerMA,0,SlowerMode,Slower_applied_price,pos);

         
         pos--;
     }
//----      

   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 ---