[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 202

 
hoz:


For starters, get used to putting brackets where you need them. Like this:

There may not be a tick in this second or even a minute, so better without seconds and Minute() < 5 and limit opening: if(OrdersTotal< 1) or as many as needed!
 

I'm looking at the code of the standard Moving Average indicator.

I got to the function:

//+------------------------------------------------------------------+
//| Exponential Moving Average                                       |
//+------------------------------------------------------------------+
void ema()
  {
   double pr=2.0/(MA_Period+1);
   int    pos=Bars-2;
   if(ExtCountedBars>2) pos=Bars-ExtCountedBars-1;
//---- main calculation loop
   while(pos>=0)
     {
      if(pos==Bars-2) ExtMapBuffer[pos+1]=Close[pos+1];
      ExtMapBuffer[pos]=Close[pos]*pr+ExtMapBuffer[pos+1]*(1-pr);
           pos--;
     }
  }

The variable pr is just a coefficient taken out of the box? Why 2.0 /(MA_Period+1)?

Further I see that it's only activated if I've uncalculated 2 bars... where's the logic again?

And here:

ExtMapBuffer[pos]=Close[pos]*pr+ExtMapBuffer[pos+1]*(1-pr);

Sum of the value of the last 2 closing prices, multiplied by coefficients. Why so? What is the logic here? The last price was dominated by pr and the penultimate price by (1-pr).

What does it give? I want to understand the principle of how the machine works thoroughly,

 
hoz:

I'm looking at the code of the standard Moving Average indicator.

I got to the function:

The variable pr is just a coefficient taken out of the box? Why 2.0 /(MA_Period+1)?

Further I see that it's only executed if I haven't calculated 2 bars... where's the logic in this situation again?

And here:

Sum of the value of the last 2 closing prices, multiplied by coefficients. Why so? What is the logic here? The last price was dominated by pr and the penultimate price by (1-pr).

What does it give? I want to understand the principle of how the machine works thoroughly,

Victor, experiment by substituting a numerical value for pr. Say, if MA period = 19, then 2.0 /(MA_Period+1) = 0.1, and(1-pr) = 0.9. From here, do the math!
 
borilunad:
Victor, experiment by substituting a numerical value for pr. Say, if the MA period = 19, then 2.0 /(MA_Period+1) = 0.1, and(1-pr) = 0.9. From here you can do the math!

Boris, I even drew a couple of buffers on a sheet of paper. Something comes out strange. But I noticed that in this way mashki is pressed to the past. I.e. it has a lower value if the current closing price. This is if prices are rising all the time. If it is the other way round, it moves faster in the other direction. This is the logic behind it.
 
hoz:

Boris, I've even written a couple of buffers on a piece of paper. Something comes out strange. But I have noticed that in this way the swabs are pinned to the past. I.e. it has a lower value if the current closing price. This is if prices are rising all the time. If it is the other way round, it moves faster in the other direction. This is the logic.

The sum of the value of the last 2 closing prices.... is incorrect - the cloze is added to the average value
 
YOUNGA:

The sum of the value of the last 2 closing prices.... is incorrect - cloze is added to the average value
it is normal to find on the internet exponential smoothing - description
 
YOUNGA:

The sum of the value of the last 2 closing prices.... is wrong - the cloze
is added to the average value.


Yes, that's what I meant. But exactly the distribution ofpr between the last values i.e. the last closing price and the average value i.e. the last received buffer is not quite clear.

 
YOUNGA:


Let me explain if you open one lot on each EURJPY and USDJPY pair then EURUSD lot should be 1 point change in the price of EURUSD something must happen with the synthetic EURJPY/USDJPY since they are correlated


That's the point, one lot for EURJPY and USDJPY are not equal positions. That's why their situation will be the following (I think they opened in different directions, don't you?): 100 000 EUR - 100 000 USD = 100 000 USD * (EUR/USD -1). That is, the result of the trade, expressed in dollars, will be directly proportional to the EURUSD exchange rate minus 1.
 
YOUNGA:
and in general it's OK to find exponential anti-aliasing on the web - description

By the way, yes. Thanks for the tip :) I've been a real pain in the ass lately. I'm reading the description of "exponential smoothing" and I'm starting to realise...
 
hoz:

What does it do? I want to understand the principle of building the waving machine thoroughly,


The way it works is as follows (we transform the recursive equation into an explicit one):

EMA (i) = C (i)*pr + EMA (i+1)*(1-pr) = C (i)*pr + (1-pr)* (C (i+1)*pr + EMA (i+2)*(1-pr)) = C (i)*pr + C (i+1)*pr* (1-pr) + EMA (i+2)*(1-pr)^2 = C (i)*pr + C (i+1)*pr* (1-pr) + (C (i+2)*pr + EMA (i+3)*(1-pr))*(1-pr)^2

= C (i)*pr + C (i+1)*pr* (1-pr) + C (i+2)*pr*(1-pr)^2 + EMA (i+3)* (1-pr)^3 = ... repeat, repeat... = Sum {k = from i to infinity; C(k)*pr* (1-pr)^ (k-1)}

In other words, it is a series whose coefficients are a geometric progression with denominator (1-pr)<1, that is, a decreasing one. We know from school algebra that such a progression is a decreasing exponent. That is where the name MA comes from.

Why did they take this formula? Without going into details, I can say that this formula will give us the same average group delay of an input quote at the output of the MA as the SMA with the same period. In other words, EMA and SMA with the same period parameter give approximately the same delay. (But only approximately! - SMA is a linear-phase filter, EMA is not)