Author: Copyright � 2007, MetaQuotes Software Corp.
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
PVT_MA
//+------------------------------------------------------------------+
//|                                       Price and Volume Trend.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"
//----
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Black
#property indicator_color2 Yellow

//---- input parameters
extern int ExtPVTAppliedPrice = 0;
extern int SignalLine_Period   =  5;
//---- buffers
double ExtPVTBuffer[];
double MA_PVT_Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string sShortName;
//---- indicator buffer mapping
   SetIndexBuffer(0, ExtPVTBuffer);
//---- indicator line
   SetIndexStyle(0, DRAW_LINE);
//---- sets default precision format for indicators visualization
   IndicatorDigits(0);     

//---- indicator buffer mapping
   SetIndexBuffer(1, MA_PVT_Buffer);
//---- indicator line
   SetIndexStyle(1, DRAW_LINE);
//---- sets default precision format for indicators visualization
   IndicatorDigits(1);     
   
//---- name for DataWindow and indicator subwindow label
   sShortName="PVT_MA";
   IndicatorShortName(sShortName);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| On Balance Volume                                                |
//+------------------------------------------------------------------+
int start()
  {
   int    i, nLimit, nCountedBars;
   double dCurrentPrice, dPreviousPrice;
//---- bars count that does not changed after last indicator launch.
   nCountedBars = IndicatorCounted();
//---- last counted bar will be recounted
   if(nCountedBars > 0) 
       nCountedBars--;
   nLimit = Bars - nCountedBars - 1;
//---- 
   for(i = nLimit; i >= 0; i--)
     {
       if(i == Bars - 1)
           ExtPVTBuffer[i] = Volume[i];
       else
         {
           dCurrentPrice = GetAppliedPrice(ExtPVTAppliedPrice, i);
           dPreviousPrice = GetAppliedPrice(ExtPVTAppliedPrice, i + 1);
           ExtPVTBuffer[i] = ExtPVTBuffer[i+1] + Volume[i]*(dCurrentPrice - 
                             dPreviousPrice) / dPreviousPrice;  
         }
     }  
   for(i = nLimit; i >= 0; i--)
      MA_PVT_Buffer[i]=iMAOnArray(ExtPVTBuffer,0,SignalLine_Period,0,0,i);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double GetAppliedPrice(int nAppliedPrice, int nIndex)
  {
   double dPrice;
//----
   switch(nAppliedPrice)
     {
      case 0:  dPrice=Close[nIndex];                                        break;
      case 1:  dPrice=Open[nIndex];                                         break;
      case 2:  dPrice=High[nIndex];                                         break;
      case 3:  dPrice=Low[nIndex];                                          break;
      case 4:  dPrice=(High[nIndex] + Low[nIndex]) / 2.0;                   break;
      case 5:  dPrice=(High[nIndex] + Low[nIndex] + Close[nIndex]) / 3.0;   break;
      case 6:  dPrice=(High[nIndex] + Low[nIndex] + 2*Close[nIndex]) / 4.0; break;
      default: dPrice = 0.0;
     }
//----
   return(dPrice);
  }
//+------------------------------------------------------------------+

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