REM -- Trade long/short on a close higher or lower than the high or the low of an outside bar.
REM -- successful trades are closed at the spread (height) of the outside bar.
REM -- eg if the outside bar is 50 points high then the profit on a successful trade would be approx 50 points
REM -- the trade is stopped out if the price hits half the height of the outside bar in the wrong direction
REM -- so an outside bar with a 50 point spread would be stopped out at approx -25 points
ONCE outsidebarinplay = 0 //1=true, 0=false
REM -- if we have no position
IF NOT ONMARKET THEN
REM -- store the highs and lows of the previous three bars
twobarhigh = MAX(HIGH[1], HIGH[2])
twobarlow = MIN(LOW[1], LOW[2])
threebarhigh = MAX(twobarhigh, HIGH[3])
threebarlow = MIN(twobarlow, LOW[3])
REM -- If the bar is an outside bar (high is higher than the high of the last 3 bars, low is the opposite)
IF HIGH>threebarhigh AND LOW < threebarlow THEN
REM -- store the high, the low and the spread of the outside bar
outsidebarhigh = HIGH
outsidebarlow = LOW
outsidebarspread = outsidebarhigh-outsidebarlow
outsidebarinplay = 1 //1=true, 0=false
ENDIF
IF outsidebarinplay = 1 THEN
IF HIGH > outsidebarhigh THEN
BUY 1 SHARES AT outsidebarhigh STOP REALTIME
ENDIF
IF LOW < outsidebarlow THEN
SELLSHORT 1 SHARES AT outsidebarlow STOP REALTIME
ENDIF
ENDIF
ENDIF
IF LONGONMARKET THEN
IF HIGH > (outsidebarhigh + outsidebarspread) THEN
SELL 1 SHARES AT (outsidebarhigh + outsidebarspread) LIMIT REALTIME //profit
outsidebarinplay = 0
ELSIF LOW < (outsidebarhigh - outsidebarspread) THEN
SELL 1 SHARES AT (outsidebarhigh - (outsidebarspread/2)) STOP REALTIME //loss
outsidebarinplay = 0
ENDIF
ENDIF
IF SHORTONMARKET THEN
IF LOW < (outsidebarlow - outsidebarspread) THEN
EXITSHORT 1 SHARES AT (outsidebarlow - outsidebarspread) LIMIT REALTIME //profit
outsidebarinplay = 0
ELSIF HIGH > (outsidebarlow + outsidebarspread) THEN
EXITSHORT 1 SHARES AT (outsidebarlow + (outsidebarspread/2)) STOP REALTIME //loss
outsidebarinplay = 0
ENDIF
ENDIF