Derivative_v1

Author: Scriptong
Price Data Components
Series array that contains open prices of each barSeries array that contains close prices for each barSeries array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
Miscellaneous
It issuies visual alerts to the screenImplements a curve of type %1
0 Views
0 Downloads
0 Favorites
Derivative_v1
ÿþ//+------------------------------------------------------------------+

//|                                                      ProjectName |

//|                                      Copyright 2012, CompanyName |

//|                                       http://www.companyname.net |

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

#property copyright "Scriptong"

#property link      "http://advancetools.net"

#property strict



#property indicator_separate_window

#property indicator_level1 0.0

#property indicator_buffers 1

#property indicator_color1 clrDodgerBlue

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

//|                                                                  |

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

enum ENUM_PRICE_TYPE

  {

   PRICE_TYPE_CLOSE,      // Close / 0:@KB85   

   PRICE_TYPE_OPEN,       // Open / B:@KB85   

   PRICE_TYPE_HIGH,       // High / 0:A8<C<

   PRICE_TYPE_LOW,        // Low / 8=8<C<

   PRICE_TYPE_MEDIAN,     // Median / !@54=OO

   PRICE_TYPE_TYPICAL,    // Typical / "8?8G=0O

   PRICE_TYPE_WEIGHTED,   // Weighted close / 725H5==>5 70:@KB85

   PRICE_TYPE_FULL_MEDIAN // Full median / >;=0O A@54=OO

  };

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

input int             i_slowing      = 34;             // Slowing / 0?074K20=85

input ENUM_PRICE_TYPE i_price        = PRICE_TYPE_WEIGHTED; // Applied price / A?>;L7C5<0O F5=0

input int             i_indBarsCount = 10000;          // The number of bars to display / >;8G5AB2> 10@>2 >B>1@065=8O

//--- The indicator's buffers

double            g_indValues[];

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

   if(!IsTuningParametersCorrect())

      return INIT_FAILED;

//---

   if(!BuffersBind())

      return (INIT_FAILED);

//---

   return INIT_SUCCEEDED;

  }

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

//| Checking the correctness of input parameters                     |

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

bool IsTuningParametersCorrect()

  {

   string name=WindowExpertName();

//---

   bool isRussianLang=(TerminalInfoString(TERMINAL_LANGUAGE)=="Russian");

//---

   if(i_slowing<1)

     {

      Alert(name,(isRussianLang)? ": ?5@8>4 70<54;5=8O 4>;65= 1KBL 1>;55 0. =48:0B>@ >B:;NG5=." :

            ": period of slowing must be more than zero. The indicator is turned off.");

      return false;

     }

//---

   return (true);

  }

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

//| Custom indicator deinitialization function                       |

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

void OnDeinit(const int reason)

  {

//---

  }

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

//| Binding of array and the indicator buffers                       |

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

bool BuffersBind()

  {

   string name=WindowExpertName();

//---

   bool isRussianLang=(TerminalInfoString(TERMINAL_LANGUAGE)=="Russian");

//--- Binding the array and indicator buffer

   if(!SetIndexBuffer(0,g_indValues))

     {

      Alert(name,(isRussianLang)? ": >H81:0 A2O7K20=8O <0AA82>2 A 1CD5@0<8 8=48:0B>@0. H81:0 !"+IntegerToString(GetLastError()) :

            ": error of binding of the arrays and the indicator buffers. Error N"+IntegerToString(GetLastError()));

      return false;

     }

//--- Set the type of indicator's buffer

   SetIndexStyle(0,DRAW_LINE);

//---

   return true;

  }

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

//| Initialize of all indicator buffers                              |

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

void BuffersInitializeAll()

  {

   ArrayInitialize(g_indValues,EMPTY_VALUE);

  }

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

//| Determination of bar index which needed to recalculate           |

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

int GetRecalcIndex(int &total,const int ratesTotal,const int prevCalculated)

  {

   total=ratesTotal-i_slowing-2;

//---

   if(i_indBarsCount>0 && i_indBarsCount<total)

      total=MathMin(i_indBarsCount,total);

//---

   if(prevCalculated<ratesTotal-1)

     {

      BuffersInitializeAll();

      return total;

     }

//---

   return (MathMin(ratesTotal - prevCalculated, total));

  }

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

//| Calculation the applied price                                    |

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

double GetPrice(int barIndex)

  {

   double open=iOpen(NULL,0,barIndex);

   double close= iClose(NULL,0,barIndex);

   double high = iHigh(NULL,0,barIndex);

   double low=iLow(NULL,0,barIndex);

//---

   switch(i_price)

     {

      case PRICE_TYPE_CLOSE:           return close;

      case PRICE_TYPE_OPEN:            return open;

      case PRICE_TYPE_HIGH:            return high;

      case PRICE_TYPE_LOW:             return low;

      case PRICE_TYPE_MEDIAN:          return (high + low) / 2;

      case PRICE_TYPE_TYPICAL:         return (high + low + close) / 3;

      case PRICE_TYPE_WEIGHTED:        return (high + low + 2 * close) / 4;

      case PRICE_TYPE_FULL_MEDIAN:     return (high + low + open + close) / 4;

     }

//---

   return 0.0;

  }

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

//| Calculation of indicators values                                 |

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

void CalcIndicatorData(int limit,int total)

  {

   for(int i=limit; i>=0; i--)

      g_indValues[i]=100.0 *(GetPrice(i)-GetPrice(i+i_slowing))/i_slowing;

  }

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

//| Custom indicator iteration function                              |

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

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

   int limit=GetRecalcIndex(total,rates_total,prev_calculated);

//---

   CalcIndicatorData(limit,total);

//---

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