PL - Barssince  [SOLVED]

Questions about MultiCharts and user contributed studies.
Try
Posts: 3
Joined: 17 Apr 2013

PL - Barssince

Postby Try » 06 May 2013

Hi
I have a problem with a Study where I'm trying to identify the number of bars since the last time price closed below an exponential moving average. I only get the total number of bars in the dataset as result of the study.

Code: Select all

Input:
LowPrice (Low),
EMALength (20),
Price (close);


variables:
barssince (0),
_EMA_low (0);

_EMA_low = XAverage (EMALength, Lowprice);

if price < _EMA_low then
value1 = value1 + 1

else
value1 = 0;

condition1 = value1 >= 1;

if condition1 then

barssince = 0;

barssince = barssince + 1;

Plot1(barssince, "barssinceDn");
I managed to get it right when the study aimed to identify the number of bars since last time we saw three consecutive ups.

Code: Select all

inputs:
Price( Close ),
ConsecutiveBarsUp( 3 );

variables:
barssince2 (0);



if Price > Price[1] then
Value1 = Value1 + 1

else
Value1 = 0 ;

condition1= Value1 >= ConsecutiveBarsUp ;

if condition1 then
barssince2 = 0;

barssince2 = barssince2 +1;

Plot1(barssince2, "barssince");

I would appreciate any help that would get the first of my two studies to work.

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

Re: PL - Barssince

Postby TJ » 06 May 2013

Hi
I have a problem with a Study where I'm trying to identify the number of bars since the last time price closed below an exponential moving average. I only get the total number of bars in the dataset as result of the study.
....
I managed to get it right when the study aimed to identify the number of bars since last time we saw three consecutive ups.
....

I would appreciate any help that would get the first of my two studies to work.
What is your problem?
What is the purpose of the indicator? You have not specified it clearly.

Can you post a screenshot (with notes) to illustrate your problem?

Try
Posts: 3
Joined: 17 Apr 2013

Re: PL - Barssince

Postby Try » 07 May 2013

Sorry for not explaining my problem too well.

The study _testindicator (upper subchart in the screenshot - see attachment) returns the number of bars since most recent reading of 3 consecutive ups (The lower code in my first post from 6th of May).

The Upper code in my first post from 6th of May, aims to return the number of bars since the most recent bar closing below the exponential moving average as described in the PL-code (The red bars in the screenshot/image).
As you see from _testindicator2 in the lower subchart it returns the total number of bars in the dataset. I want the study to return the number of bars since the most recent bar closing below the exponential moving average.

Hope this makes more sense.
Attachments
MC_PrintScreen.png
(118.28 KiB) Downloaded 767 times

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: PL - Barssince  [SOLVED]

Postby Henry MultiСharts » 07 May 2013

Hello Try,

In the code of your top study (_Testindicator2) you need to change the order of the XAverage function inputs as the following:

Code: Select all

_EMA_low = XAverage (Lowprice, EMALength);

Try
Posts: 3
Joined: 17 Apr 2013

Re: PL - Barssince

Postby Try » 07 May 2013

Thanks so much. Somewwhat embarrassed here.

Thanks again.


Return to “MultiCharts”