[IOG] how to make a limit order remain active if not filled  [SOLVED]

Questions about MultiCharts and user contributed studies.
kernel
Posts: 91
Joined: 19 Feb 2013
Has thanked: 21 times
Been thanked: 4 times

[IOG] how to make a limit order remain active if not filled

Postby kernel » 20 Nov 2015

Hi,

A limit order remains active throughout the next bar or tick (if IOG on) until filled or canceled. Wonder how I can change this default behavior and not to have it canceled if not filled throughout the next bar or tick? Would it be automatically canceled if my position goes flat without it being filled at last?

Basically what I'd like to do in my IOG=true code is to send an limit order for profit target after entry, and not to have it canceled every tick and re-send every next tick if not filled (which is the default behavior), but have it remain active until it gets filled (PT gets hit) or have it canceled if my position goes flat (say, my stop loss gets hit first). May anyone kindly provide code snippet for this please?

Thanks,

-kernel
Last edited by kernel on 21 Nov 2015, edited 1 time in total.

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

Re: how to make a limit order remain active

Postby tony » 20 Nov 2015

I dealt with this a long time ago. When a limit order is generated, it is because the conditions are true but if price ticks to such a level that conditions are no longer true, the order is cancelled. You therefore need to write your code to hold a value once conditions are true and thus not cancel the limit.

kernel
Posts: 91
Joined: 19 Feb 2013
Has thanked: 21 times
Been thanked: 4 times

Re: how to make a limit order remain active

Postby kernel » 21 Nov 2015

Tony,

I guess I'm confused by how MC behaves now. Let's say you write the stop loss and profit target like this:

Code: Select all

[IntrabarOrderGeneration = TRUE]

// ..........//

if(marketPosition = 1) then begin

Sell ("longLoss")next bar at longProtStop stop;
Sell ("longProfit")next bar at longProfitStop limit;

end;
Assuming now you have a long position, as long as it remains open, the above two sell orders will be repeatedly placed and canceled (if not filled) on each every coming "tick" (IOG=true), until they get filled or the position goes flat, right?

However, this is not what I wanted it to be, what I want is: the orders are placed ONCE, and remain ACTIVE on my broker's server, until they get filled or my position goes flat.


I dealt with this a long time ago. When a limit order is generated, it is because the conditions are true but if price ticks to such a level that conditions are no longer true, the order is cancelled. You therefore need to write your code to hold a value once conditions are true and thus not cancel the limit.

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

Re: how to make a limit order remain active

Postby tony » 21 Nov 2015

In this instance MP=1 will remain true so the stop and limit order should not be cancelled. Somewhere in your code, likely the definition of longProtStop and LongProfitStop is what is causing orders to be cancelled and re-generated. Without seeing more code I can't help.

kernel
Posts: 91
Joined: 19 Feb 2013
Has thanked: 21 times
Been thanked: 4 times

Re: how to make a limit order remain active

Postby kernel » 21 Nov 2015

Taking the following code snippet as example, my confusion lies in how long the life expectancy of an order is after being placed?

(1) it will be on your broker's server and active throughout next tick (IOG=true) or bar(IOG=false), but if it is not filled throughout next tick/bar or your position closes, it will be automatically canceled. When next tick comes (take IOG=true as example), if condition1 is evaluated to be true, the order will be placed again...in this case, the order gets canceled and placed repeatedly on each coming tick as long as "condition1=true", and if not filled and you still have the position.

(2) the order will be placed once upon "condition1=true", and as long as "condition1=true", the order will remain active on your broker's server (regardless of how many ticks or bars elapse) until:
(2.1) it gets filled
(2.2) condition1 becomes false
(2.3) your position goes flat
In case of (2.2) and (2.3), the unfilled active order on your broker's server gets canceled.

Which of the above two is correct?

Code: Select all

[IntrabarOrderGeneration = TRUE]

// ..........//

if condition1 then begin

Sell ("longLoss")next bar at longProtStop stop;
Sell ("longProfit")next bar at longProfitStop limit;

end;
In this instance MP=1 will remain true so the stop and limit order should not be cancelled. Somewhere in your code, likely the definition of longProtStop and LongProfitStop is what is causing orders to be cancelled and re-generated. Without seeing more code I can't help.

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

Re: how to make a limit order remain active if not filled  [SOLVED]

Postby Henry MultiСharts » 15 Dec 2015

Hello kernel,

Second description is correct.
(2) the order will be placed once upon "condition1=true", and as long as "condition1=true", the order will remain active on your broker's server (regardless of how many ticks or bars elapse) until:
(2.1) it gets filled
(2.2) condition1 becomes false
(2.3) your position goes flat
In case of (2.2) and (2.3), the unfilled active order on your broker's server gets canceled.


Return to “MultiCharts”