aCuddlyTurtle
Member
@Svanoy I have it go flat then buy on green, then go flat and short on red. then just go flat on blue. the other colors are there to reset the code. This is what I have so far.
Code:
###rsi####
input price = close;
input length = 14;
input OB = 70;
input OS = 30;
input rsiAverageType = AverageType.WILDERS;
def over_bought = OB;
def over_sold = OS ;
def rsi = reference RSI(price = price, length = length, averageType = rsiAverageType);
##### Stop Loss / Profit Target ####
input offsetType = {default percent, value, tick};
input longstop = 0.05;
input shortstop = 0.05;
input longtarget = 1.2;
input shorttarget = 1.2;
def entryPrice = EntryPrice();
def mult;
switch (offsetType) {
case percent:
mult = entryPrice / 100;
case value:
mult = 1;
case tick:
mult = TickSize();
}
def longstopPrice = entryPrice - longstop * mult;
def shortstopPrice = entryPrice + shortstop * mult;
def longTargetPrice = entryPrice + longtarget * mult;
def shortTargetPrice = entryPrice - shorttarget * mult;
############
def long = rsi[0] crosses above over_sold[0];
def longexit = rsi[0] crosses below over_bought[0];
def longStopProfit = low <= longstopPrice or high >= longTargetPrice;
def short = rsi[0] crosses below over_bought[0];
def shortexit = rsi[0] crosses above over_sold[0];
def shortStopProfit = high >= shortstopPrice or low<= shortTargetPrice;
AddOrder(OrderType.BUY_AUTO, long, tickcolor = GetColor(6), arrowcolor = GetColor(6), name = "LE");
AddOrder(OrderType.SELL_TO_CLOSE, longexit, tickcolor = GetColor(2), arrowcolor = GetColor(2), name = "Lexit");
AddOrder(OrderType.SELL_TO_CLOSE, longStopProfit, tickcolor = GetColor(9), arrowcolor = GetColor(9), name = "sp");
AddOrder(OrderType.SELL_AUTO, short, tickcolor = GetColor(2), arrowcolor = GetColor(2), name = "SE");
AddOrder(OrderType.BUY_TO_CLOSE, shortexit, tickcolor = GetColor(6), arrowcolor = GetColor(6), name = "stop");
AddOrder(OrderType.BUY_TO_CLOSE, shortStopProfit, tickcolor = GetColor(9), arrowcolor = GetColor(9), name = "sp");
#### Labels ####
AddLabel(yes, " ", if long[1] then Color.GREEN else Color.MAGENTA);
AddLabel(yes, " ", if short[1] then Color.RED else Color.YELLOW);
AddLabel(yes, " ", if long[1] and longstopProfit[1] or short[1] and shortstopProfit[1] then Color.BLUE else Color.CYAN);
def NewBar = if close[1] != close[2] or high[1] != high[2] or low[1] != low[2] then yes else Double.NaN;
def Clock = if !IsNaN(NewBar) and Clock[1] == 1 then 0 else if !IsNaN(NewBar) and Clock[1] == 0 then 1 else Clock[1];
AddLabel(yes, " ", if Clock == 0 then Color.VIOLET else Color.Gray);