Moving Averages and repainting  [SOLVED]

Questions about MultiCharts and user contributed studies.
Seed83
Posts: 5
Joined: 29 Jan 2015
Has thanked: 2 times

Moving Averages and repainting

Postby Seed83 » 14 Apr 2015

broker feed: Oanda

I take the pre-built indicator Moving Average 1 line and put it in the chart. It obviously doesn’t repaint.

Code: Select all

inputs: Price( Close ), Length( 9 ), Displace( 0 ) ;
variables: var0( 0 ) ;

var0 = AverageFC( Price, Length ) ;

condition1 = Displace >= 0 or CurrentBar > AbsValue( Displace ) ;
if condition1 then
begin
Plot1[Displace]( var0, "Avg" ) ;


if Displace <= 0 then
begin
condition1 = Price crosses over var0 ;
if condition1 then
Alert( "Price crossing over average" )
else
begin
condition1 = Price crosses under var0 ;
if condition1 then
Alert( "Price crossing under average" ) ;
end ;
end;
end ;
Now I want to test another type of moving average in the indicator. I copy all the code and create a new indicator PersonalMA with the same identical code apart from a line:

var0 = WAverage( Price, Length ) ;

in place of

var0 = AverageFC( Price, Length ) ;

Code: Select all

inputs: Price( Close ), Length( 9 ), Displace( 0 ) ;
variables: var0( 0 ) ;

var0 = WAverage( Price, Length ) ;

[code]condition1 = Displace >= 0 or CurrentBar > AbsValue( Displace ) ;
if condition1 then
begin
Plot1[Displace]( var0, "Avg" ) ;


if Displace <= 0 then
begin
condition1 = Price crosses over var0 ;
if condition1 then
Alert( "Price crossing over average" )
else
begin
condition1 = Price crosses under var0 ;
if condition1 then
Alert( "Price crossing under average" ) ;
end ;
end;
end ;
Now the indicator repaints (that is it changes if you scroll backwards the chart). I have tested other built-in moving average functions...the result is the same. I'm not a mathematician but it sounds strange to me. Now the final test. I wrote the original line

var0 = AverageFC( Price, Length )

in my PersonalMa indicator so now the two indicators are identical. I inserted even the same period lenght. Result: My indicator repaints, the original not!! I don't know what is the problem.

User avatar
TJ
Posts: 7743
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Moving Averages and repainting

Postby TJ » 15 Apr 2015

I have tried your code,
I do not see any so called "repainting".

Can you make a few screenshots to illustrate your observation?

Seed83
Posts: 5
Joined: 29 Jan 2015
Has thanked: 2 times

Re: Moving Averages and repainting

Postby Seed83 » 15 Apr 2015

I have tried your code,
I do not see any so called "repainting".

Can you make a few screenshots to illustrate your observation?
HI,

built-in Mov Avg 1 line indicator is cyan
Personal_Ma (same code but with Waverage in place of Average) is red
Attachments
multichartsbug2.png
(91.67 KiB) Downloaded 454 times
multichartsbug1.png
(84.39 KiB) Downloaded 458 times

User avatar
TJ
Posts: 7743
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Moving Averages and repainting

Postby TJ » 15 Apr 2015

I have tried your code,
I do not see any so called "repainting".
Can you make a few screenshots to illustrate your observation?
HI,
built-in Mov Avg 1 line indicator is cyan
Personal_Ma (same code but with Waverage in place of Average) is red
Go to Format Study,

under Scale tab,

select "Same as instrument".

Seed83
Posts: 5
Joined: 29 Jan 2015
Has thanked: 2 times

Re: Moving Averages and repainting  [SOLVED]

Postby Seed83 » 15 Apr 2015

I have tried your code,
I do not see any so called "repainting".
Can you make a few screenshots to illustrate your observation?
HI,
built-in Mov Avg 1 line indicator is cyan
Personal_Ma (same code but with Waverage in place of Average) is red
Go to Format Study,

under Scale tab,

select "Same as instrument".
Thank you, following your instructions (I don't why) now it works correctly!!!


Return to “MultiCharts”