Author: Copyright � 2010 Festival
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
ZPF
//+------------------------------------------------------------------+
//|                                                          ZPF.mq4 |
//|                                        Copyright © 2010 Festival |
//|                                                         festival |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010 Festival"
#property link      "festival"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red
#property  indicator_width1 2
#property  indicator_width2 2
//---- input parameters
extern int ZPF_Period=12;
//---- buffers
double ExtGreenBuffer[];
double ExtRedBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   string sShortName="ZPF("+ZPF_Period+")";
   IndicatorShortName(sShortName);
   SetIndexLabel(0,sShortName);
//----
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,ExtGreenBuffer);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(1,ExtRedBuffer);
   SetIndexDrawBegin(0,ZPF_Period*2);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int SMA_Fast=ZPF_Period,
   SMA_Slow=ZPF_Period*2,
   limit,SumVolume,c,i,z;
   double SumFastClose,SumSlowClose;
//----
   if(Bars<=SMA_Slow) return(0);

   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   if(counted_bars==0) limit-=1+MathMax(SMA_Slow,SMA_Fast);

//----
   for(c=0; c<(SMA_Fast-1); c++)
     {
      SumVolume+=Volume[c];
      SumFastClose+=Close[c];
     }
//----
   SumSlowClose=SumFastClose;
//----
   for(z=c; z<(SMA_Slow-1); z++)
      SumSlowClose+=Close[z];
//----
   double SumZPF;
//----
   for(i=0; i<limit; i++)
     {
      SumVolume+=Volume[c+i];
      SumFastClose += Close[c+i];
      SumSlowClose += Close[z+i];
      SumZPF=((SumVolume/SMA_Fast) *((SumFastClose/SMA_Fast) -(SumSlowClose/SMA_Slow)))/2;
      ExtGreenBuffer[i]=0+SumZPF;
      ExtRedBuffer[i]=0-SumZPF;
      SumVolume-=Volume[i];
      SumFastClose -= Close[i];
      SumSlowClose -= Close[i];
     }
   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 ---