## MA Crossover shown in price Chart

Here you can post and download custom indicators. PLEASE: Do not start topics unless you are posting your own indicator, they will be moved to appropriate section even if you do.

### MA Crossover shown in price Chart

Based on the request.
viewtopic.php?f=27&t=65699
MA Crossover shown in price Chart.lua

Apprentice
FXCodeBase: Confirmed User

Posts: 20393
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

### MA Equilibrium

My implementation.
Will give the price for which, the two moving average will be equalized.
MA Equilibrium.bin

Apprentice
FXCodeBase: Confirmed User

Posts: 20393
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

### Re: MA Crossover shown in price Chart

MA Equilibrium.bin update.

Apprentice
FXCodeBase: Confirmed User

Posts: 20393
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

### Re: MA Crossover shown in price Chart

Thanks for all the hard work.

Apologies, my initial calculations were completely wrong.

The first equilibrium file was very close but I noticed the equilibrium price in the current open bar moved as the price moved which it shouldn't do.

The second Equilibrium bin file gives me results very similar to mine ie prices way too high and low.

The correct formula seems to be:

(Period2*SUM(Period1-1)-Period1*SUM(Period2-1))/(Period1-Period2)

(20*SUM(10-1))-10*SUM(20-1))/(10-20)

Where Sum(Period1-1) ie Sum(10-1) is the sum of the previous 9 closes
and Sum(Period2-1) ie Sum(20-1) is the sum of the previous 19 closes

I can send an excel spreadsheet showing the calculations if you require further information.

Many thanks for all your efforts.
robbieyoung

Posts: 19
Joined: Tue Apr 21, 2015 3:12 am

### Re: MA Crossover shown in price Chart

Hi,

I have looked again at the updated MA Equilibrium bin.

This is very close but I notice the MA Equilibrium price for the latest (Open) bar still varies as the current price varies, it should be fixed.

The attached spreadsheet gives the calculated equilibrium price using the formula given in the last post for H4 EURUSD Prices.

Substituting the equilibrium price for the close price on the same bar does equate the 2 MA's.

I hope this helps,

Thanks again.
Attachments
Equal MA's.xlsb
robbieyoung

Posts: 19
Joined: Tue Apr 21, 2015 3:12 am

### Re: MA Crossover shown in price Chart

Based on / Modified
(Period2*SUM(Period1-1)-Period1*SUM(Period2-1))/(Period1-Period2)

Is calculated as
Price[-1] + (Period2* (Period-1)SUM[-1]-Period1*(Period-2)SUM[-1])/(Period1-Period2)
Modified MA Crossover shown in price Chart.lua

Apprentice
FXCodeBase: Confirmed User

Posts: 20393
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

### Re: MA Crossover shown in price Chart

Many thanks for the update but I get the following error:

C:/Program Files (x86)/Candleworks/FXTS2/Indicators/Custon/Modified MA Crossover shown in price Chart.lua:65: attempt to concatenate upvalue 'Method2' (a nil value)

Sorry to be a pain but this indicator will really help me.

Thanks again.
robbieyoung

Posts: 19
Joined: Tue Apr 21, 2015 3:12 am

### Re: MA Crossover shown in price Chart

I managed to get the code to work by removing Method1 & Method2 from the name as they were returning nul.

The calculations are working perfectly but the results and the plotted line seems to be shifted 1 period to the right.

I tried changing the calculation to:

Line[period-1]=source[period-1]+(Period2*Sum1-Period1*Sum2)/(Period1-Period2);

This shifts the results back 1 period but then there is no value showing the MA equilibrium price in the current open bar.

Ill try some other things to fix it but your help would be greatly appreciated (again!)

Thanks
robbieyoung

Posts: 19
Joined: Tue Apr 21, 2015 3:12 am

### Re: MA Crossover shown in price Chart

I changed the code to:

local name = profile:id() .. "(" .. instance.source:name() .. ", " .. Period1 .. ", " .. Period2 .. ")";

and:

local Sum1=mathex.sum(source, period-Period1+1, period);
local Sum2=mathex.sum(source, period-Period2+1, period);
Line[period]=source[period]+(Period2*Sum1-Period1*Sum2)/(Period1-Period2);

and this seems to have done shifted the graph back 1 period and also provides a calculation for the final open bar.

I cannot thank you enough for all your work in creating this indicator.

It will be a massive help to me monitoring for potential upcoming trades.
robbieyoung

Posts: 19
Joined: Tue Apr 21, 2015 3:12 am

### Re: MA Crossover shown in price Chart

Fixed.

Apprentice
FXCodeBase: Confirmed User

Posts: 20393
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia