condition occurred in the last n bars  [SOLVED]

Questions about MultiCharts and user contributed studies.
turbofib
Posts: 213
Joined: 11 May 2013
Has thanked: 67 times
Been thanked: 1 time

condition occurred in the last n bars  [SOLVED]

Postby turbofib » 06 Sep 2014

hi,

i want to code an expression so that if it occurs in the last n bars do something

exampe:

Code: Select all



condition1=Momentum( Close, 34 )>30;

if condition1 or condition1[1] or condition1[2] or condition1[3] then do something;
how i can code it?

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: condition occurred in the last n bars

Postby TJ » 06 Sep 2014

not exactly sure what you mean...

you can give this a try:

Code: Select all


input:
Look.back(10);

var:
big.mom(0);

if Momentum( Close, 34 )>30 then
big.mom = 1
else
big.mom = 0;

if summation( big.mom, look.back ) > 0 then do something;


turbofib
Posts: 213
Joined: 11 May 2013
Has thanked: 67 times
Been thanked: 1 time

Re: condition occurred in the last n bars

Postby turbofib » 06 Sep 2014

Yes is correct, but I thought there was a native instruction to do this

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: condition occurred in the last n bars

Postby TJ » 06 Sep 2014

Yes is correct, but I thought there was a native instruction to do this
How much more native than a summation?

Another method would be using a loop to evaluate every incidence of "n".


Return to “MultiCharts”