Data1 slower than data2, taking entries with IOG by using a data2 condition  [SOLVED]

Questions about MultiCharts and user contributed studies.
daniele.maddaluno
Posts: 4
Joined: 29 Aug 2018
Has thanked: 1 time

Data1 slower than data2, taking entries with IOG by using a data2 condition

Postby daniele.maddaluno » 12 Apr 2019

I have this configuration:

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;
What I expected from this code that I wrote and from what I see in my "Output" is that as soon as the condition is met on the data2
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.

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

Re: Data1 slower than data2, taking entries with IOG by using a data2 condition

Postby TJ » 12 Apr 2019

If data1 has no new tick, how do you expect the order to be filled?

Do you want the order to be filled at the previous tick's price?

daniele.maddaluno
Posts: 4
Joined: 29 Aug 2018
Has thanked: 1 time

Re: Data1 slower than data2, taking entries with IOG by using a data2 condition

Postby daniele.maddaluno » 12 Apr 2019

My data1 is on a CFD underlying.
I'm able to transmit the order at the proper price/tick level manually on a live demo account, so I assumed that I could do the same with an automatic signal.
So the answer to your question is yes, I would like to be filled at the previous tick's price from data1.

Here is an entry example, I manually clicked on "buy ask" (vertical blu line).
The entryprice seems to be the previous tick's price + spread.
Attachments
Q&A_Data1_Data2.PNG
(38.69 KiB) Downloaded 303 times

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Data1 slower than data2, taking entries with IOG by using a data2 condition  [SOLVED]

Postby Henry MultiСharts » 15 Apr 2019

Hello Daniele,

With IOG enabled the script calculation is triggered by a new tick. Order can be sent on the next received tick.
You will need to add the following attributes to your code to have the script recalculated on timeout, and the orders to be allowed to be sent intrabar and when BarStatus(1)=-1:
[IntrabarOrderGeneration=True]
[AllowSendOrdersAlways=True]
RecalcLastBarAfter(1);
Only a market order can be sent with [AllowSendOrdersAlways=True] when the calculation is triggered by the RecalcLastBarAfter command.

For Stop, Limit, Stop Limit orders the code will have to wait for a new real tick to come to send the order.

If you need to send exit orders intrabar – use the algorithmic exit order commands unconditionally (SetStopLoss, SetProfitTarget, etc).
In this case the exit order will sent to the broker as soon as the position is open, disregard IOG settings.

daniele.maddaluno
Posts: 4
Joined: 29 Aug 2018
Has thanked: 1 time

Re: Data1 slower than data2, taking entries with IOG by using a data2 condition

Postby daniele.maddaluno » 17 Apr 2019

Hello Henry,
I think that this is exactly what I was looking for, thank you!

The behavior in automation live and in playback seems to work as I wanted now, but what if I wanted to backtest/optimize through the classic way (the simple view-->Strategy performance report)?
The classic backtest in this moment is giving me wrong entries (even if in real and playback is fine).
Is there something to make the backtest work with this logic?

And is there some other cheats to use "Stop, Limit, Stop Limit orders"? If I understood correctly the answer should be "no", shouldn't it?

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Data1 slower than data2, taking entries with IOG by using a data2 condition

Postby Henry MultiСharts » 18 Apr 2019

Hello Henry,
I think that this is exactly what I was looking for, thank you!

The behavior in automation live and in playback seems to work as I wanted now, but what if I wanted to backtest/optimize through the classic way (the simple view-->Strategy performance report)?
The classic backtest in this moment is giving me wrong entries (even if in real and playback is fine).
Is there something to make the backtest work with this logic?
Daniele, have you tried enabling the "Realtime-history matching" option for backtesting?
And is there some other cheats to use "Stop, Limit, Stop Limit orders"? If I understood correctly the answer should be "no", shouldn't it?
There is no way to send price orders without a new tick.


Return to “MultiCharts”