Calcul de la période des cycles selon Ehlers
Forums › ProRealTime forum Français › Support ProBuilder › Calcul de la période des cycles selon Ehlers
- This topic has 5 replies, 2 voices, and was last updated 8 years ago by zilliq.
Viewing 6 posts - 1 through 6 (of 6 total)
-
-
05/11/2016 at 11:04 AM #6787
Bonjour à tous,
Je cherche à coder cet indicateur d’Ehlers qui détermine la péridoe du cycle dominant.
Je bute sur la conversion de ce code MT5 en PRT car MT5 n’est vraiment pas ma tasse de thé
Alors si quelqu’un a plus de facilité pour faire la conversion
Merci d’avance
Zilliq
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164<span class="comment">//+------------------------------------------------------------------+</span><span class="comment">//| CyclePeriod.mq5 |</span><span class="comment">//| Copyright 2011, Investeo.pl |</span><span class="comment">//| http://Investeo.pl |</span><span class="comment">//+------------------------------------------------------------------+</span><span class="preprocessor">#property copyright <span class="string">"Copyright 2011, Investeo.pl"</span></span><span class="preprocessor">#property link <span class="string">"http://Investeo.pl"</span></span><span class="preprocessor">#property version <span class="string">"1.00"</span></span><span class="preprocessor">#property indicator_separate_window</span><span class="preprocessor">#property description <span class="string">"CyclePeriod indicator - described by John F. Ehlers"</span></span><span class="preprocessor">#property description <span class="string">"in \"Cybernetic Analysis for Stocks and Futures\""</span></span><span class="preprocessor">#property indicator_buffers <span class="number">2</span></span><span class="preprocessor">#property indicator_plots <span class="number">2</span></span><span class="preprocessor">#property indicator_width1 <span class="number">1</span></span><span class="preprocessor">#property indicator_width2 <span class="number">1</span></span><span class="preprocessor">#property indicator_type1 DRAW_LINE</span><span class="preprocessor">#property indicator_type2 DRAW_LINE</span><span class="preprocessor">#property indicator_color1 Green</span><span class="preprocessor">#property indicator_color2 Red</span><span class="preprocessor">#property indicator_label1 <span class="string">"Cycle"</span></span><span class="preprocessor">#property indicator_label2 <span class="string">"Trigger Line"</span></span><span class="preprocessor">#define Price(i) ((high[i]+low[i])/<span class="number">2.0</span>)</span><span class="keyword">double</span> Smooth[];<span class="keyword">double</span> Cycle[];<span class="keyword">double</span> Trigger[];<span class="comment">//double Price[];</span><span class="keyword">double</span> Q1[]; <span class="comment">// Quadrature component</span><span class="keyword">double</span> I1[]; <span class="comment">// InPhase component</span><span class="keyword">double</span> DeltaPhase[];<span class="keyword">double</span> InstPeriod[];<span class="keyword">double</span> CyclePeriod[];<span class="keyword">input</span> <span class="keyword">double</span> InpAlpha=<span class="number">0.07</span>; <span class="comment">// alpha</span><span class="comment">//+------------------------------------------------------------------+</span><span class="comment">//| Custom indicator initialization function |</span><span class="comment">//+------------------------------------------------------------------+</span><span class="keyword">int</span> <span class="functions">OnInit</span>(){<span class="comment">//--- indicator buffers mapping </span><span class="functions">ArraySetAsSeries</span>(Cycle,<span class="keyword">true</span>);<span class="functions">ArraySetAsSeries</span>(CyclePeriod,<span class="keyword">true</span>);<span class="functions">ArraySetAsSeries</span>(Trigger,<span class="keyword">true</span>);<span class="functions">ArraySetAsSeries</span>(Smooth,<span class="keyword">true</span>);<span class="comment">//ArraySetAsSeries(Price,true);</span><span class="functions">SetIndexBuffer</span>(<span class="number">0</span>,CyclePeriod,<span class="keyword">INDICATOR_DATA</span>);<span class="functions">SetIndexBuffer</span>(<span class="number">1</span>,Trigger,<span class="keyword">INDICATOR_DATA</span>);<span class="functions">PlotIndexSetDouble</span>(<span class="number">0</span>,<span class="keyword">PLOT_EMPTY_VALUE</span>,<span class="number">0.0</span>);<span class="functions">PlotIndexSetDouble</span>(<span class="number">1</span>,<span class="keyword">PLOT_EMPTY_VALUE</span>,<span class="number">0.0</span>);<span class="keyword">return</span>(<span class="number">0</span>);}<span class="comment">//+------------------------------------------------------------------+</span><span class="comment">//| Custom indicator iteration function |</span><span class="comment">//+------------------------------------------------------------------+</span><span class="keyword">int</span> <span class="functions">OnCalculate</span>(<span class="keyword">const</span> <span class="keyword">int</span> rates_total,<span class="keyword">const</span> <span class="keyword">int</span> prev_calculated,<span class="keyword">const</span> <span class="keyword">datetime</span> &time[],<span class="keyword">const</span> <span class="keyword">double</span> &open[],<span class="keyword">const</span> <span class="keyword">double</span> &high[],<span class="keyword">const</span> <span class="keyword">double</span> &low[],<span class="keyword">const</span> <span class="keyword">double</span> &close[],<span class="keyword">const</span> <span class="keyword">long</span> &tick_volume[],<span class="keyword">const</span> <span class="keyword">long</span> &volume[],<span class="keyword">const</span> <span class="keyword">int</span> &spread[]){<span class="comment">//--- </span><span class="keyword">long</span> tickCnt[<span class="number">1</span>];<span class="keyword">int</span> i;<span class="keyword">int</span> ticks=<span class="functions">CopyTickVolume</span>(<span class="functions">Symbol</span>(), <span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>, tickCnt);<span class="keyword">if</span>(ticks!=<span class="number">1</span>) <span class="keyword">return</span>(rates_total);<span class="keyword">double</span> DC, MedianDelta;<span class="functions">Comment</span>(tickCnt[<span class="number">0</span>]);<span class="keyword">if</span>(prev_calculated==<span class="number">0</span> || tickCnt[<span class="number">0</span>]==<span class="number">1</span>){<span class="comment">//--- last counted bar will be recounted</span><span class="keyword">int</span> nLimit=rates_total-prev_calculated-<span class="number">1</span>; <span class="comment">// start index for calculations</span><span class="functions">ArraySetAsSeries</span>(high,<span class="keyword">true</span>);<span class="functions">ArraySetAsSeries</span>(low,<span class="keyword">true</span>);<span class="functions">ArrayResize</span>(Smooth,<span class="functions">Bars</span>(<span class="predefines">_Symbol</span>,<span class="predefines">_Period</span>));<span class="functions">ArrayResize</span>(Cycle,<span class="functions">Bars</span>(<span class="predefines">_Symbol</span>,<span class="predefines">_Period</span>));<span class="comment">//ArrayResize(Price,Bars(_Symbol,_Period));</span><span class="functions">ArrayResize</span>(CyclePeriod,<span class="functions">Bars</span>(<span class="predefines">_Symbol</span>,<span class="predefines">_Period</span>));<span class="functions">ArrayResize</span>(InstPeriod,<span class="functions">Bars</span>(<span class="predefines">_Symbol</span>,<span class="predefines">_Period</span>));<span class="functions">ArrayResize</span>(Q1,<span class="functions">Bars</span>(<span class="predefines">_Symbol</span>,<span class="predefines">_Period</span>));<span class="functions">ArrayResize</span>(I1,<span class="functions">Bars</span>(<span class="predefines">_Symbol</span>,<span class="predefines">_Period</span>));<span class="functions">ArrayResize</span>(DeltaPhase,<span class="functions">Bars</span>(<span class="predefines">_Symbol</span>,<span class="predefines">_Period</span>));<span class="keyword">if</span> (nLimit>rates_total-<span class="number">7</span>) <span class="comment">// adjust for last bars</span>nLimit=rates_total-<span class="number">7</span>;<span class="keyword">for</span>(i=nLimit;i>=<span class="number">0</span> && !<span class="functions">IsStopped</span>();i--){Smooth[i] = (Price(i)+<span class="number">2</span>*Price(i+<span class="number">1</span>)+<span class="number">2</span>*Price(i+<span class="number">2</span>)+Price(i+<span class="number">3</span>))/<span class="number">6.0</span>;<span class="keyword">if</span> (i<rates_total-<span class="number">7</span>){Cycle[i] = (<span class="number">1.0</span>-<span class="number">0.5</span>*InpAlpha) * (<span class="number">1.0</span>-<span class="number">0.5</span>*InpAlpha) * (Smooth[i]-<span class="number">2.0</span>*Smooth[i+<span class="number">1</span>]+Smooth[i+<span class="number">2</span>])+<span class="number">2.0</span>*(<span class="number">1.0</span>-InpAlpha)*Cycle[i+<span class="number">1</span>]-(<span class="number">1.0</span>-InpAlpha)*(<span class="number">1.0</span>-InpAlpha)*Cycle[i+<span class="number">2</span>];} <span class="keyword">else</span>{Cycle[i]=(Price(i)-<span class="number">2.0</span>*Price(i+<span class="number">1</span>)+Price(i+<span class="number">2</span>))/<span class="number">4.0</span>;}Q1[i] = (<span class="number">0.0962</span>*Cycle[i]+<span class="number">0.5769</span>*Cycle[i+<span class="number">2</span>]-<span class="number">0.5769</span>*Cycle[i+<span class="number">4</span>]-<span class="number">0.0962</span>*Cycle[i+<span class="number">6</span>])*(<span class="number">0.5</span>+<span class="number">0.08</span>*InstPeriod[i+<span class="number">1</span>]);I1[i] = Cycle[i+<span class="number">3</span>];<span class="keyword">if</span> (Q1[i]!=<span class="number">0.0</span> && Q1[i+<span class="number">1</span>]!=<span class="number">0.0</span>)DeltaPhase[i] = (I1[i]/Q1[i]-I1[i+<span class="number">1</span>]/Q1[i+<span class="number">1</span>])/(<span class="number">1.0</span>+I1[i]*I1[i+<span class="number">1</span>]/(Q1[i]*Q1[i+<span class="number">1</span>]));<span class="keyword">if</span> (DeltaPhase[i] < <span class="number">0.1</span>)DeltaPhase[i] = <span class="number">0.1</span>;<span class="keyword">if</span> (DeltaPhase[i] > <span class="number">0.9</span>)DeltaPhase[i] = <span class="number">0.9</span>;MedianDelta = Median(DeltaPhase, i, <span class="number">5</span>);<span class="keyword">if</span> (MedianDelta == <span class="number">0.0</span>)DC = <span class="number">15.0</span>;<span class="keyword">else</span>DC = (<span class="number">6.28318</span>/MedianDelta) + <span class="number">0.5</span>;InstPeriod[i] = <span class="number">0.33</span> * DC + <span class="number">0.67</span> * InstPeriod[i+<span class="number">1</span>];CyclePeriod[i] = <span class="number">0.15</span> * InstPeriod[i] + <span class="number">0.85</span> * CyclePeriod[i+<span class="number">1</span>];Trigger[i] = CyclePeriod[i+<span class="number">1</span>];}}<span class="comment">//--- return value of prev_calculated for next call</span><span class="keyword">return</span>(rates_total);}<span class="comment">//+------------------------------------------------------------------+</span><span class="keyword">double</span> Median(<span class="keyword">double</span>& arr[], <span class="keyword">int</span> idx, <span class="keyword">int</span> m_len){<span class="keyword">double</span> MedianArr[];<span class="keyword">int</span> copied;<span class="keyword">double</span> result = <span class="number">0.0</span>;<span class="functions">ArraySetAsSeries</span>(MedianArr, <span class="keyword">true</span>);<span class="functions">ArrayResize</span>(MedianArr, m_len);copied = <span class="functions">ArrayCopy</span>(MedianArr, arr, <span class="number">0</span>, idx, m_len);<span class="keyword">if</span> (copied == m_len){<span class="functions">ArraySort</span>(MedianArr);<span class="keyword">if</span> (m_len %<span class="number">2</span> == <span class="number">0</span>)result = (MedianArr[m_len/<span class="number">2</span>] + MedianArr[(m_len/<span class="number">2</span>)+<span class="number">1</span>])/<span class="number">2.0</span>;<span class="keyword">else</span>result = MedianArr[m_len / <span class="number">2</span>];}<span class="keyword">else</span> <span class="functions">Print</span>(<span class="macro">__FILE__</span>+<span class="macro">__FUNCTION__</span>+<span class="string">"median error - wrong number of elements copied."</span>);<span class="keyword">return</span> result;}05/11/2016 at 1:36 PM #6802J’ai recodé l’indicateur pour PRT, mais je ne suis pas certain pour le calcul de la fonction Median.
Regarde ce que ça donne:
12345678910111213141516171819202122232425262728293031323334353637383940414243Price = medianpriceInpAlpha=0.07once MedianDelta = 0if barindex>20 thenSmooth = (Price[2]*Price[1]+2*Price[2]+Price[3])/6.0if barindex<27 thenCycleP = (1-0.5*InpAlpha) * (1-0.5*InpAlpha) * (Smooth-2.0*Smooth[1]+Smooth[2])+2.0*(1.0*InpAlpha)*CycleP[1]-(1.0-InpAlpha)*(1.0-InpAlpha)*CycleP[2]elseCycleP = (Price-2.0*Price[1]+Price[2])/4.0endifQ1 = (0.0962*CycleP+0.5769*CycleP[2]-0.5769*CycleP[4]-0.0962*CycleP[6])*(0.5+0.08*InstPeriod[1])I1 = CycleP[3]if Q1<>0 AND Q1[1]<>0 thenDeltaPhase = (I1/Q1-I1[1]/Q1[1])/(1.0+I1*I1[1]/(Q1*Q1[1]))elsif DeltaPhase<0.1 thenDeltaPhase = 0.1elsif DeltaPhase>0.9 thenDeltaPhase = 0.9endifarray = 0for i = 0 to 5 doarray = array + DeltaPhase[i]nextMedianDelta = array/2if MedianDelta = 0 thenDC=15elseDC=(6.28318/MedianDelta) + 0.5endifInstPeriod = 0.33*DC+0.67*InstPeriodCyclePeriod = 0.15*InstPeriod+0.85*CyclePeriod[1]endifRETURN CyclePeriod,CyclePeriod[1]05/25/2016 at 9:57 AM #795605/25/2016 at 9:34 PM #803505/25/2016 at 9:40 PM #803705/25/2016 at 9:42 PM #8040Voici le code MT4, peut être plus “simple”
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114//+------------------------------------------------------------------+//| CyclePeriod.mq4 |//| |//| Cycle Period |//| |//| Algorithm taken from book |//| "Cybernetics Analysis for Stock and Futures" |//| by John F. Ehlers |//| |//| contact@mqlsoft.com |//| http://www.mqlsoft.com/ |//+------------------------------------------------------------------+#property copyright "Coded by Witold Wozniak (www.mqlsoft.com)"#property link "http://www.mqlsoft.com"#property version "2.0"#property description "The algorithm was taken from the book "#property description "\"Cybernetics Analysis for Stock and Futures\" "#property description "by John F. Ehlers"#property strict#property indicator_separate_window#property indicator_buffers 1#property indicator_color1 clrRed#property indicator_minimum 0double DeltaPhase[];double CPeriod[];double Smooth[];double Cycle[];double Q1[];double I1[];double InstPeriod[];input double Alpha = 0.07;int buffers = 0;int drawBegin = 8;int median = 5;int init() {IndicatorBuffers(7);initBuffer(CPeriod, "Cycle Period", DRAW_LINE);initBuffer(Smooth);initBuffer(Cycle);initBuffer(Q1);initBuffer(I1);initBuffer(DeltaPhase);initBuffer(InstPeriod);IndicatorShortName("Cycle Period [" + DoubleToStr(Alpha, 2) + "]");return (0);}int start() {if (Bars <= drawBegin) return (0);int countedBars = IndicatorCounted();if (countedBars < 0) return (-1);if (countedBars > 0) countedBars--;int s, limit = MathMin(Bars - countedBars - 1, Bars - drawBegin);for (s = limit; s >= 0; s--) {Smooth[s] = (P(s) + 2.0 * P(s + 1) + 2.0 * P(s + 2) + P(s + 3)) / 6.0;Cycle[s] = (1.0 - 0.5 * Alpha) * (1.0 - 0.5 * Alpha) * (Smooth[s] - 2 * Smooth[s + 1] + Smooth[s + 2])+ 2.0 * (1.0 - Alpha) * Cycle[s + 1]- (1.0 - Alpha) * (1.0 - Alpha) * Cycle[s + 2];if (s > Bars - 8) {Cycle[s] = (P(s) - 2.0 * P(s + 1) + P(s + 2)) / 4.0;}Q1[s] = (0.0962 * Cycle[s] + 0.5769 * Cycle[s + 2] - 0.5769 * Cycle[s + 4] - 0.0962 * Cycle[s + 6])* (0.5 + 0.08 * InstPeriod[s + 1]);I1[s] = Cycle[s + 3];if (Q1[s] != 0.0 && Q1[s + 1] != 0.0) {DeltaPhase[s] = (I1[s] / Q1[s] - I1[s + 1] / Q1[s + 1])/ (1.0 + I1[s] * I1[s + 1] / (Q1[s] * Q1[s + 1]));}DeltaPhase[s] = MathMax(0.1, DeltaPhase[s]);DeltaPhase[s] = MathMin(1.1, DeltaPhase[s]);double MedianDelta, DC;double M[];ArrayResize(M, median);ArrayCopy(M, DeltaPhase, 0, s, median);ArraySort(M);if (median % 2 == 0) {MedianDelta = (M[median / 2] + M[(median / 2) + 1]) / 2.0;} else {MedianDelta = M[median / 2];}if (MedianDelta == 0.0) {DC = 15.0;} else {DC = 6.28318 / MedianDelta + 0.5;}InstPeriod[s] = 0.33 * DC + 0.67 * InstPeriod[s + 1];CPeriod[s] = 0.15 * InstPeriod[s] + 0.85 * CPeriod[s + 1];}return (0);}double P(int index) {if (index >= Bars) {return ((High[Bars - 1] + Low[Bars - 1]) / 2.0);}return ((High[index] + Low[index]) / 2.0);}void initBuffer(double& array[], string label = "", int type = DRAW_NONE, int arrow = 0, int style = EMPTY, int width = EMPTY, color clr = CLR_NONE) {SetIndexBuffer(buffers, array);SetIndexLabel(buffers, label);SetIndexEmptyValue(buffers, 0);SetIndexDrawBegin(buffers, drawBegin);SetIndexShift(buffers, 0);SetIndexStyle(buffers, type, style, width);SetIndexArrow(buffers, arrow);buffers++;} -
AuthorPosts
Viewing 6 posts - 1 through 6 (of 6 total)
Find exclusive trading pro-tools on
Similar topics: