"If open next bar" behaviour

Questions about MultiCharts and user contributed studies.
wilkinsw
Posts: 662
Joined: 21 Apr 2013
Has thanked: 154 times
Been thanked: 104 times

"If open next bar" behaviour

Postby wilkinsw » 15 Dec 2016

Hi,

Would someone kindly shed some light on the particulars of how "open next bar" command alters how the code is interpreted?

I have it running in some of my code, just to check that I'm going to send stop orders that won't be rejected due to a large change in the opening price of the next bar vs the close of the current bar.

However, I've noticed that it's changed the behaviour of sessionlastbar, eventough sessionlastbar and open next bar do not interact with each other in my codes logic.

By simply adding a token "open next bar" command anywhere the following happens:

Code: Select all

if sessionlastbar=true then value1=1 else value1=0

if open next bar >0 then begin
if value1=1 then buy next bar at market
end;
This will create an entry on the sessionlastbar.

If you remove "open next bar", it will create an entry on the next bar along instead.

Is that expected behaviour? So are all variables recalculated at the start of the bar if one uses "open next bar"?

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

Re: "If open next bar" behaviour

Postby Henry MultiСharts » 19 Dec 2016

Hello wilkinsw,

That is expected behavior. Using "open next bar" in your code makes it calculate on bar open, instead of bar close.

wilkinsw
Posts: 662
Joined: 21 Apr 2013
Has thanked: 154 times
Been thanked: 104 times

Re: "If open next bar" behaviour

Postby wilkinsw » 28 Nov 2017

Hi Henry,

I noticed a fixed bug in MC11:

"Fixed bug in which SessionLastBar was not working correctly in Open Next Bar mode."

How was it not working correctly? I'm not ready to upgrade to MC11 yet for my live trading. Could you shed light on what was happening in the above bug please? Is it that the sessionlastbar event isn't detectable using open next bar mode?

If I use open next bar mode in MC10, how does it impact referencing bar time?:

Code: Select all

Var: flag(false);
input: closetime(1600);//time of the last bar of the day
if time=closetime then flag=true else flag=false;

if flag=true then begin
{if open next bar >x then buy next bar at y limit}
end;
Will the next bar (the first bar of the day) generate orders, immediately (after receiving the 1st tick of the day)? Or do I need "flag[1]= TRUE" for this to happen?

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

Re: "If open next bar" behaviour

Postby Henry MultiСharts » 14 Dec 2017

Hello wilkinsw,

There was a bug when SessionLastBar command returned True value not on the actual last bar of the session, but on the one before it.
If you do not use this command in your code then you won't have this issue.


Return to “MultiCharts”