how to reference the previous bar when IOG is enabled?

Questions about MultiCharts and user contributed studies.
liang323
Posts: 30
Joined: 12 Mar 2006
Has thanked: 1 time

how to reference the previous bar when IOG is enabled?

Postby liang323 » 09 Jan 2012

Hi from what I understand, when IntraBarOrderGeneration is enabled, next bar means next tick, and 1 bar ago means 1 tick ago.

If so, how do one actually reference the previous Bar value instead of previous tick?

For example:

[IntraBarOrderGeneration = true]
If MovAvg > MovAvg [1] then
Buy 1 contract next bar at market;

when IOG is set to true, MovAvg > MovAvg[1] means the value of MovAvg is greater than the value of MovAvg 1 TICK ago, how do I make it to reference the value of MovAvg of the previous Bar instead of tick?

thanks in advance.

SUPER
Posts: 646
Joined: 03 Mar 2007
Has thanked: 106 times
Been thanked: 84 times

Re: how to reference the previous bar when IOG is enabled?

Postby SUPER » 09 Jan 2012

Hi from what I understand, when IntraBarOrderGeneration is enabled, next bar means next tick, and 1 bar ago means 1 tick ago.

If so, how do one actually reference the previous Bar value instead of previous tick?

For example:

[IntraBarOrderGeneration = true]
If MovAvg > MovAvg [1] then
Buy 1 contract next bar at market;

when IOG is set to true, MovAvg > MovAvg[1] means the value of MovAvg is greater than the value of MovAvg 1 TICK ago, how do I make it to reference the value of MovAvg of the previous Bar instead of tick?

thanks in advance.


if BarStatus(1)=2 then begin
PreviousMovAvg = MovAvg;
MovAvg= Average(C, AvgLength);
end;

Here MovAvg is Average of closed bar and PreviousMovAvg will be of a bar before it.

liang323
Posts: 30
Joined: 12 Mar 2006
Has thanked: 1 time

Re: how to reference the previous bar when IOG is enabled?

Postby liang323 » 09 Jan 2012

hi Super, thanks very much for the assistance.

so to complete the strategy, can I say:

Code: Select all

[IntraBarOrderGeneration = true]

input: AvgLength( 14 );
var: MovAvg( 0 ), PreviousMovAvg( 0 );

if BarStatus(1)=2 then begin
PreviousMovAvg = MovAvg;
MovAvg= Average(C, AvgLength);
end;

if MovAvg > PreviousMovAvg then
buy 1 contract next bar at market;
Thanks again~

SUPER
Posts: 646
Joined: 03 Mar 2007
Has thanked: 106 times
Been thanked: 84 times

Re: how to reference the previous bar when IOG is enabled?

Postby SUPER » 09 Jan 2012

Yes, that looks fine.

liang323
Posts: 30
Joined: 12 Mar 2006
Has thanked: 1 time

Re: how to reference the previous bar when IOG is enabled?

Postby liang323 » 09 Jan 2012

Thanks for the help buddy!

cheers.

User avatar
siscop
Posts: 197
Joined: 09 Jan 2011
Has thanked: 34 times
Been thanked: 29 times

Re: how to reference the previous bar when IOG is enabled?

Postby siscop » 09 Jan 2012

when IOG is set to true, MovAvg > MovAvg[1] means the value of MovAvg is greater than the value of MovAvg 1 TICK ago, how do I make it to reference the value of MovAvg of the previous Bar instead of tick?
Please correct me if I am wrong.
AFAIK MovAvg[1] is always the previous bar and not the previous tick. It doesnt matter if IOG is active when variables are not intrabarpersist. All variables (at the begining of the loop) are set to back to the value of the last close point of the last bar and not of the last TICK.
So your code from your first post should be fine.
It is a total different situation when your variables are intrabarpersist.

liang323
Posts: 30
Joined: 12 Mar 2006
Has thanked: 1 time

Re: how to reference the previous bar when IOG is enabled?

Postby liang323 » 10 Jan 2012

hi Siscop, thanks for the reply. I did a backtest of a sample strategy based on MovAvg to see whether it's referencing the previous bar or previous tick. When IOG is enabled, and MovAvg > MovAvg[1] gives a result that tick value is used instead of the close of last bar.
sample1.jpg
(109.33 KiB) Downloaded 994 times

Code: Select all

[IntrabarOrderGeneration = true]
inputs: Price( Close ), Length( 9 ), Displace( 0 ) ;
variables: MovAvg( 0 ) ;

MovAvg = AverageFC( Price, Length ) ;

if marketposition <= 0 and MovAvg > MovAvg[1] then
buy 1 contract next bar at market;

if marketposition >= 0 and MovAvg < MovAvg[1] then
sellshort 1 contract next bar at market;

Please see the attached image, i marked it with blue square, the Cyan MovAvg is greater than the previous bar, yet a short entry was made, it was because somewhere within the bar the value of MovAvg became less than its previous Tick, so a sellshort order was issued.

let me know what you think.

Cheers.

User avatar
siscop
Posts: 197
Joined: 09 Jan 2011
Has thanked: 34 times
Been thanked: 29 times

Re: how to reference the previous bar when IOG is enabled?

Postby siscop » 10 Jan 2012

it was because somewhere within the bar the value of MovAvg became less than its previous Tick, so a sellshort order was issued.
The Tick within the bar calculated the MovAvg below the MovAvg of the last bar and not the last tick.
You should check that via a Print command.
Print ("MA[1]: ",MovAvg[1]," Time[1]: ",Time[1]," MA: ",MovAvg," Time: ",Time);


If Time == Time[1] -> you are right
If Time!= Time[1] -> I am right
or
if MovAvg[1] differs within a bar then you are right since it should have the same value within a bar

Squib
Posts: 17
Joined: 25 Nov 2011
Has thanked: 19 times
Been thanked: 6 times

Re: how to reference the previous bar when IOG is enabled?

Postby Squib » 10 Jan 2012

Please correct me if I am wrong.
AFAIK MovAvg[1] is always the previous bar and not the previous tick. It doesnt matter if IOG is active when variables are not intrabarpersist. All variables (at the begining of the loop) are set to back to the value of the last close point of the last bar and not of the last TICK.
So your code from your first post should be fine.
It is a total different situation when your variables are intrabarpersist.
... and even if a variable is declared as intrabarpersist.
variable[1] is always the variable value of the previous bar and not the previous tick. Independent on IOG or intrabarpersist. To access the value of a previous tick, you have to store it before in another variable.

liang323
Posts: 30
Joined: 12 Mar 2006
Has thanked: 1 time

Re: how to reference the previous bar when IOG is enabled?

Postby liang323 » 10 Jan 2012

Hi siscop and squid, thank you for the clarification.

so when IOG is enabled, variable[1] is the variable value of the previous bar and not the previous tick. When "sell next bar at market" is used, it means sell at next tick, only for the purpose of intra bar order execution.

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

Re: how to reference the previous bar when IOG is enabled?

Postby TJ » 10 Jan 2012

Read the fine print:

IntraBarOrderGeneration

User avatar
c0ntango
Posts: 70
Joined: 13 Sep 2018
Has thanked: 3 times
Been thanked: 16 times
Contact:

Re: how to reference the previous bar when IOG is enabled?

Postby c0ntango » 19 Nov 2020

Hey guys,

Thread from 2012 - this post may not be super useful but thought I'd share I came across this quesiton as well, and instead of trying to understand the code and the answers in this thread I propose the simplest way to understand more about the behavior of IOG, try this with IOG set to True and then to False:

if LastBarOnChart then begin
print(symbolname, close[50]:6:6);
print(symbolname, close[20]:6:6);
print(symbolname, close[10]:6:6);
end;

You can do it with other functions or indicators you want to use, and try it with/without setting them on intrabarpersist as well - it should give you all the answers you're looking for.

(The answer, by the way, is: IOG does not update time series array references like close[20] on every tick)


Return to “MultiCharts”