Navigation:Home > Content >

GannOvl.mq4

Time: 2015-10-13 | Download file:GannOvl.mq4

#include 
//+------------------------------------------------------------------+
//|                                                             .mq4 |
//| Gann Overlay to find changes in trend                            |
//|                                                                  |
//|                                        Converted by Mql2Mq4 v2.0 |
//|                                            http://yousky.free.fr |
//|                                  Copyright (c) 2006, Yousky Soft |
//+------------------------------------------------------------------+

#property copyright " Copyright © 2004, MetaQuotes Software Corp."
#property link      " http://www.metaquotes.net/"

#property indicator_chart_window
#property indicator_color1 Blue
#property indicator_buffers 2
#property indicator_color2 Red

//+------------------------------------------------------------------+
//| Common External variables                                        |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| External variables                                               |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Special Convertion Functions                                     |
//+------------------------------------------------------------------+

int LastTradeTime;
double ExtHistoBuffer[];
double ExtHistoBuffer2[];

void SetIndexValue(int shift, double value)
{
  ExtHistoBuffer[shift] = value;
}

void SetIndexValue2(int shift, double value)
{
  ExtHistoBuffer2[shift] = value;
}

//+------------------------------------------------------------------+
//| End                                                              |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Initialization                                                   |
//+------------------------------------------------------------------+

int init()
{
   SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID);
   SetIndexBuffer(0, ExtHistoBuffer);
   SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID);
   SetIndexBuffer(1, ExtHistoBuffer2);
   return(0);
}
int start()
{
//+------------------------------------------------------------------+
//| Local variables                                                  |
//+------------------------------------------------------------------+
int shift = 0;
double i = 0;
double slope = 0;
int refbar = 0;
double refhi = 0;
double reflo = 0;
double cnt = 0;
double cap = 1;
double prev = 0;
double pr_bar = 0;
double up_cnt = 0;
double dn_cnt = 0;
int pen_bar = 0;
double pen_val = 0;
double prev_valley = 0;
double prev_peak = 0;
double start_mom = 0;
double crt_peak = 0;
double crt_valley = 0;
int tmp = 0;
double prev_mom = 0;
double prev_val = 0;
bool can = false;

/*[[
	Name := GannOvl
	Author := Copyright © 2004, MetaQuotes Software Corp.
	Link := http://www.metaquotes.net/
	Notes := Gann Overlay to find changes in trend
	Separate Window := No
	First Color := Blue
	First Draw Type := Symbol
	First Symbol := 167
	Use Second Data := Yes
]]*/





 //the counters for up/down lines






refbar=Bars-2;
refhi=High[refbar];
reflo=Low[refbar];

//first clea up chart if necessary 


//adding colour to the chart
shift=Bars-3;
slope=0;

up_cnt=0;
dn_cnt=0;

while( shift>=0
  ) {
       tmp=0;
       while( tmp == 0 && shift>=0
       ) {
          tmp=iCustom(NULL, 0, "GannSwingOwn",0,shift);
          shift--;
       } 
               
        if( tmp>0 ) 
           {             
                  if( tmp == High[shift+1] ) 
                     { 
                         prev_valley=crt_valley;
                         crt_peak=tmp;
                     }    
                                          
                  if( tmp == Low[shift+1] ) 
                     { 
                          prev_peak=crt_peak;
                          crt_valley=tmp;
                     } 
           } 
                        
		 can=false;
         //Transition from green             
         if( crt_peak>prev_peak && prev_peak>0 && slope != 1 && prev_mom>0 && shift=prev_peak ) break;
                         SetIndexValue2(pen_bar,pen_val); //bearish                                                                          
                      }   
                     SetIndexValue2(pen_bar,0);
                     pen_bar++;
                   while( pen_bar != shift
                     ) {
                     pen_val=tmp+ (pen_bar-i)*(prev_val-tmp)/(prev_mom-i);
                         SetIndexValue(pen_bar,pen_val); //bearish
                         pen_bar--;                         
                     } 
                      pen_bar++;    
                   //3)
                   // OBJ_TRENDLINE, cnt-9*period*60, close[9], cnt-19*period*60, close[19]);
                  /*  MoveObject("Red"+dn_cnt,OBJ_TRENDLINE,CurTime-prev_mom*period*60,
                              prev_val,CurTime-pen_bar*period*60,pen_val,RED,3,STYLE_SOLID);                   
                    MoveObject("Green"+up_cnt,OBJ_TRENDLINE,CUrTime-pen_bar*period*60,
                               pen_val,CurTime-(shift+1)*period*60,tmp,LIGHTGREEN,3,STYLE_SOLID);                   */
                   //SetIndexValue2(pen_bar,pen_val);
                  up_cnt++;
                  dn_cnt++;                          
            }  else          
         //transition from GREEN to RED
         if( crt_valley0 && slope != 2 && prev_mom>0 ) 
            { 
                  slope=2;
                  pen_bar=prev_mom;
                  pen_val=High[pen_bar];
                  i=shift+1;
                  //1) and 2)
                   while( pen_val>=prev_valley && pen_bar != shift 
                      ) {                        
                         pen_val=tmp+ (pen_bar-i)*(prev_val-tmp)/(prev_mom-i);                         
                        pen_bar--; 
                         if( pen_val=shift;pen_bar--){ 
	 	                   pen_val=tmp+ (pen_bar-i)*(prev_val-tmp)/(prev_mom-i);                         
                            // pen_bar--; 
                             if( pen_val=shift;pen_bar--){ 
	 	                   pen_val=tmp+ (pen_bar-i)*(prev_val-tmp)/(prev_mom-i);                         
                            // pen_bar--; 
                             //if pen_val        

Recommend