#help_fix_strat2
#https://usethinkscript.com/threads/help-with-strategy-code.18069/
#Help With Strategy Code
#Jank 2/26 #1
#Hi I was trying to make a Strategy for buying Forex based on BB and RSI for the minute chart but I'm getting errors from thinkscript, and I don't know how to fix them. Can anyone help me and maybe give me some suggestions on how to improve the strategy?
# Bollinger Bands and RSI Strategy with Visual Signals
#declare lower;
input bbLength = 20;
input numDevDn = -2.0;
input numDevUp = 2.0;
input rsiLength = 14;
input oversoldThreshold = 40;
input overboughtThreshold = 65;
input stopLossPercent = 5.0;
def price = close;
#def bb = BollingerBands(price, length = bbLength, numDevDn = numDevDn, numDevUp = numDevUp);
#def lowerBand = bb.lowerBand;
#def upperBand = bb.upperBand;
def bb_lower = BollingerBands(price, length = bbLength, numDevDn = numDevDn, numDevUp = numDevUp).lowerBand;
def bb_upper = BollingerBands(price, length = bbLength, numDevDn = numDevDn, numDevUp = numDevUp).upperBand;
#def rsiValue = RSI(close, rsiLength);
def rsiValue = RSI(length = rsiLength, price = close);
def buyCondition = close < bb_lower and rsiValue <= oversoldThreshold;
def sellCondition = close > bb_upper and rsiValue >= overboughtThreshold;
# Buy Signal
plot BuySignal = buyCondition;
BuySignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BuySignal.SetDefaultColor(Color.GREEN);
# Sell Signal
plot SellSignal = sellCondition;
SellSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SellSignal.SetDefaultColor(Color.RED);
# Stop Loss
def entryPrice = if buyCondition and !buyCondition[1] then close else entryPrice[1];
def stopLossLevel = entryPrice * (1.0 - stopLossPercent / 100);
def stopLossCondition = close <= stopLossLevel;
input tradesize = 1;
# Exit on Stop Loss
#AddOrder(OrderType.SELL_TO_CLOSE, sellCondition or stopLossCondition, tickcolor = GetColor(8), arrowcolor = GetColor(8), name = "Sell");
AddOrder(OrderType.SELL_TO_CLOSE, stopLossCondition, tickcolor = GetColor(8), arrowcolor = GetColor(8), name = "Sell");
# Exit on Target
AddOrder(OrderType.SELL_TO_CLOSE, sellCondition, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "Sell");
# Set Stop Loss Label
AddLabel(stopLossCondition, "Stop Loss", Color.RED);
# Plot visual signals on the chart
AddChartBubble(buyCondition, low, "Buy", Color.GREEN, no);
AddChartBubble(sellCondition or stopLossCondition, high, "Sell", Color.RED, yes);
addorder(type = OrderType.buy_to_open, condition = buyCondition, price = open[-1], tradesize = tradesize, tickcolor = Color.green, arrowcolor = Color.green, name = "BUY");
#