Preventing two orders from being triggered by the same bar?

Questions about MultiCharts and user contributed studies.
jese514
Posts: 16
Joined: 11 Apr 2014
Has thanked: 2 times
Been thanked: 3 times

Preventing two orders from being triggered by the same bar?

Postby jese514 » 23 Jun 2014

I have a system that places a long and short at the same time, and is meant to only do 1 trade per day. I am experiencing a problem in which I end up with 2 trades in 1 day if one bar pierces both my long entry and short entry price.

This is my code to place orders:

Code: Select all

if EntriesToday(Date) = 0 then begin
Buy ( "LE" ) vNumShares shares next bar at vLongEntryPrice Stop;
Sellshort ( "SE" ) vNumShares shares next bar at vShortEntryPrice Stop;
end;
Perhaps this occurs because I am not currently using IntrabarOrderGeneration. If I start using IntrabarOrderGeneration, will the next tick after the first order is filled cause the other sitting order to be cancelled? Or is there some other way to 'cancel' a sitting order if EntriesToday(Date) > 0 ?

As a side note, another problem is that when I try out IntrabarOrderGeneration, I end up with different trades. I think this is because my entry prices are based on the close of a certain time. But when I use IntrabarOrderGeneration it seems to not wait for that minute to close to get the close price, it instead treats each tick as the close price... does that make sense, and if so how can I single out the close price of a specific minute when using IntrabarOrderGeneration?

Thanks!

User avatar
MAtricks
Posts: 789
Joined: 09 Apr 2012
Has thanked: 286 times
Been thanked: 288 times

Re: Preventing two orders from being triggered by the same b

Postby MAtricks » 23 Jun 2014

There are a couple issues here.

1. You need to test with Bar Magnifier ON. You have two orders and a back-tested large bar will always fill you with the optimistic result, whereas if you calculate your test with every tick, you know which order was filled first and last.

2. You're using the buy/sellshort commands. This means that if one order is filled the other will exit your position AND place another order in that direction. See my suggestion here: viewtopic.php?f=1&t=45995&hilit=matricks+1+1

You using EntriesToday(date) seems like it should fix this, but apparently its not?

We need the ability to control our orders. My suggestion is to have to ability to place either +1 contract or -1 contract along with the buy/sell/sellshort/buytocover commands which do the "work" for us.


Return to “MultiCharts”