multiple entry when using multi-timeseries

Questions about MultiCharts and user contributed studies.
lawrence124
Posts: 23
Joined: 11 Oct 2012
Has thanked: 1 time

multiple entry when using multi-timeseries

Postby lawrence124 » 13 Nov 2012

hi, i used the following code for 20 sec and 5 min data on same instrument:

if condition2 then
begin
if marketposition=0 then
begin
Print(File("C:\test31.txt"),CurrentDate,",",CurrentTime,",",Time,"Buy2",",",marketposition );
buy ("Buy2") Lsize contracts next bar at market;

and this is what i see in the log:

1121113.00,1747.00, 948.00 Sell2
1121113.00,1747.00,1009.00 BuyCover2
1121113.00,1747.00,1010.00 BuyCover2
1121113.00,1747.00,1331.00 Buy2, 0.00
1121113.00,1747.00,1332.00 Buy2, 0.00

Why did "buy2" ran twice? and usually the first order for the day has no problem?
(i used the code for live trading and confirmed Buy2 did run twice during live)
Thanks!

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: multiple entry when using multi-timeseries

Postby Andrew MultiCharts » 13 Nov 2012

Hello lawrence124,

In your output we can see that 2 last lines have different time:
1121113.00,1747.00,1331.00 Buy2, 0.00
1121113.00,1747.00,1332.00 Buy2, 0.00
It means that there were 2 calculations of your script and on each of them the conditions for "print" were met.

lawrence124
Posts: 23
Joined: 11 Oct 2012
Has thanked: 1 time

Re: multiple entry when using multi-timeseries

Postby lawrence124 » 13 Nov 2012

but then, i thought i have used "marketposition=0" to bar it from entering again
as i've "buy ("Buy2") Lsize contracts next bar at market;" after the print statement, and i should have a market position at 1331, but why does it enter again at 1331 ?

User avatar
furytrader
Posts: 354
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Re: multiple entry when using multi-timeseries

Postby furytrader » 13 Nov 2012

Without being able to test your code, I can only speculate, but I think it has to do with the fact that the system may not realize that you're in a position when it places the second order. Check the value of "market position" for each of your bars (by printing it out) and see when it switches from flat to long.

One possible way to avoid this is to set a condition that is required to be true before you can place the order. When you tell the computer to "buy LSize contracts next bar at market", you can then turn this condition to false so that it won't be able to immediately send another order on the next bar. You can then turn it back to true when the correct conditions develop.

lawrence124
Posts: 23
Joined: 11 Oct 2012
Has thanked: 1 time

Re: multiple entry when using multi-timeseries

Postby lawrence124 » 13 Nov 2012

i've tried to add a counter to delay the next entry so the marketposition should be correct:

Code: Select all


Print(File("C:\test31.txt"),Time,"hi4,",canTrade );
if condition2 then
begin

Print(File("C:\test31.txt"),Time,"hi,",canTrade );
if marketposition=0 and canTrade=0 then
begin
Print(File("C:\test31.txt"),CurrentDate,",",CurrentTime,",",Time,"Buy",",",marketposition,",",canTrade );

Print(File("C:\test31.txt"),Time,"hi2,",canTrade );
canTrade=500;

Print(File("C:\test31.txt"),Time,"hi3,",canTrade );
buy ("fishBuy") Lsize contracts next bar at market;
and i got the following in log:

Code: Select all

1331.00hi4, 0.00
1331.00hi, 0.00
1121114.00, 212.00,1331.00Buy, 0.00, 0.00
1331.00hi2, 0.00
1331.00hi3, 500.00
1332.00hi4, 0.00
1332.00hi, 0.00
1121114.00, 212.00,1332.00Buy, 0.00, 0.00
1332.00hi2, 0.00
1332.00hi3, 500.00
1332.00hi4, 499.00
1332.00hi, 499.00
1332.00hi4, 498.00
somehow, the counter got reset @ 1332 for the long order from 1331, but when it enter again @ 1332, it works as expected. Any idea?

lawrence124
Posts: 23
Joined: 11 Oct 2012
Has thanked: 1 time

Re: multiple entry when using multi-timeseries

Postby lawrence124 » 13 Nov 2012

i believe i found out the cause of the problem, this issue exist whenever the 2nd series is not a multiple of 1st series, ie, issue exist if 1st series is 7seconds, and 2nd series is 1 minute, but issue gone when 1st series is 6 second and 2nd series is 1 minute

it is a normal behavior of MC? Thanks!

User avatar
furytrader
Posts: 354
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Re: multiple entry when using multi-timeseries

Postby furytrader » 13 Nov 2012

From what you're describing, that certainly sounds strange.

Could you run the same analysis, but use a timestamp with seconds (i.e., "time_s" instead of "time"). This will help confirm the sequence of events.

Also, are the results that you're seeing occurring in real-time or when you're back-testing?

lawrence124
Posts: 23
Joined: 11 Oct 2012
Has thanked: 1 time

Re: multiple entry when using multi-timeseries

Postby lawrence124 » 14 Nov 2012

first log i used 5 seconds time frame:

Code: Select all

133200.00hi, 0.00
133200.00,Buy, 0.00, 0.00
133200.00hi2, 0.00
133200.00hi3, 500.00
133205.00hi, 499.00
133210.00hi, 498.00
133215.00hi, 497.00
133220.00hi, 496.00
133225.00hi, 495.00
2nd one i used 7 seconds:

Code: Select all

133158.00hi, 0.00
133158.00,Buy, 0.00, 0.00
133158.00hi2, 0.00
133158.00hi3, 500.00
133205.00hi, 0.00
133205.00,Buy, 0.00, 0.00
133205.00hi2, 0.00
133205.00hi3, 500.00
133212.00hi, 499.00
so, signal generated around 1332, i can understand that it doesnt know it is in position by next 7 seconds, but dont know why the counter got reset after 133158.00 and before 133205

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

Re: multiple entry when using multi-timeseries

Postby TJ » 14 Nov 2012

first log i used 5 seconds time frame:

Code: Select all

133200.00hi, 0.00
133200.00,Buy, 0.00, 0.00
133200.00hi2, 0.00
133200.00hi3, 500.00
133205.00hi, 499.00
133210.00hi, 498.00
133215.00hi, 497.00
133220.00hi, 496.00
133225.00hi, 495.00
2nd one i used 7 seconds:

Code: Select all

133158.00hi, 0.00
133158.00,Buy, 0.00, 0.00
133158.00hi2, 0.00
133158.00hi3, 500.00
133205.00hi, 0.00
133205.00,Buy, 0.00, 0.00
133205.00hi2, 0.00
133205.00hi3, 500.00
133212.00hi, 499.00
so, signal generated around 1332, i can understand that it doesnt know it is in position by next 7 seconds, but dont know why the counter got reset after 133158.00 and before 133205
What is your SetMaxBarsBack ?

lawrence124
Posts: 23
Joined: 11 Oct 2012
Has thanked: 1 time

Re: multiple entry when using multi-timeseries

Postby lawrence124 » 14 Nov 2012

didnt not set it in the signal code, the environmental setting, should be the default "50"

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

Re: multiple entry when using multi-timeseries

Postby TJ » 14 Nov 2012

didnt not set it in the signal code, the environmental setting, should be the default "50"
What is needed for your code?

lawrence124
Posts: 23
Joined: 11 Oct 2012
Has thanked: 1 time

Re: multiple entry when using multi-timeseries

Postby lawrence124 » 14 Nov 2012

i changed it to 500 and changed the first series to 7 seconds, the result is still the same and i believe 500 is far more than enough.

btw, i'm using MC6, which, from what i see in "what's new with MC7: Synchronization of updates to all data series"...you believe it is the reason for the behavior as described?

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: multiple entry when using multi-timeseries

Postby Andrew MultiCharts » 17 Nov 2012

Most likely this feature will help you, but it is not present in MultiCharts 6.


Return to “MultiCharts”