Prevent multiple entries on same bar?

Questions about MultiCharts and user contributed studies.
Xyzzy
Posts: 162
Joined: 19 Mar 2011
Has thanked: 43 times
Been thanked: 79 times

Prevent multiple entries on same bar?

Postby Xyzzy » 12 Jul 2016

I'm running a strategy in the portfolio trader. I'm attempting to approximate IOG (which isn't supported in the portfolio trader) by using one-second bars as Data1 and daily bars as Data2.

I'm trying to ensure that there's only one entry per day per symbol. Currently I have code like this:

Code: Select all

[AllowSendOrdersAlways = true]
RecalcLastBarAfter(5);
...
If EntriesToday(date) = 0 then begin
Buy next bar at XX limit;
end;
Unfortunately, I had a situation this morning where one order was filled at 06:45:32:950. Just milliseconds later (at 06:45:32:962), MultiCharts transmitted a second order for the same symbol. The second order was filled a second later, so I ended up with two filled orders for this symbol instead of just one.

I'm assuming that after the first order was filled, the value for EntriesToday(date) wasn't updated until the next bar. When a new tick occurred within the same bar, the strategy didn't "know" that an order had already been filled, so it submitted the second order.

Is my understanding correct? Would anyone know of a workaround for this?

Thanks much in advance.

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

Re: Prevent multiple entries on same bar?

Postby tony » 13 Jul 2016

You can format the signal to limit entries and or exits to one per bar. I use this but also built in some back up code based on bar number. Once a position is taken whether long or short I recored that bar number and then include in my order generation statements that bar number <> current bar number. But there is a setting which should resolve your issue.

I wanted to include the back up logic in the list of statements that generate long or short entries. I had a similar situation to what you are talking about but no longer.

Xyzzy
Posts: 162
Joined: 19 Mar 2011
Has thanked: 43 times
Been thanked: 79 times

Re: Prevent multiple entries on same bar?

Postby Xyzzy » 13 Jul 2016

Thanks very much Tony. I'll give that a try.

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

Re: Prevent multiple entries on same bar?

Postby tony » 13 Jul 2016

If you add a statement(s) as back up logic aside from the settings, then I would advise putting the statement(s) in your list of conditionals that generate orders. Versus as more of a global conditional. I believe this way it is "fool proof" to not allow more than one entry on the same bar. PM me if you need help with the statements to use.

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

Re: Prevent multiple entries on same bar?

Postby Henry MultiСharts » 14 Jul 2016

Hello Xyzzy,

You can also disable pyramiding if it is not required for your strategy:
Right click on Strategy in the Portfolio tree->Show properties->Properties.
Disable the option "Allow up to N entry orders in the same direction as the currently held position".

Xyzzy
Posts: 162
Joined: 19 Mar 2011
Has thanked: 43 times
Been thanked: 79 times

Re: Prevent multiple entries on same bar?

Postby Xyzzy » 14 Jul 2016

Hi Henry,

Thanks for the suggestion. Unfortunately I do need to use pyramiding.

Specifically, I'm using second-bars for Data1 to simulate IOG, and daily bars as Data2 that are used for the actual logic of my signal. I want to pyramid into the position, but with a maximum of one entry per day.

My plan was to check if EntriesToday(date) = 0. However, the EntriesToday value doesn't get updated within the bar. I.e., if my strategy fills an order within a one-second bar, and there's another tick within that bar, then it might place another order.

Would you have any other suggestions about how to go about this? I'm still scratching my head. (I would love to use IOG, but I realize that's not supported in Portfolio Trader yet.)

User avatar
ABC
Posts: 718
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 408 times
Contact:

Re: Prevent multiple entries on same bar?

Postby ABC » 15 Jul 2016

Xyzzy,

you should be able to count fills or how many orders you let pass for the signals in the Money Management signal (where you can use IOG) and after one fill for a strategy don't let additional entries pass that day.

Regards,

ABC
Hi Henry,

Thanks for the suggestion. Unfortunately I do need to use pyramiding.

Specifically, I'm using second-bars for Data1 to simulate IOG, and daily bars as Data2 that are used for the actual logic of my signal. I want to pyramid into the position, but with a maximum of one entry per day.

My plan was to check if EntriesToday(date) = 0. However, the EntriesToday value doesn't get updated within the bar. I.e., if my strategy fills an order within a one-second bar, and there's another tick within that bar, then it might place another order.

Would you have any other suggestions about how to go about this? I'm still scratching my head. (I would love to use IOG, but I realize that's not supported in Portfolio Trader yet.)


Return to “MultiCharts”