Help With Strategy Code

Jank

New member
VIP
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?

No such constant: bb.lowerband at 15:17
No such constant: bb.upperband at 16:17
No such constant: bb.lowerband at 15:17
Expected double at 15:5
No such constant: bb.upperband at 16:17
Expected double at 16:5
LOWER not allowed in strategies
Only constants expected here: _inline_referenced_param_bSRP_141_length CL constant function parameter 'length' at 18:16
Only constants expected here: _inline_referenced_param_bSRP_141_length CL constant function parameter 'length' at 18:16
No such constant: bb.lowerband at 15:17
No such constant: bb.upperband at 16:17
No such constant: bb.lowerband at 15:17
Expected double at 15:5
No such constant: bb.upperband at 16:17
Expected double at 16:5
Only constants expected here: _inline_referenced_param_bSRP_141_length CL constant function parameter 'length' at 18:16
Only constants expected here: _inline_referenced_param_bSRP_141_length CL constant function parameter 'length' at 18:16
 

Attachments

  • RSI-BB-FOREX.txt
    1.7 KB · Views: 64
Solution
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?

No such constant: bb.lowerband at 15:17
No such constant: bb.upperband at 16:17
No such constant: bb.lowerband at 15:17
Expected double at 15:5
No such constant: bb.upperband at 16:17
Expected double at 16:5
LOWER not allowed in strategies
Only constants expected here: _inline_referenced_param_bSRP_141_length CL constant function parameter 'length' at 18:16
Only constants expected here: _inline_referenced_param_bSRP_141_length CL constant function parameter 'length' at 18:16
No such...
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?

No such constant: bb.lowerband at 15:17
No such constant: bb.upperband at 16:17
No such constant: bb.lowerband at 15:17
Expected double at 15:5
No such constant: bb.upperband at 16:17
Expected double at 16:5
LOWER not allowed in strategies
Only constants expected here: _inline_referenced_param_bSRP_141_length CL constant function parameter 'length' at 18:16
Only constants expected here: _inline_referenced_param_bSRP_141_length CL constant function parameter 'length' at 18:16
No such constant: bb.lowerband at 15:17
No such constant: bb.upperband at 16:17
No such constant: bb.lowerband at 15:17
Expected double at 15:5
No such constant: bb.upperband at 16:17
Expected double at 16:5
Only constants expected here: _inline_referenced_param_bSRP_141_length CL constant function parameter 'length' at 18:16
Only constants expected here: _inline_referenced_param_bSRP_141_length CL constant function parameter 'length' at 18:16



errors in strategy,
it lists all the errors at the bottom of code. look at them and go look at the code line.

can't use lower in a strategy
declare lower;

----------------

this is wrong. should have the plot plot name after the () . can't use it on a variable
def bb = BollingerBands(price, length = bbLength, numDevDn = numDevDn, numDevUp = numDevUp);
def lowerBand = bb.lowerBand;
def upperBand = bb.upperBand;

fixed
def bb_lower = BollingerBands(price, length = bbLength, numDevDn = numDevDn, numDevUp = numDevUp).lowerBand;
def bb_upper = BollingerBands(price, length = bbLength, numDevDn = numDevDn, numDevUp = numDevUp).upperBand;

----------------

wrong parameters in RSI(). you didn't specify parameter names , so they have to be in the correct order and quantity. price is 4th parameter, so would need to specify the 3 before price (without names)
def rsiValue = RSI(close, rsiLength);

fixed
def rsiValue = RSI(length = rsiLength, price = close);

go here and learn about the RSI study & parameters
https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/R-S/RSI

-------------

you are missing addorder to buy on open
addorders are missing parameters and don't have all the names listed


addorders, you have 2 sell to close. i would separate the conditions in first one, so each just has 1 condition. one for target and 1 for stop

AddOrder(OrderType.SELL_TO_CLOSE, sellCondition or stopLossCondition, tickcolor = GetColor(8), arrowcolor = GetColor(8), name = "Sell");


added addorder for buy


----------------

Code:
#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");

#
 

Attachments

  • Capture.JPG
    Capture.JPG
    52.7 KB · Views: 69
Last edited:
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
373 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top