Counting bars/days since condition=true

Questions about MultiCharts and user contributed studies.
Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Counting bars/days since condition=true

Postby Jonny473 » 22 Jun 2018

The task is about counting the bars when a condition becomes true, I want to count the number of bars or days since the condition is true (even if it becomes not true in the meantime) IN A STRATEGY. So if I would enter a trade with the condition becoming true I would probably use barssinceentry.
As I don’t buy/sell right here and just use this condition to be open for x bars I am wondering how to count from there.

Code: Select all

If condition1 then begin
count=count+1;
///count is 1 when condition became true
count1=Holdperiod-count;
///as count counting the number of bars since the condition1 is true, I am using another variable count1 . Holdperiod indicates how many bars condition1 shall be true, see below
If count1<0 then condition1=false
Unfortunately this does not work, any recommendations!?

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

Re: Counting bars/days since condition=true

Postby TJ » 22 Jun 2018

What do you mean by... (even if it becomes not true in the meantime) ?

Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Re: Counting bars/days since condition=true

Postby Jonny473 » 22 Jun 2018

What do you mean by... (even if it becomes not true in the meantime) ?
If want to count from the moment when the condition became true for the first time and then keep that condition being true for x bars, although within that time the initial condition might have turned to false (and switched back to true and so on within the time range of x bars).

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

Re: Counting bars/days since condition=true

Postby TJ » 22 Jun 2018

Look up the keyword

BarStatus

Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Re: Counting bars/days since condition=true

Postby Jonny473 » 22 Jun 2018

Ok Barstatus(0-2): 0:Open,1:Intrabar,2:Close. As this strategy is applied to Daily Bars with IntrabarCalculation I dont get your point here.

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

Re: Counting bars/days since condition=true

Postby TJ » 22 Jun 2018

Ok Barstatus(0-2): 0:Open,1:Intrabar,2:Close. As this strategy is applied to Daily Bars with IntrabarCalculation I dont get your point here.

Your mind is focused on a "Daily" strategy,
but in fact, your logic is an intra-day one, because you are making intra-day evaluations and decisions.

You need to re-orient your approach.
You might even have to re-write your logic and/or strategy.

Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Re: Counting bars/days since condition=true

Postby Jonny473 » 12 Jul 2018

Hmm good point...had some work to do sorry for the delayed answer...what I could do is just multiply the Daily Length parameters wirh the Intraday Timeframe I want to use for my Multitimeframe Strategy....what do you think?

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

Re: Counting bars/days since condition=true

Postby TJ » 12 Jul 2018

The task is about counting the bars when a condition becomes true, I want to count the number of bars or days since the condition is true (even if it becomes not true in the meantime) IN A STRATEGY. So if I would enter a trade with the condition becoming true I would probably use barssinceentry.
As I don’t buy/sell right here and just use this condition to be open for x bars I am wondering how to count from there.

Code: Select all

If condition1 then begin
count=count+1;
///count is 1 when condition became true
count1=Holdperiod-count;
///as count counting the number of bars since the condition1 is true, I am using another variable count1 . Holdperiod indicates how many bars condition1 shall be true, see below
If count1<0 then condition1=false
Unfortunately this does not work, any recommendations!?

As for the count,
1) you need to delineate the critical event -- the point that changes from condition=false to condition=true.

Code: Select all


If condition=true AND condition[1]=false then
begin
// your logic here
end;

2) you do not need to go through the count=count+1 routine.

Code: Select all

If condition=true AND condition[1]=false then
begin

COUNT = currentbar;

end;

// at a later point... number of bars since = Currentbar - COUNT

Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Re: Counting bars/days since condition=true

Postby Jonny473 » 07 Aug 2018

Sorry for the delayed reply, I had some other work to do...I might work around this issue with ADE, will give it a try.

Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Re: Counting bars/days since condition=true

Postby Jonny473 » 15 Aug 2018

Thought about this once more; the "condition" equivalent for barssinceentry if you dont have a marketposition is the MRO function.


Return to “MultiCharts”