Author: Copyright 2018, MetaQuotes Software Corp.
Price Data Components
0 Views
0 Downloads
0 Favorites
PFE_v1
ÿþ//+------------------------------------------------------------------+

//|                                                          PFE.mq5 |

//|                        Copyright 2018, MetaQuotes Software Corp. |

//|                                                 https://mql5.com |

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

#property copyright "Copyright 2018, MetaQuotes Software Corp."

#property link      "https://mql5.com"

#property version   "1.00"

#property description "Polarized Fractal Efficiency oscillator"

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_plots   1

//--- plot PFE

#property indicator_label1  "PFE"

#property indicator_type1   DRAW_LINE

#property indicator_color1  clrRed

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- input parameters

input uint     InpPeriodFastROC  =  1;    // Fast ROC period

input uint     InpPeriodSlowROC  =  9;    // Slow ROC period

input uint     InpPeriodMA       =  5;    // MA period

input int      InpPDS            =  10;   // PDS

//--- indicator buffers

double         BufferPFE[];

double         BufferRAW[];

//--- global variables

int            period_froc;

int            period_sroc;

int            period_ma;

int            period_max;

int            pds;

//--- includes

#include <MovingAverages.mqh>

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- set global variables

   period_froc=int(InpPeriodFastROC<1 ? 1 : InpPeriodFastROC);

   period_sroc=int(InpPeriodSlowROC<1 ? 1 : InpPeriodSlowROC);

   period_ma=int(InpPeriodMA<2 ? 2 : InpPeriodMA);

   period_max=fmax(period_froc,period_sroc);

   pds=InpPDS;

//--- indicator buffers mapping

   SetIndexBuffer(0,BufferPFE,INDICATOR_DATA);

   SetIndexBuffer(1,BufferRAW,INDICATOR_CALCULATIONS);

//--- setting indicator parameters

   IndicatorSetString(INDICATOR_SHORTNAME,"Polarized Fractal Efficiency ("+(string)period_froc+","+(string)period_sroc+","+(string)period_ma+","+(string)pds+")");

   IndicatorSetInteger(INDICATOR_DIGITS,Digits());

//--- setting buffer arrays as timeseries

   ArraySetAsSeries(BufferPFE,true);

   ArraySetAsSeries(BufferRAW,true);

//---

   return(INIT_SUCCEEDED);

  }

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

//| 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[])

  {

//--- #AB0=>2:0 <0AA82>2 1CD5@>2 :0: B09<A5@89

   ArraySetAsSeries(close,true);

//--- @>25@:0 8 @0AGQB :>;8G5AB20 ?@>AG8BK205<KE 10@>2

   if(rates_total<fmax(period_max,4)) return 0;

//--- @>25@:0 8 @0AGQB :>;8G5AB20 ?@>AG8BK205<KE 10@>2

   int limit=rates_total-prev_calculated;

   if(limit>1)

     {

      limit=rates_total-period_max-1;

      ArrayInitialize(BufferPFE,EMPTY_VALUE);

      ArrayInitialize(BufferRAW,0);

     }

//--- >43>B>2:0 40==KE

   for(int i=limit; i>=0 && !IsStopped(); i--)

     {

      double ROCSlow=(close[i+period_sroc]!=0 ? 100.0*(close[i]/close[i+period_sroc]-1) : 0);

      double ROCFast=(close[i+period_froc]!=0 ? 100.0*(close[i]/close[i+period_froc]-1) : 0);

      double x=sqrt(ROCSlow*ROCSlow+100.0);

      double y=sqrt(ROCFast*ROCFast+1.0)+pds;

      double z=x/(y!=0 ? y : 1);

      BufferRAW[i]=(close[i]>close[i+period_sroc] ? 100.0*z : -100.0*z);

     }

//---  0AGQB 8=48:0B>@0

   if(ExponentialMAOnBuffer(rates_total,prev_calculated,0,period_ma,BufferRAW,BufferPFE)==0)

      return 0;



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