Trade markers

4 functions

These place an entry or exit marker and, in hosts that support order routing, raise a trade event. Passing DRAWNULL as the price suppresses the marker.

BUY(COND, PRICE, ICON, COLOR)

Long entry marker.

COND(condition)
Where the entry fires.
PRICE(series)
Marker price. DRAWNULL raises the event without drawing anything.
ICON(integer)
Icon number. Optional.
COLOR(color)
Marker colour. Optional.
// pair the entry with its exit, and filter so the two
// alternate — otherwise the marker fires all the way up
B := CROSS(MA(CLOSE, 5), MA(CLOSE, 20));
S := CROSS(MA(CLOSE, 20), MA(CLOSE, 5));
BUY(TFILTER(B, S, 0), LOW);
SELL(TFILTER(S, B, 0), HIGH);
SELL(COND, PRICE, ICON, COLOR)

Long exit marker.

COND(condition)
Where the exit fires.
PRICE(series)
Marker price. DRAWNULL suppresses the marker.
ICON(integer)
Icon number. Optional.
COLOR(color)
Marker colour. Optional.
// exit on either a crossover or a trailing stop, whichever
// comes first
STOP := LLV(LOW, 10);
SELL(CROSS(MA(CLOSE, 20), MA(CLOSE, 5)) OR CLOSE < STOP, HIGH);
BUYSHORT(COND, PRICE, ICON, COLOR)

Short entry marker.

COND(condition)
Where the short entry fires.
PRICE(series)
Marker price. DRAWNULL suppresses the marker.
ICON(integer)
Icon number. Optional.
COLOR(color)
Marker colour. Optional.
// the short side of the same system — note BUYSHORT opens
// the position and SELLSHORT closes it, not the other way round
BS := CROSS(MA(CLOSE, 20), MA(CLOSE, 5));
SS := CROSS(MA(CLOSE, 5),  MA(CLOSE, 20));
BUYSHORT(TFILTER(BS, SS, 0), HIGH);
SELLSHORT(TFILTER(SS, BS, 0), LOW);
SELLSHORT(COND, PRICE, ICON, COLOR)

Short exit marker.

COND(condition)
Where the short exit fires.
PRICE(series)
Marker price. DRAWNULL suppresses the marker.
ICON(integer)
Icon number. Optional.
COLOR(color)
Marker colour. Optional.
// cover the short at a target instead of a crossover
ENTRY := VALUEWHEN(CROSS(MA(CLOSE, 20), MA(CLOSE, 5)), CLOSE);
SELLSHORT(CLOSE < ENTRY * 0.95, LOW);