NexusFi: Find Your Edge


Home Menu

 





Referencing Previous Bars that Meet Certain Criteria


Discussion in ThinkOrSwim

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




 
Search this Thread

Referencing Previous Bars that Meet Certain Criteria

  #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?
NexusFi Journal Challenge - April 2024
Feedback and Announcements
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
Are there any eval firms that allow you to sink to your …
Traders Hideout
Exit Strategy
NinjaTrader
Futures True Range Report
The Elite Circle
 
  #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


© 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