IOG with Stop limit order

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
allenlowe
Posts: 37
Joined: 29 Jun 2011
Has thanked: 2 times
Been thanked: 3 times

IOG with Stop limit order

Postby allenlowe » 29 Apr 2012

Dear All,

I am using 1 min bar with IOG on for my trade. Also, I have turned on the "limit to market order" with a setting of 5 seconds. My strategy is very simple.

Code: Select all

If condition1 then
begin
Buy ("Strategy 1") 1 next bar Price1 stop Price1 limit;
end;
if condition2 then
begin
Sell (Strategy 2") 1 next bar Price2 stop Price2 limit;
end;
The reason I am using stop order is that if I don't use it, the backtesting not working well.
The reason I am using limit order because the bid/ask spread is quite big for what I am trading.

It works fine except..... the last few second of the bar. I have an order generated at 10:56:59 and then cancelled at 10:57:01 without trigger the "Limit to Market order" function of MC. Are there any code to change the "Limit to Market Order" within the coding. Or I have to rewrite my whole strategy with seperate coding for the last 5 seconds of every minute.

I understand there are a lot of EL experts here may indicate a direction for me.

Thanks a lot.

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

Re: IOG with Stop limit order

Postby JoshM » 02 May 2012

(..) I have turned on the "limit to market order" with a setting of 5 seconds.

(..)

The reason I am using limit order because the bid/ask spread is quite big for what I am trading.

It works fine except..... the last few second of the bar. I have an order generated at 10:56:59 and then cancelled at 10:57:01 without trigger the "Limit to Market order" function of MC. Are there any code to change the "Limit to Market Order" within the coding.
I don't know of a way to 'control' the "Limit to Market Order" in PowerLanguage, but wouldn't a solution/work-around be to increase the 'convert limit to market order in x-seconds' setting to a higher value?

Btw, if you're trading an instrument with a wide bid/ask spread, why do you want to convert limit orders after 5 seconds to a market order? If it's lightly traded, it might be an option to just change the limit price if the order isn't filled x-seconds after signal generation, thus giving better control over slippage that way.

allenlowe
Posts: 37
Joined: 29 Jun 2011
Has thanked: 2 times
Been thanked: 3 times

Re: IOG with Stop limit order

Postby allenlowe » 02 May 2012

Increase the setting X-second wouldn't be a solution. Because the order cancel automatically at the end of the bar. Therefore, if the order generated at 10:56:59, it will automatically cancel next second no matter how many second I set in my limit to order setting.

I think change the limit price after x second can also be a good replacement for "limit to order". However, the problem of automatically cancel will still happen at the end of a bar. Therefore, I still need to rewrite the code to handle signal generated during the last few second of a minute bar. I would like to get the opinions of how other MC users will deal with this before start my coding.

Thanks.

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

Re: IOG with Stop limit order

Postby JoshM » 02 May 2012

Increase the setting X-second wouldn't be a solution. Because the order cancel automatically at the end of the bar. Therefore, if the order generated at 10:56:59, it will automatically cancel next second no matter how many second I set in my limit to order setting.

I think change the limit price after x second can also be a good replacement for "limit to order". However, the problem of automatically cancel will still happen at the end of a bar. Therefore, I still need to rewrite the code to handle signal generated during the last few second of a minute bar. I would like to get the opinions of how other MC users will deal with this before start my coding.
Ow I see, it's a coding related issue instead of setting issue with 'convert market to limit'.

Very simplified, I do the following: a) evaluate entry logic on bar close, b) determine if there is a long or short signal, c) calculate the limit price, d) submit the limit order intrabar as long as the enter long or enter short conditions are true and there isn't yet a position.

Like the following:

Code: Select all

if (BarStatus(1) = 2) then begin

if (MarketPosition(0) = 0) then begin

enterLong = ...
enterShort = ...

if (enterLong = True) then
ELPrice = High; // limit price

if (enterShort = True) then
ESPrice = Low;
end //: no MarketPosition

end; //: BarStatus(1) = 2

// Entries intrabar
if (MarketPosition(0) = 0) then begin

if (enterLong = True) then
Buy ("EL Limit") posSize contracts next bar at ELPrice limit;

if (enterShort = True) then
SellShort ("ES Limit") posSize contracts next bar at ESPrice limit;

end; //: No MarketPosition Intrabar

allenlowe
Posts: 37
Joined: 29 Jun 2011
Has thanked: 2 times
Been thanked: 3 times

Re: IOG with Stop limit order

Postby allenlowe » 02 May 2012

Thanks a lot.

I am new to MC and chart trading programming. Never think of separate the signal and the coding for buying. You are right that if I separate like this, the problem should be solved.

My original order was based on the moving average of minute bar and other indicator to create limit for buy and sell. A bit more complicated than my example and 3 different condition for buying and selling. However, due to interactive broker say I have too many order cancellation and I have to modify my code to use intra-bar order generation.

I think I need to use my whole weekend to think of and re-write my coding.

Thanks again.


Return to “User Contributed Studies and Indicator Library”