How orders from Power language work

Questions about MultiCharts and user contributed studies.
Nick
Posts: 496
Joined: 04 Aug 2006
Has thanked: 4 times
Been thanked: 24 times

How orders from Power language work

Postby Nick » 30 Jul 2016

Well its a milestone day, I thought Id take a look at autotrading!

Below is a quote from TJ, is this still how things work? Is this the only option? Can I have a pair of entry orders resting at the exchange even if MC has to manage the bracket?

e.g. lets say it is with a broker/exchange that does not support OCO natively. I want to trade a range break out. My strategy places a stop to buy above the market and a stop to sell below the market.

Can I have these orders held at the broker and have multicharts cancel one when the other is filled? I'd much rather get better execution (less slipage) at the risk of maybe both getting filled (most unlikely to happen if the bracket is not too tight).

It looks like chart trader does it like this? Is it an option from power language? The quote below is 5 or so years old, does it still hold true now?

Many Thanks.

For non-IOG strategies:
Your order is only good for ONE bar.
MultiCharts evaluates your logic at the end of each bar.
If the condition meets your logic, the order is sent at the open of the next bar.
If the order is not filled at the end of next bar, and the condition is no longer met,
the order will expire. (ie. it be automatically cancelled).

For IOG strategies:
Your order is only good for ONE tick.
MultiCharts evaluates your logic every tick.
If the condition meets your logic, the order is sent at the next tick (intrabar).
If the order is not filled at the next tick, the order will expire. (ie it be automatically cancelled).
P.S. in an ideal world this would all be asynchronous. When your entry conditions are met you place your bracket. Often entry conditions do not require tick granularity only the trigger does. When anything happens to one of those orders (e.g. its filled) an event is triggered. That runs some code to deal with stops and targets. Synchronously running code every tick to see if a bracket is filled is pretty inefficient, especially if you are doing this on a dozen or so currencies or even 100s of instruments.

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: How orders from Power language work

Postby JoshM » 31 Jul 2016

e.g. lets say it is with a broker/exchange that does not support OCO natively. I want to trade a range break out. My strategy places a stop to buy above the market and a stop to sell below the market.

Can I have these orders held at the broker and have multicharts cancel one when the other is filled?
Yes. For Interactive Brokers for instance:
Simulated OCO-group means that all OCO orders are sent to the broker, price is monitored by MultiCharts and once one of the orders is filled, other orders from this OCO group are cancelled by MultiCharts. When one of the OCO orders is filled, MultiCharts sends a command to cancel the second OCO order to broker. Note that the second order may also be filled if price reaches its level before the cancellation is processed by the broker.
See: Wiki: Interactive Brokers profile.

For more, see:
OCO trading risks.
Supported order types in MultiCharts.
P.S. in an ideal world this would all be asynchronous. When your entry conditions are met you place your bracket. Often entry conditions do not require tick granularity only the trigger does. When anything happens to one of those orders (e.g. its filled) an event is triggered. That runs some code to deal with stops and targets. Synchronously running code every tick to see if a bracket is filled is pretty inefficient, especially if you are doing this on a dozen or so currencies or even 100s of instruments.
In the 'Strategy Properties' window, in the 'Auto Trading' tab, there are two options under 'Recalculate on Broker Events' that, when enabled, cause the signal to recalculate when an order is filled. That would be like your 'triggered event' you're talking about here. You can use the GetAppInfo() keyword (with `aiCalcReason` between its parentheses) to conditionally execute certain code immediately after the order filled event or market position changed event.

For the case that 'entry conditions don't require tick granularity while triggers do', you can use the BarStatus() keyword to have the script calculate more efficiently. For instance, you can have your entry trigger calculate with every tick but the remainder of your code on bar close only.
Below is a quote from TJ, is this still how things work? Is this the only option?
Yes, this is still how things work. But the quote is not about orders, it's about when the script calculates and can submit orders. The difference between intra-bar order generation and regular on-bar-close calculation is only when the script calculates, and that difference remains the same regardless of you're sending market orders, stop orders, limit orders, etc.

See the IntrabarOrderGeneration attribute for more.

Nick
Posts: 496
Joined: 04 Aug 2006
Has thanked: 4 times
Been thanked: 24 times

Re: How orders from Power language work

Postby Nick » 31 Jul 2016

Hi Josh, thank you very much for not only taking the trouble to reply in detail but providing links too. It's very much appreciated. I did spend a couple of hours trawling the wiki, and PL manual trying to get a feel for how things worked at a basic structural level. I also searched the wider internet for bits of code or how to's.

Perhaps that's a sad reflection on my ability 'how to Internet' as I get old and senile. I do feel that the MC documentation could be better indexed and grouped. For example the downloadable power language reference could have a contents section organised by type of function. The wiki could do with more tags and overview pages. And the dictionary in PL editor (imho) should be free text searchable and be liberally tagged. The quality and depth of information seems somewhat variable too (imho anyway).

Personally I found looking for the information frustrating and came away without fully understanding how autotrading worked at a fundamental level.

Anyway thanks again hopefully this might help someone else too.

#autotrading #OCO #GetAppInfo #EventDriven #OrderExecution #intrabar #:)

Nick
Posts: 496
Joined: 04 Aug 2006
Has thanked: 4 times
Been thanked: 24 times

Re: How orders from Power language work

Postby Nick » 02 Aug 2016

Do I have to use IOG to place a stop loss order on the same bar as the entry?

I get the syntax error 'This bar' can only be used in close orders. Even though it IS a close order. I am using something similar to

Code: Select all

if getappinfo(aiCalcReason)= CalcReason_OrderFilled then buytocover next bar NNN stop;
I have managed to implement all my logic so far without IOG except for this. I'd like to avoid using it if at all possible if for no other reason it freezes the PowerLanguageEditor with logging info when turned on. :)

Am I missing something here?

Thanks in advance.


Return to “MultiCharts”