How to keep alive a Limit order till filled  [SOLVED]

Questions about MultiCharts and user contributed studies.
maxmax68
Posts: 163
Joined: 20 Nov 2012
Has thanked: 55 times
Been thanked: 48 times

How to keep alive a Limit order till filled

Postby maxmax68 » 25 Mar 2013

Hi,
today on a chart timeframe 1 minute, IOG true, SA on, I tried a simple strategy that had to buy limit and sell limit.
Please someone can explain me how MC works with Limit orders?

If I well understood, MC sends to broker a Limit order that waits for filling all bar time.
At the end of the bar if not filled MC sends cancel order. Correct?

And next bar what happens ? The limit order is lost if condition no more triggered ?

How can I keep the limit order alive for more 1 minute bars without make it cancelled and resubmitted ?

I tried to change Auto Trade Strategy Properties with these results:

Replace to market partially filled orders - is ok, works at every end of bar to change to market my limit order. But it is not what I want, because I want to keep limit order for more 1 minute bars.


Unfilled strategy orders replacement on the contrary seemed not to work, because although setted to 180 seconds, limit orders were deleted on the end of the first limit order bar.

Thanks for your answers.
Massimo

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

Re: How to keep alive a Limit order till filled

Postby TJ » 25 Mar 2013

> How can I keep the limit order alive for more 1 minute bars without make it cancelled and resubmitted ?


make your logic true for more than the 1 minute bar, your order will remain alive until you make the condition "not true".

maxmax68
Posts: 163
Joined: 20 Nov 2012
Has thanked: 55 times
Been thanked: 48 times

Re: How to keep alive a Limit order till filled

Postby maxmax68 » 26 Mar 2013

Hi Tj,
sorry I am not able to understand your answer.
Please be more specific, possibly with a code example !
I'm trying to understand the logic of MC with Limit-Stop orders.
And I would like to keep a single limit order alive till filled, without having it cancelled and resubmitted on every 1 minute chart bar.
Thanks
Massimo

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

Re: How to keep alive a Limit order till filled

Postby TJ » 26 Mar 2013

Hi Tj,
sorry I am not able to understand your answer.
Please be more specific, possibly with a code example !
I'm trying to understand the logic of MC with Limit-Stop orders.
And I would like to keep a single limit order alive till filled, without having it cancelled and resubmitted on every 1 minute chart bar.
Thanks
Massimo
note:

1. IOG is designed for use with market orders.

2. please post your code, we can help you to debug.

maxmax68
Posts: 163
Joined: 20 Nov 2012
Has thanked: 55 times
Been thanked: 48 times

Re: How to keep alive a Limit order till filled

Postby maxmax68 » 26 Mar 2013

So IOG is only for Market orders, not for Limit/Stop orders ?
This means limit/stop orders are submitted only at the end of the current bar and not after every tick ?
This is the basic code I tested with the results I told you in first message.
I would like the buy or sell limit order stands till filled.
Please, make me understand the logic of MC engine, how It handles orders.
Regards
Massimo

Code: Select all

[IntrabarOrderGeneration=true]
Inputs:
vTick(0.002); // Tick value

If LastBarOnChart_s and MarketPosition_at_Broker=0 and close>high[1]+vTick then begin
buy ("LE") 1 shares next bar at high[1]-vTick limit;
end
else if LastBarOnChart_s and MarketPosition_at_Broker>0 and close<low[1]-vTick then begin
sell ("LX") 1 shares next bar at low[1]+vTick limit;
end;

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

Re: How to keep alive a Limit order till filled

Postby TJ » 26 Mar 2013

I would separate the logic from the order:

eg.

Code: Select all

//[IntrabarOrderGeneration=true]
Inputs:
vTick(0.002); // Tick value

var:
BuySell(0); // Buy = 1, Sell = -1

// --- Logic ---
if (LastBarOnChart_s and MarketPosition_at_Broker=0 and close>high[1]+vTick)
then BuySell = 1 // buy logic
else
if (LastBarOnChart_s and MarketPosition_at_Broker>0 and close<low[1]-vTick)
then BuySell = -1 // sell logic
else
BuySell = BuySell[1]; // this will make the condition stays the same until otherwise

// --- Orders ---
if BuySell = 1 then
buy ("LE") 1 shares next bar at high[1]-vTick limit
else
if BuySell = -1 then
sell ("LX") 1 shares next bar at low[1]+vTick limit;
If you need the order to execute sooner, you will need to drop down to a finer bar resolution.

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

Re: How to keep alive a Limit order till filled

Postby TJ » 26 Mar 2013

So IOG is only for Market orders, not for Limit/Stop orders ?
This means limit/stop orders are submitted only at the end of the current bar and not after every tick ?
This is the basic code I tested with the results I told you in first message.
I would like the buy or sell limit order stands till filled.
Please, make me understand the logic of MC engine, how It handles orders.
Regards
Massimo
lots of useful articles in wiki
https://www.multicharts.com/trading-sof ... acktesting
and
Autotrade / Backtest / Optimization FAQ:
viewtopic.php?f=16&t=10811

maxmax68
Posts: 163
Joined: 20 Nov 2012
Has thanked: 55 times
Been thanked: 48 times

Re: How to keep alive a Limit order till filled

Postby maxmax68 » 26 Mar 2013

TJ,
thank you for your code suggestion and for the links.
I will try to find my answers in the posts you showed me.
Regards
Massimo

maxmax68
Posts: 163
Joined: 20 Nov 2012
Has thanked: 55 times
Been thanked: 48 times

Re: How to keep alive a Limit order till filled  [SOLVED]

Postby maxmax68 » 27 Mar 2013

Hi,
today I tested a code on a 1 minute chart, SA on and IOG true.
It seems to me that IOG is good for Limit/Stop orders too, not only Market orders.
Infact the script was calculated tick by tick and Limit order was placed on the next tick,
not on next bar open !

This is what I think I understood today about Limit orders, hope it is correct:
- When condition becomes true MC submits a Limit order.
- At the end of the bar MC cancels Limit order.
- At the end of the bar, when code is recalculated, if the condition is still true and the code sends again a Limit order we have two scenarios:
- If the new Limit order is the same (price and number of shares) then the Limit order to be cancelled on the bar end, then MC keeps the old limit order, without cancelling and resubmitting a new one.
- If the new Limit order has parameters changed (price and number of shares) then the old Limit order is cancelled on the bar end, and MC submits a new limit order with new parameters.

This is the code i tested:

Code: Select all

[IntrabarOrderGeneration=true]

Inputs:
vTick(0.001); // Tick value

var:
intrabarpersist BuySell(0), // Buy = 1, Sell = -1
intrabarpersist vPrice(0); // Buy/Sell limit order price

once cleardebug;
// --- Logic ---
if (LastBarOnChart_s and MarketPosition_at_Broker=0 and close>high[1] and BuySell<1)then begin
BuySell = 1; // buy logic
vPrice=high[1]-6*vTick;
print ("BuySell=1 BUY LIMIT ",vPrice:0:3);
end else
if (LastBarOnChart_s and MarketPosition_at_Broker>0 and close<low[1]-vTick and BuySell>-1)then begin
BuySell = -1; // sell logic
vPrice=low[1]+3*vTick;
print ("BuySell=-1 SELL LIMIT ",vPrice:0:3);
end;

// --- Orders ---
if BuySell = 1 then begin
print ("BuySell=1 BUY LIMIT");
buy ("LE") 1 shares next bar at vPrice limit;
end else
if BuySell = -1 then begin
print ("BuySell=-1 SELL LIMIT");
sell ("LX") 1 shares next bar at vPrice limit;
end;
if LastBarOnChart_s then
print (time_s," - ",close:0:3," MP: ",marketposition:0:0," - MPB: ",MarketPosition_at_Broker:0:0," BuySell= ",BuySell:0:0," - vPrice= ",vPrice:0:3);
Regards
Massimo

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

Re: How to keep alive a Limit order till filled

Postby Henry MultiСharts » 28 Mar 2013

Hello maxmax68,

Your understanding is correct, except one thing (step 2):
- At the end of the bar MC cancels Limit order.
After step 1 auto trading goes to step 3 of your description.
Infact the script was calculated tick by tick and Limit order was placed on the next tick, not on next bar open !
Correct.

IOG On (tick by tick calculation)-order is generated on the current tick and sent on the next tick. That is possible to send Market and Price Next bar orders.
IOG Off (calculation on the close of the bar)-order is generated on the close of the current bar and sent on the opening tick of the next bar.

This Bar on Close order is sent on the close of the signal generation bar (disregard IOG settings). Only market orders can be sent This bar. Buy Next bar at open = Buy Next bar at Market.


Return to “MultiCharts”