Greeting to everyone is my please to joined this amazing community I'm very grateful
please I needed your help I have been working on this script but note able to make it work on ThinkOrSwim
please I needed your help I have been working on this script but note able to make it work on ThinkOrSwim
Ruby:
# Trend Following with Mean Reversion Strategy
# Inputs
input lengthMA = 50;
input lengthBB = 20;
input lengthRSI = 14;
input overbought = 70;
input oversold = 30;
# Define indicators
def MA = Average(close, lengthMA);
def UpperBB = BollingerBandTop(close, lengthBB);
def LowerBB = BollingerBandBottom(close, lengthBB);
def RSI = RSI(close, lengthRSI);
# Entry rules
def longCondition = close > MA and RSI < oversold and close crosses above LowerBB;
def shortCondition = close < MA and RSI > overbought and close crosses below UpperBB;
# Exit rules
def longExit = close crosses below UpperBB or RSI > overbought;
def shortExit = close crosses above LowerBB or RSI < oversold;
# Plot signals
plot longEntry = if longCondition then Low else Double.NaN;
plot shortEntry = if shortCondition then High else Double.NaN;
plot longExitSignal = if longExit then Low else Double.NaN;
plot shortExitSignal = if shortExit then High else Double.NaN;
longEntry.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
longEntry.SetDefaultColor(Color.GREEN);
shortEntry.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
shortEntry.SetDefaultColor(Color.RED);
longExitSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
longExitSignal.SetDefaultColor(Color.GREEN);
shortExitSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
shortExitSignal.SetDefaultColor(Color.RED);
# Alerts
Alert(longCondition, "Long Entry", "Long Entry Signal", Alert.BAR, Sound.RING);
2
Alert(shortCondition, "Short Entry", "Short Entry Signal", Alert.BAR, Sound.RING);
Alert(longExit, "Long Exit", "Long Exit Signal", Alert.BAR, Sound.RING);
Alert(shortExit, "Short Exit", "Short Exit Signal", Alert.BAR, Sound.RING);
Last edited by a moderator: