NexusFi: Find Your Edge


Home Menu

 





Putting up and down arrows on chart


Discussion in ThinkOrSwim

Updated
      Top Posters
    1. looks_one cala with 2 posts (0 thanks)
    2. looks_two Cirrus Flyer with 1 posts (1 thanks)
    3. looks_3 tangerine with 1 posts (1 thanks)
    4. looks_4 jeremyis with 1 posts (2 thanks)
    1. trending_up 16,177 views
    2. thumb_up 4 thanks given
    3. group 4 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread

Putting up and down arrows on chart

  #1 (permalink)
Cirrus Flyer
Kaukauna, WI, USA
 
Posts: 1 since Feb 2014
Thanks Given: 1
Thanks Received: 1

I'm trying to put up or down arrows on the chart if certain conditions are met. Here's the code that I'm having trouble with:


plot Arrow = if (ConnersRSI <= UnderSold) then Arrow = (Arrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP)) else if (ConnersRSI => OverBought) then Arrow = (Arrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN));

Think Script just gives me Invalid Statement. I took the form of the if statement right out of the TOS reference area.

Can anybody help get? Again, thanks in advance for the help.

Alan

Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Exit Strategy
NinjaTrader
NexusFi Journal Challenge - May 2024
Feedback and Announcements
ZombieSqueeze
Platforms and Indicators
Trade idea based off three indicators.
Traders Hideout
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
48 thanks
Just another trading journal: PA, Wyckoff & Trends
34 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
  #2 (permalink)
jeremyis
Portland, OR, USA
 
Posts: 3 since Aug 2015
Thanks Given: 4
Thanks Received: 3

Hi Alan,

AFAIK, you'll want to use addOrder() to add up/down arrows. But first a bit on your question about the invalid statement. When using plot Data = x, the x needs to resolve to a numeric value otherwise we couldn't plot it. For a very simplistic possibly even silly illustration, if we wanted to plot a 1 every time the close exceeded the open price and 0 if it didn't, we could write:

 
Code
plot Data = if close > open then 1 else 0;
Note how the value assigned to Data is numeric (1 or 0);

Now for for putting arrows on the chart, the AddOrder() function offers that. The ConnorsRSI isn't built into TOS so I found an implementation online and modified it for use as a strategy and not a plot. We use the appropriate AddOrders with conditions for overbought buy and sell. I created this as a strategy (not a study) and then ran a strategy report on FB for the last year (daily) and it made 115 orders with total Profit/Loss of $2075. I also used the standard convention from other strategies where up arrows indicate a long entry (aka buy) and down arrows a short entry (aka sell). Hope that helps

 
Code
input Over_Bought = 70;
input Over_Sold = 30;

# ConnorsRSI taken from 
# https://groups.yahoo.com/neo/groups/TOS_thinkscript/conversations/topics/14212
input Price_RSI_Period = 3;
input Streak_RSI_Period = 2;
input Rank_Lookback = 100;

# Component 1: the RSI of closing price
def priceRSI = reference RSI("price" = close, "length" = Price_RSI_Period);

# Component 2: the RSI of the streak 
def upDay = if close > close[1] then 1 else 0;
def downDay = if close < close[1] then -1 else 0;
def upStreak = if upDay != 0 then upStreak[1] + upDay else 0;
def downStreak = if downDay != 0 then downStreak[1] + downDay else 0;
def streak = upStreak + downStreak;
def streakRSI = reference RSI("price" = streak, "length" = Streak_RSI_Period); 

# Componenet 3: The percent rank of the current return
def ROC1 = close / close[1] - 1;

def rank = fold i = 1 to Rank_Lookback + 1 with r = 0 do 
r + (GetValue(ROC1, i, Rank_Lookback) < ROC1) ;

def pctRank = (rank / Rank_Lookback) * 100 ; 

# The final ConnorsRSI calculation, combining the three components
def ConnorsRSI = (priceRSI + streakRSI + pctRank) / 3;

#Add up arrows
AddOrder(OrderType.BUY_AUTO, ConnorsRSI <= Over_Sold, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "ConnorsRSIStratLE");
#Add down arrows
AddOrder(OrderType.SELL_AUTO, ConnorsRSI >= Over_Bought, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "ConnorsRSIStratSE");

Reply With Quote
Thanked by:
  #3 (permalink)
tangerine
albuquerque nm/usa
 
Posts: 29 since Aug 2015
Thanks Given: 3
Thanks Received: 9



Cirrus Flyer View Post
I'm trying to put up or down arrows on the chart if certain conditions are met. Here's the code that I'm having trouble with:


plot Arrow = if (ConnersRSI <= UnderSold) then Arrow = (Arrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP)) else if (ConnersRSI => OverBought) then Arrow = (Arrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN));

Think Script just gives me Invalid Statement. I took the form of the if statement right out of the TOS reference area.

Can anybody help get? Again, thanks in advance for the help.

Alan

jeremyis already gave you a great reply, way above my pay grade. But for those browsing who are more TS newbie than I am, the thread title suggests something simpler might be on offer. So here are some simplistic answers to your question.
--------------------------------------
 
Code
#For arrows, you want some definite value produced by a calculation in your code.
#Let's say you want an UP arrow whenever the close moves up at least 1% from the
#previous close FOR THE FIRST TIME. And you want a DOWN arrow whenever the close
#moves down at least 1% from the previous close FOR THE FIRST TIME. So the initial
#part of your code could look like this:

def runup = close >= 1.01 * close[1];
def rundown = close <= 0.99 * close[1];

#Now plot the arrows:

plot Above = runup;
Above.SetDefaultColor(Color.BLUE);
Above.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
plot Below = rundown;
Below.SetDefaultColor(Color.RED);
Below.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

#Next, IF YOU HAD DECLARED THIS AS A LOWER STUDY, then to make those arrows run in nice
#horizontal lines, add a zeroline (or you'll get annoyingly ragged rows of arrows. DO NOT
#add the zeroline to an upper study (price overlay) because it'll flatten everything on your chart,
#remedied only by right-clicking the study and USE LEFT AXIS:

plot zeroline = 0;
--------------------------------------
#Now, suppose you find that the above code seems to profit you Long only when the
#current high is higher than the previous high, and it profits you Short only when the
#current low is lower than the previous low. Time to tweak it. Before I began to better
#understand how to write if-then-else conditionals, I simply used def workarounds like
#this, to avoid if-then-else stuff:

def runup = close >= 1.01 * close[1] AND high > high[1];
def rundown = close <= 0.99 * close[1] AND low < low[1];

#The above two lines of code are the only change from the original, using the Boolean
#operator "AND" to say you want BOTH conditions met before plotting an arrow.

plot Above = runup;
Above.SetDefaultColor(Color.BLUE);
Above.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
plot Below = rundown;
Below.SetDefaultColor(Color.RED);
Below.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

Reply With Quote
Thanked by:
  #4 (permalink)
cala
France
 
Posts: 2 since Jan 2018
Thanks Given: 6
Thanks Received: 0

Hi guys, this is so cool. How can I translate this to the C#code or use it on ctrader. Thanks in advance

Reply With Quote
  #5 (permalink)
cala
France
 
Posts: 2 since Jan 2018
Thanks Given: 6
Thanks Received: 0


cala View Post
Hi guys, this is so cool. How can I translate this to the C#code or use it on ctrader. Thanks in advance

This is no longer applicable as I decided to change.

Reply With Quote




Last Updated on February 7, 2018


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts