order condition for RSI strategy with 3 inputs

SVL1967NC

New member
Hi,

Could you please help me to modify slightly standard RSI Strategy to include not 2 inputs but 3 inputs ( input over_bought = 70, input_neutral=50, input over_sold = 30) and to allow only one trade since crossover.
Buy only once if RSI crosses above any of these 3 levels and Sell only once when RSI crosses below any of these 3 levels .
In other words, you stay in long position without crossing below any intermediate levels ( 30, 50, 70), but reverse the position immediately if price crosses below any of these 3 levels ( 30, 50, 70) and vice versa.
I can not figure out how to script this condition.
Thanks in advance.

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2013-2020
#

input price = close;
input length = 14;
input over_bought = 70;
input over_sold = 30;
input rsiAverageType = AverageType.WILDERS;

def rsi = reference RSI(price = price, length = length, averageType = rsiAverageType);

AddOrder(OrderType.BUY_AUTO, rsi crosses above over_sold, tickColor = GetColor(0), arrowColor = GetColor(0), name = "RSI_LE");
AddOrder(OrderType.SELL_AUTO, rsi crosses below over_bought, tickColor = GetColor(1), arrowColor = GetColor(1), name = "RSI_SE");
 
Last edited by a moderator:
Code:
input price = close;
input length = 14;
input over_bought = 70;
input neutral= 50;
input oversold = 30;
input rsiAverageType = AverageType.WILDERS;

def x = (RSI[1] < (overbought or neutral or oversold)) and (RSI > (overbought or neutral or oversold));
def y = (RSI[1] > (overbought or neutral or oversold)) and (RSI < (overbought or neutral or oversold));



def rsi = reference RSI(price = price, length = length, averageType = rsiAverageType);

AddOrder(OrderType.BUY_AUTO, x, tickColor = GetColor(0), arrowColor = GetColor(0), name = "RSI_LE");
AddOrder(OrderType.SELL_AUTO, y, tickColor = GetColor(1), arrowColor = GetColor(1), name = "RSI_SE");
 

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

YungTraderFromMontana, many thanks for your prompt reply.

TOS highlighted these 2 lines in red "Expected Double":
def x = (RSI[1] < (overbought or neutral or oversold)) and (RSI > (overbought or neutral or oversold));
def y = (RSI[1] > (overbought or neutral or oversold)) and (RSI < (overbought or neutral or oversold));

I figured out myself through Global Strategy Setting by allowing up to 1 entry in the same direction regardless of the entry that generated the order. The below script works fine:

Code:
input price = close;
input length = 14;
input over_bought = 70;
input neutral= 50;
input over_sold = 30;

input rsiAverageType = AverageType.WILDERS;

def rsi = reference RSI(price = price, length = length, averageType = rsiAverageType);

AddOrder(OrderType.BUY_AUTO, rsi crosses above over_sold, tickColor = GetColor(0), arrowColor = GetColor(0), name = "RSI_LE");
AddOrder(OrderType.BUY_AUTO, rsi crosses above neutral, tickColor = GetColor(0), arrowColor = GetColor(0), name = "RSI_LE");
AddOrder(OrderType.BUY_AUTO, rsi crosses above over_bought, tickColor = GetColor(0), arrowColor = GetColor(0), name = "RSI_LE");

AddOrder(OrderType.SELL_AUTO, rsi crosses below over_bought, tickColor = GetColor(1), arrowColor = GetColor(1), name = "RSI_SE");
AddOrder(OrderType.SELL_AUTO, rsi crosses below neutral, tickColor = GetColor(1), arrowColor = GetColor(1), name = "RSI_SE");
AddOrder(OrderType.SELL_AUTO, rsi crosses below over_sold, tickColor = GetColor(1), arrowColor = GetColor(1), name = "RSI_SE");
 
Hello, apologies if this has already been posted. I did search diligently trying to find answers but I am not sure what I am doing wrong. I am using a custom Buy order with OCO to try and trigger a buy order when the RSI crosses above the 60 and a sell order when the RSI crosses below either the 60 or 70.

Buy order script: RSI()."RSI" from 1 bars ago crosses above 60

Sell order script: RSI()."RSI" crosses below 70 or RSI()."RSI" crosses below 60

The buy order seems to be triggering when it should, however, the sell order is triggering 2 bars early and I have no explanation for it.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
197 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