Tuesday, June 2, 2009

Code example for referencing TOS studies for a readers email

A reader wrote in and asked a question. I'm not sure if I understood exactly what my reader wanted to do but here is one example of leveraging TOS studies.

Reference SimpleMovingAvg(length=21). That would return the SMA value for that bar. If the SMA(21) was less than the close of that bar it would print a point at the specified value.

insideBar.setHiding( if(close > reference SimpleMovingAvg(length=21),1,0));

So if(close > reference SimpleMovingAvg(length=21),1,0)) says that if close > SMA(21) then return true, else return false. Return value true activates the Hide function, return value 0 does not activate it.

(Thanks for the email. I hope you don't mind me sharing a portion of it so all can learn. Best regards, Freethinkscript).

input offset = 1 ;
plot InsideBar = if close < close[1] then high + offset else double.NaN;

insideBar.setHiding( if(close > reference SimpleMovingAvg(length=21),1,0));
blog comments powered by Disqus