OCO group for entry

Questions about MultiCharts and user contributed studies.
steven
Posts: 37
Joined: 07 Jun 2010
Location: china
Has thanked: 2 times

OCO group for entry

Postby steven » 20 May 2011

Dear TS,

For OCO group, may I use below code for entry?

Code: Select all

if marketposition = 0 then
begin
buy("BUY") next bar close+10 stop;
sellshort("Sell") next bar close-1 stop;
end;

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

Re: OCO group for entry

Postby TJ » 20 May 2011

Dear TS,

For OCO group, may I use below code for entry?

Code: Select all

if marketposition = 0 then
begin
buy("BUY") next bar close+10 stop;
sellshort("Sell") next bar close-1 stop;
end;
OCO mean one cancels the other.

if your condition is met in bar #1, the order will be posted at the beginning of bar #2.
during bar #2, if your BUY order is filled, how do you suppose to cancel the sell order?

steven
Posts: 37
Joined: 07 Jun 2010
Location: china
Has thanked: 2 times

Re: OCO group for entry

Postby steven » 20 May 2011

Dear TJ,

what I supposed is when the condition is met in bar#1, both buy and sell orders was posted in the beginning of bar#2, if the buy order was filled during the bar#2, then canncel the sell one.

I saw your guide about the OCO, the sample code just for order closure, is that means it can be only used in order closure, can not use in order initiate?

Steven

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

Re: OCO group for entry

Postby TJ » 20 May 2011

Dear TJ,

what I supposed is when the condition is met in bar#1, both buy and sell orders was posted in the beginning of bar#2, if the buy order was filled during the bar#2, then canncel the sell one.

I saw your guide about the OCO, the sample code just for order closure, is that means it can be only used in order closure, can not use in order initiate?

Steven
If you posted an order to the broker, it will stay there for the bar, or until withdrawn.
If you want to withdraw an order before the end of the bar, you have to write the code to do so.

The "set-exit-type" orders are different from REGULAR orders, they are part of the Strategy Engine.
ie. these orders are posted to broker when there is a position,
and AUTOMATICALLY withdrawn if the position no longer exists.

note for general audience: please see post #3
viewtopic.php?f=16&t=6929

steven
Posts: 37
Joined: 07 Jun 2010
Location: china
Has thanked: 2 times

Re: OCO group for entry

Postby steven » 23 May 2011

Dear TJ,

Thanks for the reply, I've read your post for OCO usage, it's just for "set-exit-type" orders ,
Is that means OCO cannot work for REGULAR orders?

Steven

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

Re: OCO group for entry

Postby TJ » 23 May 2011

Dear TJ,

Thanks for the reply, I've read your post for OCO usage, it's just for "set-exit-type" orders ,
Is that means OCO cannot work for REGULAR orders?

Steven
I don't quite understand what you mean.
If you want to cancel an order, you have to let your broker know.
ie. you have to code the instruction into your strategy.

steven
Posts: 37
Joined: 07 Jun 2010
Location: china
Has thanked: 2 times

Re: OCO group for entry

Postby steven » 24 May 2011

let me make it simple, May I use below codes to implentment OCO?
If not, can you tell the exactly behaviors for below 2 codes?

code 1, entry with OCO:
expectation: "buy" and "sell" orders are posted at the same time, when anyone of them was filled, cancel the other one.

Code: Select all

if marketposition = 0 then
begin
buy("BUY") next bar close+10 stop;
sellshort("Sell") next bar close-1 stop;
end;
code 2: exit with OCO:
expectation: After the long position was created, fire "s1" and "s2", when anyone of them was filled, cancel the other one.

Code: Select all

If Condition = true then
Begin
Buy ("B") next bar at Market;
End ;
sell ("s1") next bar at entryprice+10 stop;
sell ("s2") next bar at entryprice-1 stop;
Last edited by steven on 24 May 2011, edited 1 time in total.

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

Re: OCO group for entry

Postby TJ » 24 May 2011

let me make it simple, May I use below codes to implentment OCO?

...
OCO means One Cancel Other.

You have not specified what do you want to cancel in your code.

Computers are dumb; they will only do what you tell it to do.

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

Re: OCO group for entry

Postby TJ » 24 May 2011

have you read this section?

EasyLanguage Essentials Programmers Guide
Built-in Stops.......... pg. 90

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

Re: OCO group for entry

Postby TJ » 24 May 2011

... can you tell the exactly behaviors for below 2 codes?
...
I would suggest you to try out InteractiveBrokers demo system.
It has a full service order manage system, is free, and does not require registration.

steven
Posts: 37
Joined: 07 Jun 2010
Location: china
Has thanked: 2 times

Re: OCO group for entry

Postby steven » 24 May 2011

Dear TJ,

I've add the "expectation" in my post, pls check.
Coz i'm the china agent(TOUCHANCE) of MC, we want to let our users to use this function, so I need the exactly info to pass to our engineers for implement. we donnt use IB .

Steven

steven
Posts: 37
Joined: 07 Jun 2010
Location: china
Has thanked: 2 times

Re: OCO group for entry

Postby steven » 24 May 2011

have you read this section?

EasyLanguage Essentials Programmers Guide
Built-in Stops.......... pg. 90

i have read that, for set-exit-order, it works fine with TOUCHANCE plugin.

Steven

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

Re: OCO group for entry

Postby TJ » 24 May 2011

let me make it simple, May I use below codes to implentment OCO?
If not, can you tell the exactly behaviors for below 2 codes?

code 1, entry with OCO:
expectation: "buy" and "sell" orders are posted at the same time, when anyone of them was filled, cancel the other one.

Code: Select all

if marketposition = 0 then
begin
buy("BUY") next bar close+10 stop;
sellshort("Sell") next bar close-1 stop;
end;
with the above code,
1. the orders will be effective for one bar. At the end of the bar, if none of the conditions are met, the orders will be cancelled.
2. If the buy order is hit, the sellshort order will still sit there until the bar is closed.
3. if the buy order is hit, then the sellshort order is hit in the same bar, the sellshort order will sell 2 contracts for you, and you will ended up with one short position.
4. if you want to cancel one order after the other is filled, you will need to write codes to that effect.

I would suggest you to read through the ebooks here:
https://www.multicharts.com/multicharts ... mentation/

You should work through the exercises and examples in each section; they are very easy to understand.

steven
Posts: 37
Joined: 07 Jun 2010
Location: china
Has thanked: 2 times

Re: OCO group for entry

Postby steven » 24 May 2011

with the above code,
1. the orders will be effective for one bar. At the end of the bar, if none of the conditions are met, the orders will be cancelled.
2. If the buy order is hit, the sellshort order will still sit there until the bar is closed.
3. if the buy order is hit, then the sellshort order is hit in the same bar, the sellshort order will sell 2 contracts for you, and you will ended up with one short position.
4. if you want to cancel one order after the other is filled, you will need to write codes to that effect.

I would suggest you to read through the ebooks here:
https://www.multicharts.com/multicharts ... mentation/

You should work through the exercises and examples in each section; they are very easy to understand.
Thanks for the info, I got that, what about the code 2?
another extra request: you said "you will need to write codes to that effect.", could you please give me a sample?

Steven

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

Re: OCO group for entry

Postby TJ » 24 May 2011

with the above code,
1. the orders will be effective for one bar. At the end of the bar, if none of the conditions are met, the orders will be cancelled.
2. If the buy order is hit, the sellshort order will still sit there until the bar is closed.
3. if the buy order is hit, then the sellshort order is hit in the same bar, the sellshort order will sell 2 contracts for you, and you will ended up with one short position.
4. if you want to cancel one order after the other is filled, you will need to write codes to that effect.

I would suggest you to read through the ebooks here:
https://www.multicharts.com/multicharts ... mentation/

You should work through the exercises and examples in each section; they are very easy to understand.
Thanks for the info, I got that, what about the code 2?
another extra request: you said "you will need to write codes to that effect.", could you please give me a sample?

Steven
You have not read the manual
What I have described above are just a repeat of the manual.
You have to read the manual first, before I can help you further.

EasyLanguage Essentials Programmers Guide
Creating Trading Strategies ... pg 79


Return to “MultiCharts”