instantaneously detecting position change in IOG code  [SOLVED]

Questions about MultiCharts and user contributed studies.
kernel
Posts: 91
Joined: 19 Feb 2013
Has thanked: 21 times
Been thanked: 4 times

instantaneously detecting position change in IOG code

Postby kernel » 17 Nov 2015

Hi,

I tried to use "currentcontracts" to detect open position change (currentcontracts change) in my IOG code but failed. The reason is, in IOG code, even you assign currentcontracts to some variable, say, CC, the assigned variable will not change until a new bar prints on chart...is there any way to be able to detect the change instantaneously without waiting for a bar to close?

Code: Select all

[IntrabarOrderGeneration = TRUE]
vars:
CC(0);
.....

CC=currentcontracts;

......

//if currentcontracts has changed
if CC<>CC[1] then begin

.......................

end;

thanks,

-kernel

tony
Posts: 420
Joined: 14 Jun 2013
Has thanked: 30 times
Been thanked: 81 times
Contact:

Re: instantaneously detecting position change in IOG code

Postby tony » 17 Nov 2015

Not 100% sure what you are trying to accomplish. If you want to know the moment you either go flat or long / short then in line with what you have, you can hold a variable at that instance and set it to whatever you want for example

If MarketPosition =0 and var1 <> 0

Then var2 = barnumber;

after the last end; so the very last part of your code you then add

var1 = marketposition;

Just an example to know the exact bar when you went flat and then hold that value for future use. When the script is calculated, var1 which is the prior MP will be referenced against the current MP and at the instance they are different, the variable var2 is held until the same conditions are true again.

kernel
Posts: 91
Joined: 19 Feb 2013
Has thanked: 21 times
Been thanked: 4 times

Re: instantaneously detecting position change in IOG code

Postby kernel » 17 Nov 2015

Hi Tony,

Basically I'm trying to find means of being able to detect my currentcontracts change instantaneously and act accordingly w/o waiting for another bar to print on chart.

This variable-assignment approach works fine when IOG=false but does not work in IOG=true code, because the variable won't get updated until next "bar" prints. I need the change gets reflected upon next "tick" coming (as in IOG code), and not to wait till next "bar" coming.

Not 100% sure what you are trying to accomplish. If you want to know the moment you either go flat or long / short then in line with what you have, you can hold a variable at that instance and set it to whatever you want for example

If MarketPosition =0 and var1 <> 0

Then var2 = barnumber;

after the last end; so the very last part of your code you then add

var1 = marketposition;

Just an example to know the exact bar when you went flat and then hold that value for future use. When the script is calculated, var1 which is the prior MP will be referenced against the current MP and at the instance they are different, the variable var2 is held until the same conditions are true again.

tony
Posts: 420
Joined: 14 Jun 2013
Has thanked: 30 times
Been thanked: 81 times
Contact:

Re: instantaneously detecting position change in IOG code

Postby tony » 17 Nov 2015

I use that very code in my own scripts which are with IOG=True. All it is doing is holding a value for MP from the prior tick when the next tick is calculated and MP changes. Trust me, it works in IOG mode.

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: instantaneously detecting position change in IOG code  [SOLVED]

Postby JoshM » 18 Nov 2015

Hi,

I tried to use "currentcontracts" to detect open position change (currentcontracts change) in my IOG code but failed. The reason is, in IOG code, even you assign currentcontracts to some variable, say, CC, the assigned variable will not change until a new bar prints on chart...is there any way to be able to detect the change instantaneously without waiting for a bar to close?

Code: Select all

[IntrabarOrderGeneration = TRUE]
vars:
CC(0);
.....

CC=currentcontracts;

......

//if currentcontracts has changed
if CC<>CC[1] then begin

.......................

end;
The `CC[1]` value returns the `CurrentContracts` value on the close of the previous bar, not the `CurrentContracts` value on the previous tick. If you want to check whether or not a position change has happened during this tick, I would try something like this:

Code: Select all

[IntrabarOrderGeneration = true];

Variables:
IntraBarPersist prevCC(0);

if (CurrentContracts <> prevCC) then begin

// Position changed

end;

// Update 'prevCC' so it's ready for
// the next script calculation
prevCC = CurrentContracts;


Return to “MultiCharts”