Source: https://fxcodebase.com/code/viewtopic.php?f=17&t=65706
Forum: 17 · Topic 65706 · 10 post(s)
Apprentice · Tue Feb 06, 2018 4:52 pm

Based on the request. viewtopic.php?f=27&t=65699
MA Crossover shown in price Chart.lua
Apprentice · Tue Feb 06, 2018 5:15 pm

My implementation. Will give the price for which, the two moving average will be equalized.
Apprentice · Tue Feb 06, 2018 6:00 pm
MA Equilibrium.bin update. Please re-download.
robbieyoung · Tue Feb 06, 2018 7:37 pm
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:
(Period2SUM(Period1-1)-Period1SUM(Period2-1))/(Period1-Period2)
(20SUM(10-1))-10SUM(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 · Wed Feb 07, 2018 7:23 am
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.
Apprentice · Thu Feb 08, 2018 6:29 am
Based on / Modified (Period2SUM(Period1-1)-Period1SUM(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
robbieyoung · Thu Feb 08, 2018 10:24 am
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 · Thu Feb 08, 2018 12:18 pm
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]+(Period2Sum1-Period1Sum2)/(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 · Thu Feb 08, 2018 12:49 pm
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]+(Period2Sum1-Period1Sum2)/(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.
Apprentice · Fri Feb 09, 2018 6:17 am
Fixed.