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.
how to reference the previous bar when IOG is enabled?
Re: how to reference the previous bar when IOG is enabled?
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.
Re: how to reference the previous bar when IOG is enabled?
hi Super, thanks very much for the assistance.
so to complete the strategy, can I say:
Thanks again~
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;
Re: how to reference the previous bar when IOG is enabled?
Please correct me if I am wrong.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?
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.
Re: how to reference the previous bar when IOG is enabled?
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.
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.
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.
Re: how to reference the previous bar when IOG is enabled?
The Tick within the bar calculated the MovAvg below the MovAvg of the last bar and not the last tick.it was because somewhere within the bar the value of MovAvg became less than its previous Tick, so a sellshort order was issued.
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
Re: how to reference the previous bar when IOG is enabled?
... and even if a variable is declared as intrabarpersist.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.
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.
Re: how to reference the previous bar when IOG is enabled?
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.
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.
- TJ
- Posts: 7744
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2224 times
Re: how to reference the previous bar when IOG is enabled?
Read the fine print:
IntraBarOrderGeneration
IntraBarOrderGeneration
Re: how to reference the previous bar when IOG is enabled?
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)
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)