Misunderstanding Intrabar Order Generation code?

Questions about MultiCharts and user contributed studies.
PD Quig
Posts: 191
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 67 times
Been thanked: 10 times

Misunderstanding Intrabar Order Generation code?

Postby PD Quig » 07 Feb 2011

I've written an IOG strategy that enters positions based on Bollinger Band tags (short at the upper band / long at the lower band) that works fine. Today I attempted to add a stop & reverse feature for when price begins to walk the bands--going against the open position.

The attached, distilled code shows the portion that I'm struggling with. As noted, the normal mode of generating entries is via BB band tags. A flag must = true for BB tag entries to happen but when the stop and reversal happens, this flag immediately gets set = false. But for some reason I'm still getting a BB tag long entry on the very next bar...even though there is no other statement in the code where I reset this flag = true! (except in the variable list where it is initialized to 'true').

I have put print statements in multiple places in the code stream but cannot figure out why the flag is getting reset to 'true' which causes the BB tag code block to get entered, generating the spurious long signal immediately after the reversal. I must be missing something fundamental about how IOG processes the bar data. Here's the bar data where this is happening (flag and band walk data with the print statement at the bottom of the routine):

CurrentBar= 79 MP= 1.00 BBFlag= TRUE LowerBandWalk=3
CurrentBar= 79 MP= 1.00 BBFlag= TRUE LowerBandWalk=3
CurrentBar= 79 MP= 1.00 BBFlag= TRUE LowerBandWalk=3
CurrentBar= 79 MP= 1.00 BBFlag= TRUE LowerBandWalk=3

CurrentBar= 80 MP= 1.00 BBFlag= TRUE LowerBandWalk=0
CurrentBar= 80 MP= 1.00 BBFlag= TRUE LowerBandWalk=0
CurrentBar= 80 MP= 1.00 BBFlag= FALSE LowerBandWalk=4 <<trigger reversal #1
CurrentBar= 80 MP= -1.00 BBFlag= TRUE LowerBandWalk=4 <<flag=true again!

CurrentBar= 81 MP= 1.00 BBFlag= TRUE LowerBandWalk=0 <<BB long entry
CurrentBar= 81 MP= 1.00 BBFlag= TRUE LowerBandWalk=5
CurrentBar= 81 MP= 1.00 BBFlag= FALSE LowerBandWalk=5
CurrentBar= 81 MP= 1.00 BBFlag= FALSE LowerBandWalk=5

CurrentBar= 82 MP= -1.00 BBFlag= FALSE LowerBandWalk=0 <<back to short next bar
CurrentBar= 82 MP= -1.00 BBFlag= FALSE LowerBandWalk=0
CurrentBar= 82 MP= -1.00 BBFlag= FALSE LowerBandWalk=6
CurrentBar= 82 MP= -1.00 BBFlag= FALSE LowerBandWalk=6

Help. I'm pulling my hair out.
forum_code.doc
(35 KiB) Downloaded 141 times

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

Re: Misunderstanding Intrabar Order Generation code?

Postby TJ » 08 Feb 2011

Is there any reason you want to initialize the BBFlag to True?

PD Quig
Posts: 191
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 67 times
Been thanked: 10 times

Re: Misunderstanding Intrabar Order Generation code?

Postby PD Quig » 08 Feb 2011

I want the default behavior to use BB tag entries at the start of every day. I just now changed it so it is initialized it to 'false' (since I'm setting it to 'true' the first bar of every day). Same results. I tried commenting out the statement that sets the flag to 'true.' That didn't work either. Something either very obvious or very subtle going on here. Either way, I'm missing it.

PD Quig
Posts: 191
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 67 times
Been thanked: 10 times

Re: Misunderstanding Intrabar Order Generation code?

Postby PD Quig » 08 Feb 2011

TJ,

It finally occurred to me to use intrabarpersist on BBFlag. Worked. Thanks for your help just the same...

PD


Return to “MultiCharts”