RSI Long Entry
This Long Entry Strategy will purchase on the bar following a drop below a specified RSI Value.
It will also calculate the number of shares based on the position size specified.
#################################
# RSI(2) Long Entry
#
# Brian Cox
# 4/2/13
#
# 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.
#
##############################################
declare once_per_bar;
input length = 2; # default 2 day length
input over_bought = 75; # Suggested over-bought threshold
input over_sold = 25; # Suggested over-sold threshold
#input trade_size = 50; # suggested tradesize
input price = close; # use the closing price in the calculations
input position_size_dollars = 2000; # what is the size of each trade?
def green = 9; # value for green
def red = 5; # value for red
def NetChgAvg = ExpAverage(price - price[1], length);
def TotChgAvg = ExpAverage(AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI_EMA = 50 * (ChgRatio + 1);
def buy = crosses (RSI_EMA, over_sold, CrossingDirection.BELOW);
def trade_size = position_size_dollars / close;
addOrder(OrderType.BUY_AUTO, buy, open[-1], trade_size, color.green, color.green);
# \__ tick color \__ arrow color
#
#
#def stop_loss = StopLossLX(percent,4.0);
input offsetType = {default percent, value, tick};
input stop = 1.0;
def entryPrice = high;
def mult;
switch (offsetType) {
case percent:
mult = entryPrice / 100;
case value:
mult = 1;
case tick:
mult = tickSize();
}
def stopPrice = entryprice - stop * mult;
# addOrder(OrderType.SELL_TO_CLOSE, low <= stopPrice, tickColor = GetColor(5), arrowColor = GetColor(5));