NexusFi: Find Your Edge


Home Menu

 





Referencing Previous Bars that Meet Certain Criteria


Discussion in ThinkOrSwim

Updated
    1. trending_up 2,328 views
    2. thumb_up 2 thanks given
    3. group 2 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
MisterT
Parsippany, NJ
 
Posts: 2 since May 2015
Thanks Given: 1
Thanks Received: 0

In ThinkOrSwim's ThinkScript, I'm trying to create an indicator which displays an average of the past 5 bars which had a range of more than 10 ticks.

For example, lets say last 10 bars had the following ranges (in ticks): 20, 22, 25, 17, 10, 7, 8, 8, 9, 8.
I want my indicator to display a value of 18.8 (i.e, (20+22+25+17+10)/5 = 18.8).

I'm fairly new to ThinkScript and so far I've been able to program an indicator which displays the average of the last 5 bars but I want to make one which will only average those bars which fulfill a certain criteria.

Any help would be appreciated!


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Victory Day Delivers: Russia-Ukraine Ceasefire Market Cl …
Prediction Markets & Event Contracts
Penalties in Budapest, Peace Deadline in Tehran: Arsenal …
Prediction Markets & Event Contracts
S&P 500 Holds the Line: No Fast Track for SpaceX, Op …
Stocks and ETFs
Warsh Drops Easing Bias, December Hike Now Above 50% -- …
Prediction Markets & Event Contracts
Wood Mackenzie Drops $200 Oil Forecast -- Airspace Expir …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
13 thanks
Darmok and Jalad at Tanagra
3 thanks
30 Sessions
1 thanks
Big Mike in Ecuador
1 thanks
  #2 (permalink)
mobiusrts
pensacola florida
 
Posts: 7 since Jul 2014
Thanks Given: 0
Thanks Received: 8

Not sure this is of any value other than to see how the fold expression is used

input Threshold = 10;
input n = 10;

def Avg = (fold i = 0 to n
with p
do p + getValue(if close > Threshold then close else 0, i, n - 1)) / n;
addLabel(1, "Avg Value " + Avg, Color.White);
AddLabel(1, "Avg " + (Average(close, n)));


Reply With Quote
Thanked by:
  #3 (permalink)
MisterT
Parsippany, NJ
 
Posts: 2 since May 2015
Thanks Given: 1
Thanks Received: 0



mobiusrts View Post
Not sure this is of any value other than to see how the fold expression is used

input Threshold = 10;
input n = 10;

def Avg = (fold i = 0 to n
with p
do p + getValue(if close > Threshold then close else 0, i, n - 1)) / n;
addLabel(1, "Avg Value " + Avg, Color.White);
AddLabel(1, "Avg " + (Average(close, n)));

Thanks for the reply. But wouldn't the above code average the last 10 bars regardless of whether it had higher than 10 ticks? If the last 10 bars all had less than 10 ticks then the value returned by this code would be 0, would it not?


Reply With Quote




Last Updated on May 14, 2015


© 2026 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 - Downloads - Top
no new posts