Reply

LWMA indicator is different from MC

1 replies

binhsir

Subscriber, bbp_participant, customer, community, sq-ultimate, 17 replies.

Visit profile

2 years ago #271099

Hi

I have a MC strategy, I need to transplant it to Algowizard an retest ,optimize.

So MC strategy code is :

inputs:Len1(14),Len2(80),sb(40);

variables:var1(0);

var1=(Average(close,Len1)-wAverage(close,Len2));

if Average(var1,sb) crosses over 0 then Buy  Next Bar at market;

if Average(var1,sb) crosses under 0 then Sell Short Next Bar at market;

Question:

1. I found that waverage function in MC is different from LWMA indicator in SQ

MC Waerage:

inputs:

PriceValue( numericseries ),

Len( numericsimple ) ;

variables:

var0( 0 ),

var1( 0 ) ;

var0 = 0 ;

for Value1 = 0 to Len – 1

begin

var0 = var0 + ( Len – Value1 ) * PriceValue[Value1] ;

end ;

var1 = ( Len + 1 ) * Len * .5 ;

WAverage = var0 / var1 ;

 

SQ LWMA indicator:

private void calculateLWMA(int CurrentBar, double newValue) {
int max = Math.min(Period, CurrentBar);
int multiplier = Period;
int divider = 0;
double sum = 0;

for(int a=0; a<max; a++){
divider += multiplier;
sum += buffer[a] * (multiplier–);
}

currentValue = sum / divider;
}

divider looks like Period*Period. So is differt from MC.  Whichi is better? Or no better, just be consistent between SQ and MC?

2. When I code average(var1,sb) crosses over 0 in Trading signals, How can I code? Because there are no “variable5” in

“ Compute from” option of average indicator.

So Is it possible to support to add custom variables  in price computed from option ? like period, shift option.

Of course i will try to add custom average function through programing in code editor first.

Thanks  very much

Bin

0

tomas262

Administrator, sq-ultimate, 2 replies.

Visit profile

2 years ago #271129

Hello,

yes, LWMA seems different from WMA since they supposed to be calculated differently

LWMA https://www.investopedia.com/terms/l/linearlyweightedmovingaverage.asp

WMA and others https://www.investopedia.com/ask/answers/071414/whats-difference-between-moving-average-and-weighted-moving-average.asp

You can simply check for two values cross but you always need to store 4 values. Meaning 2 values for Shift = 2 and 2 values for Shift = 1 so you have previous bar values and current bar values you can compare easily.

To check for the cross you simply setup these conditions:

if  Value1atShift2 < Value2atShift2 AND Value1atShift1 > Value2atShift1 – now you have a situation where Value1 crosses above Value2. This way you can setup any “Cross-over” situation …

1

Viewing 1 replies (of 1 total)