Stochastic volatility base

Author: © mladen, 2018
0 Views
0 Downloads
0 Favorites
Stochastic volatility base
ÿþ//------------------------------------------------------------------

#property copyright "© mladen, 2018"

#property link      "mladenfx@gmail.com"

#property version   "1.00"

//------------------------------------------------------------------

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_plots   0

//

//---

//

input ENUM_APPLIED_PRICE Price = PRICE_CLOSE;    // Price

//

//--

//

double val[],prices[];

//------------------------------------------------------------------

// Custom indicator initialization function

//------------------------------------------------------------------

int OnInit()

{

   SetIndexBuffer(0,val   ,INDICATOR_CALCULATIONS);

   SetIndexBuffer(1,prices,INDICATOR_CALCULATIONS);

   return(INIT_SUCCEEDED);

}

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=(prev_calculated>0?prev_calculated-1:0); for (; i<rates_total && !_StopFlag; i++)

   {

      prices[i] = getPrice(Price,open,close,high,low,i);

      val[i]    = (i>0) ? (prices[i-1]!=0) ? MathLog(prices[i]/prices[i-1]) : 0 : 0;

   }      

   return(i);

}



//

//---

//



double getPrice(ENUM_APPLIED_PRICE tprice,const double &open[],const double &close[],const double &high[],const double &low[],int i)

{

   switch(tprice)

     {

      case PRICE_CLOSE:     return(close[i]);

      case PRICE_OPEN:      return(open[i]);

      case PRICE_HIGH:      return(high[i]);

      case PRICE_LOW:       return(low[i]);

      case PRICE_MEDIAN:    return((high[i]+low[i])/2.0);

      case PRICE_TYPICAL:   return((high[i]+low[i]+close[i])/3.0);

      case PRICE_WEIGHTED:  return((high[i]+low[i]+close[i]+close[i])/4.0);

     }

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