Scan giving random erroneous results

I’m using the following script to scan for 50MA is above 150MA and 200MA and 150MA is above 200MA (50MA is above 150MA is above 200MA).

//Set MA variables 
MA1 = MA(BARS=50, CALC=Close); 
MA2 = MA(BARS=150, CALC=Close); 
MA3 = MA(BARS=200, CALC=Close);
//50MA is above 150MA and 200MA and 150MA is above 200MA
(MA1>MA2) and (MA1>MA3) and (MA2>MA3)

I’ve tried various combinations such as MA1>MA2>MA3 or V1=(MA1>MA2); V2=(MA2>MA3); V1 and V2.

However the various scans produce a watchlist with a small percentage of erroneous results with MA1 being below MA2 or MA3 or below both MA2 and MA3


Thanks Tim - the formula is correct. Can you give an example of an error?

It’s probably a difference between the MA criteria in the script versus the MAs on the chart. For example, are the MAs on the chart set to use the closing price as per the formula?

Hi Darren,

Please see workbook attached.

The 3 MA’s on the charts are set at Bars: 50/150/200, Calc Style: Simple, Calc Using: Close.




MA-Scan.owb (118 KB)


What scan settings are you using?

I used your script and ran it across the ASX All Ords codes and checked the 107 results that passed.

AGG passed, and when checked on the chart, shows that the MA setups are meeting the expected rules (and have done so for the last 3 days)…


Hi Matthew,

Codes = ASX All Ords, Membership = Current, Date Range = Last Week, Date Timeframe = 1 Day, Display = Latest Match.

Just ran it again then.
VCP Trend Scan

When scanning on Last Week it will return all true results that have occurred during that time. On March 17th the conditions were true for CHN, which is why it’s in the results.

If you scan on the Last Bar instead of Last Week you will get only those that are currently true.

Hi Darren,