Crossing Moving Averages
Strategies require an entrance and exit event.
The "Crossing Moving Averages" rely on the following events:
The first is the entrance script called: sma_crossingLongEntry.ts
The Second exit script is called: sma_crossingLongExit.ts
#################################
# SMA Long Entry for Crossing Moving averages
#
# Brian Cox
# 4/1/13
# file name: sma_crossingLongEntry.ts
#
# This strategy will add to a position when the faster moving average
# crosses above the slower moving average.
#
# the default fast value is 10 and default slow is 20.
# you can state the buy strategy as: purchase when the fast_ma crosses above the slow_ma.
#
##############################################
input fast_ma = 10; # default vaule of "fast" SMA
input slow_ma = 20; # default value of "slow" SMA
input trade_size = 50;
def fast_value = SimpleMovingAvg(close, fast_ma);
def slow_value = SimpleMovingAvg(close, slow_ma);
def buy = Crosses(fast_value, slow_value, CrossingDirection.ABOVE);
addOrder(OrderType.BUY_to_open, buy, open, trade_size, color.green, color.green);
# \__ tick color \__ arrow color
#
#
#################################
# SMA Long Exit for Crossing Moving averages
#
# Brian Cox
# 4/1/13
# file name: sma_crossingLongExit.ts
#
# This strategy will exit a position when the faster moving average
# crosses below the slower moving average.
#
# the default fast value is 10 and default slow is 20.
# you can state the exit strategy as: sell when the fast_ma crosses below the slow_ma.
#
##############################################
input fast_ma = 10; # default vaule of "fast" SMA
input slow_ma = 20; # default value of "slow" SMA
def fast_value = SimpleMovingAvg(close, fast_ma);
def slow_value = SimpleMovingAvg(close, slow_ma);
def sell = Crosses(fast_value, slow_value, CrossingDirection.BELOW);
addOrder(OrderType.SELL_TO_CLOSE, sell);