Tradarr
New member
Can someone convert the 4 strategies from https://tlc.thinkorswim.com/center/reference/Tech-Indicators/strategies/L-P/PriceSwing to 4 separate scans , particularity the RSI + Higher Low / Lower High with adjustable settings for the RSI ?
input swingType = {default "Pivot High-Low", "Bollinger Bands Crossover", "RSI Crossover", "RSI + Higher Low / Lower High"};
input length = 12;
input exitLength = 20;
input deviations = 2.0;
input overbought = 60;
input oversold = 40;
input averageType = AverageType.SIMPLE;
def rsi = reference RSI(length = length, "average type" = averageType);
def bbUpperBand = MovingAverage(averageType, close, length) + deviations * StDev(close, length);
def bbLowerBand = MovingAverage(averageType, close, length) - deviations * StDev(close, length);
def upSwing;
def downSwing;
switch (swingType) {
case "Pivot High-Low":
upSwing = low[1] < low[2] and low[1] < low;
downSwing = high[1] > high[2] and high[1] > high;
case "Bollinger Bands Crossover":
upSwing = close crosses above bbLowerBand;
downSwing = close crosses below bbUpperBand;
case "RSI Crossover":
upSwing = rsi crosses above oversold;
downSwing = rsi crosses below overbought;
case "RSI + Higher Low / Lower High":
upSwing = rsi < oversold and low > low[1];
downSwing = rsi > overbought and high < high[1];
}
def entryPrice = EntryPrice();
def afterEntryCount = if IsNaN(entryPrice[1]) and !IsNaN(entryPrice) then 1 else if !IsNaN(entryPrice) then afterEntryCount[1] + 1 else Double.NaN;
AddOrder(OrderType.BUY_TO_OPEN, upSwing, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "PriceSwingLE");
AddOrder(OrderType.SELL_TO_OPEN, downSwing, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "PriceSwingSE");
AddOrder(OrderType.BUY_TO_CLOSE, afterEntryCount > exitLength, tickcolor = GetColor(2), arrowcolor = GetColor(2), name = "PriceSwingLX");
AddOrder(OrderType.SELL_TO_CLOSE, afterEntryCount > exitLength, tickcolor = GetColor(3), arrowcolor = GetColor(3), name = "PriceSwingSX");
input swingType = {default "Pivot High-Low", "Bollinger Bands Crossover", "RSI Crossover", "RSI + Higher Low / Lower High"};
input length = 12;
input exitLength = 20;
input deviations = 2.0;
input overbought = 60;
input oversold = 40;
input averageType = AverageType.SIMPLE;
def rsi = reference RSI(length = length, "average type" = averageType);
def bbUpperBand = MovingAverage(averageType, close, length) + deviations * StDev(close, length);
def bbLowerBand = MovingAverage(averageType, close, length) - deviations * StDev(close, length);
def upSwing;
def downSwing;
switch (swingType) {
case "Pivot High-Low":
upSwing = low[1] < low[2] and low[1] < low;
downSwing = high[1] > high[2] and high[1] > high;
case "Bollinger Bands Crossover":
upSwing = close crosses above bbLowerBand;
downSwing = close crosses below bbUpperBand;
case "RSI Crossover":
upSwing = rsi crosses above oversold;
downSwing = rsi crosses below overbought;
case "RSI + Higher Low / Lower High":
upSwing = rsi < oversold and low > low[1];
downSwing = rsi > overbought and high < high[1];
}
def entryPrice = EntryPrice();
def afterEntryCount = if IsNaN(entryPrice[1]) and !IsNaN(entryPrice) then 1 else if !IsNaN(entryPrice) then afterEntryCount[1] + 1 else Double.NaN;
AddOrder(OrderType.BUY_TO_OPEN, upSwing, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "PriceSwingLE");
AddOrder(OrderType.SELL_TO_OPEN, downSwing, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "PriceSwingSE");
AddOrder(OrderType.BUY_TO_CLOSE, afterEntryCount > exitLength, tickcolor = GetColor(2), arrowcolor = GetColor(2), name = "PriceSwingLX");
AddOrder(OrderType.SELL_TO_CLOSE, afterEntryCount > exitLength, tickcolor = GetColor(3), arrowcolor = GetColor(3), name = "PriceSwingSX");