Author: yupeng shaw
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
V
ÿþ//+------------------------------------------------------------------+

//|                                                            V.mq4 |

//|                                                Author:yupeng shaw|

//|                                           E-mail:shaw_yp@126.com |

//+------------------------------------------------------------------+

#property copyright   "yupeng shaw"

#property link        "shaw_yp@126.com"

#property description "velocity and accelerated speed"

//--- indicator settings

#property indicator_separate_window

#property indicator_buffers 1

#property indicator_color1  DodgerBlue

#property indicator_label1  "V"

//--- input parameters

input int InpVPeriod=21;  // velocity period

//--- indicator buffers

double    ExtVBuffer[];

//double    ExtABuffer[];

double    ExtSBuffer[];

//--- global variable

int       ExtVPeriod;

//int       ExtAPeriod;

//int       ExtAStart;

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

void OnInit()

  {

//--- check for input value

   if(InpVPeriod<=0)

     {

      ExtVPeriod=22;

      printf("Incorrect input parameter!");

     }

   else

     {

      ExtVPeriod=InpVPeriod;

     } 

//--- 1 additional buffer used for counting.

   IndicatorBuffers(2);

   IndicatorDigits(Digits);

//--- indicator line

   SetIndexStyle(0,DRAW_LINE);

//--- indicator buffers mapping

   SetIndexBuffer(0,ExtVBuffer);

   SetIndexBuffer(1,ExtSBuffer);

//---

   //IndicatorSetInteger(INDICATOR_DIGITS,_Digits);

//--- sets first bar from what index will be drawn

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtVPeriod);

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

   string short_name="V("+string(ExtVPeriod)+")";

   IndicatorSetString(INDICATOR_SHORTNAME,short_name);

   PlotIndexSetString(0,PLOT_LABEL,short_name);

//--- initialization done

  }

//+------------------------------------------------------------------+

//| velocity and accelerated speed                                              |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

   int i,limit_V;

//--- check for bars count

   if(rates_total<=ExtVPeriod)

      return(0); // not enough bars for calculation

//--- counting from 0 to rates_total

   ArraySetAsSeries(ExtVBuffer,false);

   ArraySetAsSeries(ExtSBuffer,false);

   ArraySetAsSeries(close,false);

//--- preliminary calculations

   if(prev_calculated==0)

     {

      limit_V=ExtVPeriod-1;

      //--- filling out the array of True Range values for each period

      for(i=0;i<limit_V && !IsStopped();i++)

         {

          ExtVBuffer[i]=0.0;

          ExtSBuffer[i]=0.0;

         }

      ExtSBuffer[limit_V] = close[limit_V]-close[limit_V-ExtVPeriod+1];

      ExtVBuffer[limit_V] = ExtSBuffer[limit_V]/ExtVPeriod;

      limit_V=ExtVPeriod;

     }

   else

     { 

      limit_V=prev_calculated-1;

     }

//--- the main loop of calculations

   for(i=limit_V;i<rates_total && !IsStopped();i++)

     {

      ExtSBuffer[i]=close[i]-close[i-ExtVPeriod+1];

      ExtVBuffer[i]=ExtSBuffer[i]/ExtVPeriod;

     }

//--- return value of prev_calculated for next call

   return(rates_total);

  }

//+------------------------------------------------------------------+

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