CCI_Trigger

CCI_Trigger
Indicators Used
Commodity channel indexMoving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
CCI_Trigger
//+------------------------------------------------------------------+
//|                                                       CCITrigger |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2007, GideonSmolders(at)gmail.com."
#property  link      ""
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 6
#property  indicator_color1  LightBlue
#property  indicator_color2  Blue
#property  indicator_color3  LightPink
#property  indicator_color4  Pink
#property  indicator_color5  Yellow
#property  indicator_color6  Green

extern double CCIPeriod= 3;
extern double MainPeriod = 21;
extern double TriggerPeriod = 5;
//MODE_SMA  0 Simple moving average, 
//MODE_EMA  1 Exponential moving average,
//MODE_SMMA 2 Smoothed moving average, 
//MODE_LWMA 3 Linear weighted moving average. 
extern double TriggerMode = MODE_LWMA;   
extern double MainMode = MODE_SMMA;

//---- indicator buffers

string signal;
double cci_open[];
double cci_close[];
double cci_openma[];
double cci_closema[];
double TriggerCCI[];
double MainCCI[];



//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 2 additional buffers are used for counting.
   IndicatorBuffers(6);
   
//---- drawing settings
   SetIndexStyle(0,DRAW_NONE,STYLE_SOLID,1);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
   SetIndexStyle(2,DRAW_NONE,STYLE_SOLID,1);
   SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,1);
   SetIndexStyle(4,DRAW_LINE,STYLE_SOLID,1);
   SetIndexStyle(5,DRAW_LINE,STYLE_SOLID,1);
   
   SetIndexBuffer(0,cci_open);
   SetIndexLabel(0,"CCIopen");
   SetIndexBuffer(1,cci_close);
   SetIndexLabel(1,"CCIclose");
   SetIndexBuffer(2,cci_openma);
   SetIndexLabel(2,"CCIopenMA");
   SetIndexBuffer(3,cci_closema);
   SetIndexLabel(3,"CCIcloseMA");
   SetIndexBuffer(4,TriggerCCI);
   SetIndexLabel(4,"Trigger CCI");
   SetIndexBuffer(5,MainCCI);
   SetIndexLabel(5,"Main Line");

   

      
//---- name for DataWindow and indicator subwindow label

   
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Calculations                                    |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int i;
   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;
   
//---- main loop
   
//---- done
   for(i=0; i <= Bars; i++) 
   {
   cci_open[i]=iCCI(Symbol(),0,CCIPeriod,PRICE_OPEN,i);
   }
   for(i=0; i <= Bars; i++) 
   { 
   cci_close[i] = iCCI(Symbol(),0,CCIPeriod,PRICE_CLOSE,i);
   }
   for(i=0; i <= Bars; i++) 
   {
   cci_openma[i]=(   iCCI(Symbol(),0,CCIPeriod,PRICE_OPEN,i)+
                  iCCI(Symbol(),0,CCIPeriod,PRICE_CLOSE,i+1)
                )/2;
   }
   for(i=0; i <= Bars; i++) 
   { 
   cci_closema[i] = (   iCCI(Symbol(),0,CCIPeriod,PRICE_OPEN,i)+
                  iCCI(Symbol(),0,CCIPeriod,PRICE_CLOSE,i+1)
                )/2;
   }
   for(i=0; i <= Bars; i++) 
   {   
   TriggerCCI[i]= iMAOnArray(cci_closema,0,TriggerPeriod,0,TriggerMode,i);
   }
   for(i=0; i <= Bars; i++) 
   {
   MainCCI[i]= iMAOnArray(cci_openma,0,MainPeriod,0,MainMode,i+1);
   }

   
   for(i=0; i<=Bars; i++)
   {
      if(MainCCI[i]>cci_openma[i] && MainCCI[i]>cci_close[i] && cci_close[i]<cci_close[i+1]
         && cci_close[i]<cci_open[i] && TriggerCCI[i]<TriggerCCI[i+1])
      signal = "SELL";
      else if (MainCCI[i]<cci_openma[i] && MainCCI[i]<cci_close[i] && cci_close[i]<cci_close[i+1]
               && cci_close[i]>cci_open[i] && TriggerCCI[i]>TriggerCCI[i+1])
      signal = "BUY";
      else
      signal = "NEUTRAL";
 
    IndicatorShortName("CCI: "+signal);
   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 ---