Counter Trend Show Bar Script

Hi All,

I’ve been trying to write a script that identifies entries on a 1-3 bar counter trends on a swing relations bar chart OHLC, when the 53 period centre MA is above a 10 period AMA. To say I have been finding it a little frustrating may be a slight understatement. Any help would be much appreciated.

Min of 3 bars up with a 1-3 bar countertrend that is less in price than the preceding leg up.

Outside bar - if previous bar is 3+ up treat as counter trend and enter if the next bar is higher. Or 1st bar down if the next bar is lower.

  • if previous bar is 1-3 down enter on outside bar

Inside bar - treat as counter trend enter if the next bar is higher

Entry is 1pt above previous bar

Thanks

Simon

MA(BARS=53, CALC=Close, STYLE=Center)>AMA(BARS=10, CALC=Close) and
HIGH() > HIGH(OFFSET=1) and
LOW() > LOW(OFFSET=1) and
(((HIGH(OFFSET=1) < HIGH(OFFSET=2)) and ((LOW(OFFSET=1) < LOW(OFFSET=2)) or (HIGH(OFFSET=1) > HIGH(OFFSET=2)) and (LOW(OFFSET=1) < LOW(OFFSET=2)) or (HIGH(OFFSET=1) < HIGH(OFFSET=2)) and (LOW(OFFSET=1) > LOW(OFFSET=2))) or
((HIGH(OFFSET=2) < HIGH(OFFSET=3)) and ((LOW(OFFSET=3) < LOW(OFFSET=3)) or
((HIGH(OFFSET=3) < HIGH(OFFSET=4)) and ((LOW(OFFSET=3) < LOW(OFFSET=4))) and
((HIGH(OFFSET=5) > HIGH(OFFSET=4)) and ((LOW(OFFSET=5) > LOW(OFFS

CT-Show-Bar-test.owb (18.8 KB)

I got the following to work by using 4 scripts joined together. However I think I have done something wrong with the 53 period centre MA (weekly xjo) is above a 10 period AMA (weekly xjo). Any suggestions appreciated.

// 1 DOWN HIGH() > HIGH(OFFSET=1) and LOW(OFFSET=1) > LOW(OFFSET=4) AND (((HIGH(OFFSET=5) < HIGH(OFFSET=4)) AND (LOW(OFFSET=5) < LOW(OFFSET=4)) AND (((HIGH(OFFSET=4) < HIGH(OFFSET=3)) AND (LOW(OFFSET=4) < LOW(OFFSET=3)) AND (((HIGH(OFFSET=3) < HIGH(OFFSET=2)) AND (LOW(OFFSET=3) < LOW(OFFSET=2))) AND //outside (((HIGH(OFFSET=2) < HIGH(OFFSET=1)) and (LOW(OFFSET=2) > LOW(OFFSET=1)) or //lower ((HIGH(OFFSET=2) >= HIGH(OFFSET=1))))))))))

// 2 DOWN HIGH() > HIGH(OFFSET=1) and LOW(OFFSET=1) > LOW(OFFSET=5) AND LOW(OFFSET=2) > LOW(OFFSET=5) AND (((HIGH(OFFSET=6) < HIGH(OFFSET=5)) AND (LOW(OFFSET=6) < LOW(OFFSET=5)) AND (((HIGH(OFFSET=5) < HIGH(OFFSET=4)) AND (LOW(OFFSET=5) < LOW(OFFSET=4)) AND (((HIGH(OFFSET=4) < HIGH(OFFSET=3)) AND (LOW(OFFSET=4) < LOW(OFFSET=3))) AND //lower (((HIGH(OFFSET=3) >= HIGH(OFFSET=2)) AND //lower (((HIGH(OFFSET=2) >= HIGH(OFFSET=1)))))))))))

// 3 DOWN HIGH() > HIGH(OFFSET=1) and LOW(OFFSET=1) > LOW(OFFSET=6) AND LOW(OFFSET=2) > LOW(OFFSET=6) AND LOW(OFFSET=3) > LOW(OFFSET=6) AND (((HIGH(OFFSET=7) < HIGH(OFFSET=6)) AND (LOW(OFFSET=7) < LOW(OFFSET=6)) AND (((HIGH(OFFSET=6) < HIGH(OFFSET=5)) AND (LOW(OFFSET=6) < LOW(OFFSET=5)) AND (((HIGH(OFFSET=5) < HIGH(OFFSET=4)) AND (LOW(OFFSET=5) < LOW(OFFSET=4))) AND //lower (((HIGH(OFFSET=4) >= HIGH(OFFSET=3)) AND //lower (((HIGH(OFFSET=3) >= HIGH(OFFSET=2)) AND //lower (((HIGH(OFFSET=2) >= HIGH(OFFSET=1)))))))))))))

V1 = GETDATA(CODE=XJO:ASX tim, TIMEFRAME=1 Week) ; V2 = MA(V1, BARS=53, STYLE=Center, CALC=Close) ; V3 = AMA(V1, BARS=10, FASTSC=2, SLOWSC=30) ; V2 > V3

SCRIPT(SCRIPTNAME=xjo MA 53 IS ABOVE AMA 10 1) AND SCRIPT(SCRIPTNAME=CORRECT 3 UP 1 DWN WITH PRICE 1) or SCRIPT(SCRIPTNAME=CORRECT 3 UP 2 DWN WITH PRICE 2) or SCRIPT(SCRIPTNAME=CORRECT 3 UP 3 DWN WITH PRICE 3)

e.g Show bar 3/9/21 and 14/2/20. The MA is below the AMA

CT-TEST-1.owb (13.5 KB)