Script Assistance

Hi, Just wondered if anyone can assist me with the following criteria for a script for scans:-

  1. 50MA<20MA
  2. 20MA<7MA
  3. Price< Highest High (Last 52weeks)
  4. Price uptrending
  5. Price uptrend change >10% (Last 14days)
I have attached the charts showing typically what I need. The current script I am using is including too many false +ves. CLOSE(Day(PERIODAMOUNT=1), OFFSET=2) CROSSESABOVE MA(7)

Many thanks and appreciate any assistance.

MF-Weekly-Scan.owb (9.06 KB)

MF-Weekly-Scan.pdf (18.3 KB)

Hi Marie,

You do not need to specify the daily time frame if you are using this on Day Charts and scanning on daily data ( which is the default).

I like to break up scans into separate items and put them in variables like “C1” which in my mind I call “Condition 1”

// 50MA<20MA
c1 = MA(Bars=50) < MA(Bars=20);

// 20MA<7MA
c2 = MA(Bars=20) < MA(Bars=7); 

// Price< Highest High (Last 52weeks)
c3 = CLOSE() < HIGHESTHIGH(BACKTYPE=Weeks, BARS=52);

// Price uptrending
// I'm not sure how you define this. You could use ADX for trend strength, or a Gann Swing to define trend direction.
c4 = GANNSWING(SWINGCOUNT=2) IsUp; 

//Price uptrend change >10% (Last 14days)
c5 = CHANGE(INT_COUNT=14, INT_TYPE=Day) > 10;

// now we combine them all with ANDS since we want all to be true
c1 AND c2 AND c3 AND c4 AND c5

What I like about using the variables is if there are any issues, I can go line by line and examine each item to be sure that it is right. eg If I wanted to check my Gann Swing rule, I can comment out the last line and just put c4 as the output like this

// 50MA<20MA 
c1 = MA(Bars=50) < MA(Bars=20); 

// 20MA<7MA 
c2 = MA(Bars=20) < MA(Bars=7); 

// Price< Highest High (Last 52weeks) 
c3 = CLOSE() < HIGHESTHIGH(BACKTYPE=Weeks, BARS=52); 

// Price uptrending 
c4 = GANNSWING(SWINGCOUNT=2) IsUp; 

//Price uptrend change >10% (Last 14days) 
c5 = CHANGE(INT_COUNT=14, INT_TYPE=Day) > 10; 

// now we combine them all with ANDS since we want all to be true 
//c1 AND c2 AND c3 AND c4 AND c5
c4

Hope that helps point you in the right direction

Mathew

That’s a great example of best-practice scripting. Thanks Matthew.