Bars Since

Questions about MultiCharts and user contributed studies.
kentai
Posts: 29
Joined: 02 Jun 2011
Has thanked: 9 times
Been thanked: 1 time

Bars Since

Postby kentai » 28 Oct 2011

In Metastock, there is a syntax called Barssince. This syntax is able to find out how many bars since a condition takes place. For example, bars since MACD crosses above its moving average. In Multicharts, I like to write something similar. I like to know if it is possible to write an indicator that counts the number of bars since RSI falls below 80. How to do it? I tried the code below but Multicharts hangs after I insert the indicator

Code: Select all

input: First_Period(14) Above_level(70);

variables: Barssince(0);

Barssince = 0;
While RSI(Close, First_Period) < Above_level
begin
Barssince = Barssince + 1;
end;

Plot1(Barssince, "barssince");

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

Re: Bars Since

Postby TJ » 28 Oct 2011

In Metastock, there is a syntax called Barssince. This syntax is able to find out how many bars since a condition takes place. For example, bars since MACD crosses above its moving average. In Multicharts, I like to write something similar. I like to know if it is possible to write an indicator that counts the number of bars since RSI falls below 80. How to do it? I tried the code below but Multicharts hangs after I insert the indicator

Code: Select all

input: First_Period(14) Above_level(70);

variables: Barssince(0);

Barssince = 0;
While RSI(Close, First_Period) < Above_level
begin
Barssince = Barssince + 1;
end;

Plot1(Barssince, "barssince");
you can try this:

Code: Select all

...

myRSI = RSI(Close, First_Period);

if myRSI cross above Above_Level then
Barssince = 0;

Barssince = Barssince +1;

Plot1(Barssince, "barssince");

kentai
Posts: 29
Joined: 02 Jun 2011
Has thanked: 9 times
Been thanked: 1 time

Re: Bars Since

Postby kentai » 28 Oct 2011

Thanks


Return to “MultiCharts”