data1: 1tick on underlying1
data2: 1tick on underlying2
Generally the ticks on data1 updates slower than on data2.
I want to take a position on data1 based on the data2 informations (ticks) which updates faster than data1.
I have written a code:
- it is using IOG=true and
- I disabled real time history matching
The code simplified is something like this:
Code: Select all
[IntrabarOrderGeneration = true]
variables:
intrabarpersist MM_Long_Enabled( False ),
intrabarpersist MM_Short_Enabled( False ),
intrabarpersist EnteredThisD1Bar( False ),
intrabarpersist LastBarD1( 0, data1 );
// Manages the exits each tick movement on D1
if LastBarD1 <> BarNumber of data1 then begin
LastBarD1 = BarNumber of data1;
EnteredThisD1Bar = False;
if marketposition <> 0 then begin
if marketposition = -1 then begin
Buy To Cover next bar at market;
end;
if marketposition = +1 then begin
Sell next bar at market;
end;
MM_Short_Enabled = False;
MM_Long_Enabled = False;
end;
end;
variables:
intrabarpersist MyConditionOnD2Long( 0 ),
intrabarpersist MyConditionOnD2Short( 0 );
// Set my conditions on D2
/* ... */
// Manages the entries checking each tick on D2
if EnteredThisD1Bar = False AND (MyConditionOnD2Long OR MyConditionOnD2Short) then begin
EnteredThisD1Bar = True;
print("---------");
print("Time: ", time_s/100);
print("CurrPriceD1: ", Close );
print("LastPriceD1: ", Close[1] );
print("CurrPriceD2: ", Close of data2 );
// Case long
if MyConditionOnLong then begin
MM_Long_Enabled = True;
end else
// Case short
if MyConditionOnShort then begin
MM_Short_Enabled = True;
end;
end;
// I expected that it would have entered immediately here inside one of these two following blocks without waiting for a "data1 tick update"
if MM_Short_Enabled then begin
sellshort next bar at market;
print("Sell");
end;
if MM_Long_Enabled then begin
buy next bar at market;
print("Buy");
end;
the order is executed on data1.
The backtesting is however giving me the wrong entries because it waits for the next data1 tick update.
But when I simulate using dataplayback the order prints (the "buy" and "sell" strings) are triggered at the correct tick (on data2).
So what I instead I get is that multicharts is waiting a new tick update on data1 to enter in position (even if I disabled the real time history matching) both in backtest and in live-execution.
Probably there is something that I'm missing.