Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

Version 17 - X Bars Ago as an indicator (Feature Request) Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
usmansajid
Posted : Friday, January 27, 2017 6:38:22 AM
Registered User
Joined: 3/17/2016
Posts: 48

Hi, 

I see that in V17 in the search criteria we have a "True" option which allows the user to input a number as to when their condition was true. 

 

I would like to use this as a indicator, so I can put my custom condition inside, below is a very simple one but i have complex conditions and i'd like to when it was true, for example:

Close > Simple Moving Average 5

OR 

Close > Simple Moving Average 5 > and Slow K > D and Close > EMA etc....

The idea is to use this as a column, the value returned would tell me when the condition was true, i.e. 8 would tell me 8 bars ago this condition was true.

I know we can achieve this indirectly but formulas are long and messy, I'd really like a function and then input my condition. 

i.e. barssince(Close > AVGC5 > and Slow K > D and Close > EMA)

returns 50 - (50 bars ago this was true).

 

If this isn't available in V17, it would most certainly be a great addition. 

 

 

Bruce_L
Posted : Friday, January 27, 2017 8:12:59 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

Thank you for your suggestion.

On a sidenote, formulas such as this have recently become a lot shorter in TC2000 v17 versus previous versions of TC2000. You used to have to use the techniques outlined in the following topic to get such counts.

Days Since Last Peak (or other day-counting needs)

But such a formula could be written in a much shorter form today (this is just an example as you did not list your specific settings).

SinceTrue(C > AVGC5 OR (STOC12.3 > AVG(STOC12.3, 5) AND C > XAVGC5), 100)

Version 17 PCF Capabilities



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
donv98
Posted : Friday, January 27, 2017 12:35:39 PM
Registered User
Joined: 7/29/2010
Posts: 417

Bruce,

  Please help me understand how to use the new R17 Beta syntax :

TrueInRow(bx) -> Will return a value between 0 and period that is how many times the Boolean formula was true in a row

 

Where b can be any formula which returns a true or false result

Where x is the Period of the Indicator

 

Example you gave for 21 ema rising  bars, for 60  bar look back

http://forums.worden.com/default.aspx?g=posts&t=66185

TrueInRow(XAVGC21 > XAVGC21.1,60)

So the new syntax returns a value between 0 and x, with x being the number of bars to look back to see if the Boolean formula was true in a row.

The output is identical to the old, very long way.

I could use this to AND several of these T/F formulas in 1 pcf which would likely be far too long using the old counting bars formulas.

Do I have this correct?

I am not currently using V.  17 but am preparing ...

Many thanks,

Don

Bruce_L
Posted : Friday, January 27, 2017 1:21:35 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

I am not quite sure what help you need in understanding as you do seem to have it correct.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
donv98
Posted : Friday, January 27, 2017 1:45:45 PM
Registered User
Joined: 7/29/2010
Posts: 417

Bruce,

   Thank you for confirming. 

I want to make sure I understand the power of the new bar counting syntax as it could really help me.

 

Don

 

StockGuy
Posted : Friday, January 27, 2017 1:53:20 PM

Administration

Joined: 9/30/2004
Posts: 9,187

If the most recent bar is False, then the indicator value will be 0.  If the last 10 bars are True the indictator value will be 10.

donv98
Posted : Friday, January 27, 2017 5:02:40 PM
Registered User
Joined: 7/29/2010
Posts: 417

Stockguy,

   Thank you.

 Stockguy or Bruce,

  How would I create a pcf with the new syntax that counts the number of bars in a TTM squeeze up to maybe 30?

Many thanks for any help.

Don

Bruce_L
Posted : Monday, January 30, 2017 1:02:21 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

Please try the following Indicator Formula.

TrueInRow(STDDEV(C, 20) * 4 <= 3 * ATR(20), 30)



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
donv98
Posted : Monday, January 30, 2017 4:13:32 PM
Registered User
Joined: 7/29/2010
Posts: 417

Bruce,

Thank you very much.

    I don't have a way to check it quite yet but will soon enough.

I am in awe at the power and simplicity of the new syntax compared to the old counting method.

The new syntax opens up many more counting possibilities.

 

Don

 

usmansajid
Posted : Tuesday, January 31, 2017 9:30:04 AM
Registered User
Joined: 3/17/2016
Posts: 48

Bruce, 

I currently use the formula to tell me "how long Closing Price has been above Moving Average 50"? It returns -1 when its not true and when true, it returns the value of how long its been true for? 

The formula is below: 

ABS(AVGC50 > C) * -1 + ABS(C1 > AVGC50.1) * (ABS(C2 <= AVGC50.2) + ABS(C2 > AVGC50.2) * (ABS(C3 <= AVGC50.3) * 2 + ABS(C3 > AVGC50.3) * (ABS(C4 <= AVGC50.4) * 3 + ABS(C4 > AVGC50.4) * (ABS(C5 <= AVGC50.5) * 4 + ABS(C5 > AVGC50.5) * (ABS(C6 <= AVGC50.6) * 5 + ABS(C6 > AVGC50.6) * (ABS(C7 <= AVGC50.7) * 6 + ABS(C7 > AVGC50.7) * (ABS(C8 <= AVGC50.8) * 7 + ABS(C8 > AVGC50.8) * (ABS(C9 <= AVGC50.9) * 8 + ABS(C9 > AVGC50.9) * (ABS(C10 <= AVGC50.10) * 9 + ABS(C10 > AVGC50.10) * (ABS(C11 <= AVGC50.11) * 10 + ABS(C11 > AVGC50.11) * (ABS(C12 <= AVGC50.12) * 11 + ABS(C12 > AVGC50.12) * (ABS(C13 <= AVGC50.13) * 12 + ABS(C13 > AVGC50.13) * (ABS(C14 <= AVGC50.14) * 13 + ABS(C14 > AVGC50.14) * (ABS(C15 <= AVGC50.15) * 14 + ABS(C15 > AVGC50.15) * (ABS(C16 <= AVGC50.16) * 15 + ABS(C16 > AVGC50.16) * (ABS(C17 <= AVGC50.17) * 16 + ABS(C17 > AVGC50.17) * (ABS(C18 <= AVGC50.18) * 17 + ABS(C18 > AVGC50.18) * (ABS(C19 <= AVGC50.19) * 18 + ABS(C19 > AVGC50.19) * (ABS(C20 <= AVGC50.20) * 19 + ABS(C20 > AVGC50.20) * (ABS(C21 <= AVGC50.21) * 20 + ABS(C21 > AVGC50.21) * (ABS(C22 <= AVGC50.22) * 21 + ABS(C22 > AVGC50.22) * (ABS(C23 <= AVGC50.23) * 22 + ABS(C23 > AVGC50.23) * (ABS(C24 <= AVGC50.24) * 23 + ABS(C24 > AVGC50.24) * (ABS(C25 <= AVGC50.25) * 24 + ABS(C25 > AVGC50.25) * (ABS(C26 <= AVGC50.26) * 25 + ABS(C26 > AVGC50.26) * (ABS(C27 <= AVGC50.27) * 26 + ABS(C27 > AVGC50.27) * (ABS(C28 <= AVGC50.28) * 27 + ABS(C28 > AVGC50.28) * (ABS(C29 <= AVGC50.29) * 28 + ABS(C29 > AVGC50.29) * (ABS(C30 <= AVGC50.30) * 29 + ABS(C30 > AVGC50.30) * (ABS(C31 <= AVGC50.31) * 30 + ABS(C31 > AVGC50.31) * (ABS(C32 <= AVGC50.32) * 31 + ABS(C32 > AVGC50.32) * (ABS(C33 <= AVGC50.33) * 32 + ABS(C33 > AVGC50.33) * (ABS(C34 <= AVGC50.34) * 33 + ABS(C34 > AVGC50.34) * (ABS(C35 <= AVGC50.35) * 34 + ABS(C35 > AVGC50.35) * (ABS(C36 <= AVGC50.36) * 35 + ABS(C36 > AVGC50.36) * (ABS(C37 <= AVGC50.37) * 36 + ABS(C37 > AVGC50.37) * (ABS(C38 <= AVGC50.38) * 37 + ABS(C38 > AVGC50.38) * (ABS(C39 <= AVGC50.39) * 38 + ABS(C39 > AVGC50.39) * (ABS(C40 <= AVGC50.40) * 39 + ABS(C40 > AVGC50.40) * (ABS(C41 <= AVGC50.41) * 40 + ABS(C41 > AVGC50.41) * (ABS(C42 <= AVGC50.42) * 41 + ABS(C42 > AVGC50.42) * (ABS(C43 <= AVGC50.43) * 42 + ABS(C43 > AVGC50.43) * (ABS(C44 <= AVGC50.44) * 43 + ABS(C44 > AVGC50.44) * (ABS(C45 <= AVGC50.45) * 44 + ABS(C45 > AVGC50.45) * (ABS(C46 <= AVGC50.46) * 45 + ABS(C46 > AVGC50.46) * (ABS(C47 <= AVGC50.47) * 46 + ABS(C47 > AVGC50.47) * (ABS(C48 <= AVGC50.48) * 47 + ABS(C48 > AVGC50.48) * (ABS(C49 <= AVGC50.49) * 48 + ABS(C49 > AVGC50.49) * (ABS(C50 <= AVGC50.50) * 49 + ABS(C50 > AVGC50.50) * 50)))))))))))))))))))))))))))))))))))))))))))))))))
 
 
 
How could you do this using SinceTrue? Can you make it shorter?
patftest
Posted : Tuesday, January 31, 2017 9:49:00 AM
Registered User
Joined: 5/8/2015
Posts: 6

TRUEINROW(C > AVGC50,100)

The result is the number of bars that the close has been above the 50 bar average.  If C is less than AVGC50 on the latest bar it will return 0.

Bruce_L
Posted : Tuesday, January 31, 2017 10:14:46 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

I'm not actually sure the formula does what you think. That said, you can use either TrueInRow() or SinceTrue() for this sort of thing.

SinceTrue(bx) -> returns -1 if Boolean Formula was not true in period, or bars since it was true, 0 being the current bar, and period-1 the max it will return

TrueInRow(bx) -> Will return a value between 0 and period that is how many times the Boolean formula was true in a row

So the SinceTrue version would be:

SinceTrue(C <= AVGC50, 50)

And the TrueInRow version would be:

TrueInRow(C > AVGC50, 50)

Both return 0 if the C > AVGC50 is not true and the number of bars in a row C > AVGC50 if C > AVGC50 is true as long as C > AVGC50 is not true for all 50 bars.

If C > AVGC50 is true for all 50 bars, the SinceTrue version would return -1 while the TrueInRow version would return 50.

If you want to plot -1 instead of 0 when C > AVGC50 is not currently true, then you could write this as follows.

IIF(C <= AVGC50, -1, TrueInRow(C > AVGC50, 50))



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
donv98
Posted : Wednesday, February 1, 2017 12:09:07 PM
Registered User
Joined: 7/29/2010
Posts: 417

Bruce,

   Is there any way you could make this post a sticky or more easily  accessible?

It is very useful.

R17 Beta PCF Capabilities

 

Many thanks,

Don

 

StockGuy
Posted : Wednesday, February 1, 2017 12:11:01 PM

Administration

Joined: 9/30/2004
Posts: 9,187

Made it sticky.

donv98
Posted : Wednesday, February 1, 2017 12:35:33 PM
Registered User
Joined: 7/29/2010
Posts: 417

Stockguy,

   Thank you.

don

usmansajid
Posted : Monday, February 6, 2017 5:10:40 PM
Registered User
Joined: 3/17/2016
Posts: 48

Bruce, 

I'm trying to extend this formula further and want to use it in another column to tell me the change in % since the crossover.

 

this is the formula i'm using:

IIF(C <= AVGC50, -1, TrueInRow(C > AVGC50, 50))
 
I'm using this formula to calculate change since the crossover
((C - Cx) / Cx ) * 100
 
My understanding that Cx or C(x) returns the price closing price at period x. 
 
 
 
My formula becomes becomes 
 
((C - C(IIF(C <= AVGC50, -1, TrueInRow(C > AVGC50, 50))) / IIF(C <= AVGC50, -1, TrueInRow(C > AVGC50, 50))) * 100
 
 
However, its not working as expected, because it multiplies the price with the value returned from function, i.e. 
 
it becomes like below for example:
 
(65 - 60(50) / 60(50)) * 100 
 
 
Please help, i need to know the change % since the crossover, how do i do it? 
 
Bruce_L
Posted : Monday, February 6, 2017 7:36:35 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

I have requested that the bars ago parameters in function accept formulas as arguments, but they do not do so currently. I do not know for sure when or if this might happen. Until or unless it does, you will not be able to use this sort of short syntax to create the desired formula and you will have to do it the long way.

IIF(TrueInRow(C > AVGC50, 50) > 0, 100 * (C / (ABS(C <= AVGC50) + ABS(C > AVGC50) * (ABS(C1 <= AVGC50.1) * C + ABS(C1 > AVGC50.1) * (ABS(C2 <= AVGC50.2) * C1 + ABS(C2 > AVGC50.2) * (ABS(C3 <= AVGC50.3) * C2 + ABS(C3 > AVGC50.3) * (ABS(C4 <= AVGC50.4) * C3 + ABS(C4 > AVGC50.4) * (ABS(C5 <= AVGC50.5) * C4 + ABS(C5 > AVGC50.5) * (ABS(C6 <= AVGC50.6) * C5 + ABS(C6 > AVGC50.6) * (ABS(C7 <= AVGC50.7) * C6 + ABS(C7 > AVGC50.7) * (ABS(C8 <= AVGC50.8) * C7 + ABS(C8 > AVGC50.8) * (ABS(C9 <= AVGC50.9) * C8 + ABS(C9 > AVGC50.9) * (ABS(C10 <= AVGC50.10) * C9 + ABS(C10 > AVGC50.10) * (ABS(C11 <= AVGC50.11) * C10 + ABS(C11 > AVGC50.11) * (ABS(C12 <= AVGC50.12) * C11 + ABS(C12 > AVGC50.12) * (ABS(C13 <= AVGC50.13) * C12 + ABS(C13 > AVGC50.13) * (ABS(C14 <= AVGC50.14) * C13 + ABS(C14 > AVGC50.14) * (ABS(C15 <= AVGC50.15) * C14 + ABS(C15 > AVGC50.15) * (ABS(C16 <= AVGC50.16) * C15 + ABS(C16 > AVGC50.16) * (ABS(C17 <= AVGC50.17) * C16 + ABS(C17 > AVGC50.17) * (ABS(C18 <= AVGC50.18) * C17 + ABS(C18 > AVGC50.18) * (ABS(C19 <= AVGC50.19) * C18 + ABS(C19 > AVGC50.19) * (ABS(C20 <= AVGC50.20) * C19 + ABS(C20 > AVGC50.20) * (ABS(C21 <= AVGC50.21) * C20 + ABS(C21 > AVGC50.21) * (ABS(C22 <= AVGC50.22) * C21 + ABS(C22 > AVGC50.22) * (ABS(C23 <= AVGC50.23) * C22 + ABS(C23 > AVGC50.23) * (ABS(C24 <= AVGC50.24) * C23 + ABS(C24 > AVGC50.24) * (ABS(C25 <= AVGC50.25) * C24 + ABS(C25 > AVGC50.25) * (ABS(C26 <= AVGC50.26) * C25 + ABS(C26 > AVGC50.26) * (ABS(C27 <= AVGC50.27) * C26 + ABS(C27 > AVGC50.27) * (ABS(C28 <= AVGC50.28) * C27 + ABS(C28 > AVGC50.28) * (ABS(C29 <= AVGC50.29) * C28 + ABS(C29 > AVGC50.29) * (ABS(C30 <= AVGC50.30) * C29 + ABS(C30 > AVGC50.30) * (ABS(C31 <= AVGC50.31) * C30 + ABS(C31 > AVGC50.31) * (ABS(C32 <= AVGC50.32) * C31 + ABS(C32 > AVGC50.32) * (ABS(C33 <= AVGC50.33) * C32 + ABS(C33 > AVGC50.33) * (ABS(C34 <= AVGC50.34) * C33 + ABS(C34 > AVGC50.34) * (ABS(C35 <= AVGC50.35) * C34 + ABS(C35 > AVGC50.35) * (ABS(C36 <= AVGC50.36) * C35 + ABS(C36 > AVGC50.36) * (ABS(C37 <= AVGC50.37) * C36 + ABS(C37 > AVGC50.37) * (ABS(C38 <= AVGC50.38) * C37 + ABS(C38 > AVGC50.38) * (ABS(C39 <= AVGC50.39) * C38 + ABS(C39 > AVGC50.39) * (ABS(C40 <= AVGC50.40) * C39 + ABS(C40 > AVGC50.40) * (ABS(C41 <= AVGC50.41) * C40 + ABS(C41 > AVGC50.41) * (ABS(C42 <= AVGC50.42) * C41 + ABS(C42 > AVGC50.42) * (ABS(C43 <= AVGC50.43) * C42 + ABS(C43 > AVGC50.43) * (ABS(C44 <= AVGC50.44) * C43 + ABS(C44 > AVGC50.44) * (ABS(C45 <= AVGC50.45) * C44 + ABS(C45 > AVGC50.45) * (ABS(C46 <= AVGC50.46) * C45 + ABS(C46 > AVGC50.46) * (ABS(C47 <= AVGC50.47) * C46 + ABS(C47 > AVGC50.47) * (ABS(C48 <= AVGC50.48) * C47 + ABS(C48 > AVGC50.48) * (ABS(C49 <= AVGC50.49) * C48 + ABS(C49 > AVGC50.49) * (ABS(C50 <= AVGC50.50) * C49 + ABS(C50 > AVGC50.50) * (ABS(C51 <= AVGC50.51) * C50 + ABS(C51 > AVGC50.51))))))))))))))))))))))))))))))))))))))))))))))))))))) - 1), -1)



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
usmansajid
Posted : Tuesday, February 7, 2017 7:10:35 AM
Registered User
Joined: 3/17/2016
Posts: 48

Bruce,

Long formulas are not managable and are often messy. I spent the entire weeklend last week changing my formulas from V16 to V17 shorter versions.

 

The ability to allow C(x) or Cx to use the value returned from a function would be great.

It'd be great if it can be implemented, it would help me and many others.

 

Having said that, thanks for help. 

 

 

 

Bruce_L
Posted : Tuesday, February 7, 2017 7:15:13 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

You're welcome.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Users browsing this topic
Guest-1

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.