NexusFi: Find Your Edge


Home Menu

 





Easylanguage OCO orders


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one RM99 with 7 posts (2 thanks)
    2. looks_two Big Mike with 4 posts (1 thanks)
    3. looks_3 SPTrading with 3 posts (2 thanks)
    4. looks_4 Jura with 2 posts (2 thanks)
      Best Posters
    1. looks_one Jura with 1 thanks per post
    2. looks_two SPTrading with 0.7 thanks per post
    3. looks_3 RM99 with 0.3 thanks per post
    4. looks_4 Big Mike with 0.3 thanks per post
    1. trending_up 24,600 views
    2. thumb_up 7 thanks given
    3. group 7 followers
    1. forum 20 posts
    2. attach_file 0 attachments




 
Search this Thread

Easylanguage OCO orders

(login for full post details)
  #1 (permalink)
chippy
Dallas, TX
 
Posts: 13 since Apr 2011
Thanks Given: 0
Thanks Received: 3

Can someone please help me find out how to do an OCO order inside easylanguage for an automated strategy? I can't seem to find the information anywhere!

thanks!

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trader Dale [email protected] or Scammer Dale
Trading Reviews and Vendors
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
Request for MACD with option to use different MAs for fa …
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Tao te Trade: way of the WLD
30 thanks
GFIs1 1 DAX trade per day journal
27 thanks
Supertradersams Thread Journal on NQ/MNQ
26 thanks
Deaddogs Stock Trading
23 thanks
Daytrading ES & NQ
12 thanks

(login for full post details)
  #2 (permalink)
 RM99 
Austin, TX
 
Experience: Advanced
Platform: TradeStation
Trading: Futures
Posts: 839 since Mar 2011
Thanks Given: 124
Thanks Received: 704


chippy View Post
Can someone please help me find out how to do an OCO order inside easylanguage for an automated strategy? I can't seem to find the information anywhere!

thanks!

Just generally speaking?

It's "inherent."

For example...
/////////////////////////////////////////////////////////////////////////////////////////////
Inputs: StopProfit(100), StopLoss(100);

If MarketPosition <> 0 then begin

setstopcontract;
setprofittarget(StopProfit);
setstopcontract;
setstoploss(StopLoss);

end;
////////////////////////////////////////////////////////////////////////////////////////////

In the above example, setstopcontract (or setstopshare) sets the following code on a "per contract" or "per share" basis. If you want to set based on the overall position basis use "setstopposition;"

You can also combine profit targets with trailing stops (there's a variety on TS).

The OSO (supplemental) order is inherent as well. You simply code for your entry and then use the if MP then.....statement to ensure you immediately enact a "supplemental" order to cover your exit.

Keep in mind that when you have more than one pending order (like a typical bracket) that it violates TS's 15 second rule, so your orders will not be maintained on the tradeserver in the event of a loss of connection. if you use a single trailing stop, without IOG=True, then your trailing stop will only update every 15 seconds by default (unless of course you turn on IOG and then it will be tick/tick). Any exit code, with IOG on violates the 15 second rule.

Hope this helps.

Reply With Quote
The following user says Thank You to RM99 for this post:
(login for full post details)
  #3 (permalink)
 
Jura's Avatar
 Jura   is a Vendor
 
Posts: 775 since Apr 2010
Thanks Given: 2,352
Thanks Received: 690



chippy View Post
Can someone please help me find out how to do an OCO order inside easylanguage for an automated strategy? I can't seem to find the information anywhere!

thanks!

Hi Chippy,

I wouldn't suggest using the following code for automated trading (it might not work), but perhaps it can get you started until more knowledgeable futures.io (formerly BMT) members chime in
 
Code
                            
vars:
    
setupCondition(false);
    
if .... 
mysetup... then
    setupCondition 
true
else
    
setupCondition false;
    
// Submit entry orders as long as the setupCondition = true *and* there is no market position
if setupCondition true and MarketPositon 0 then begin
    Buy 
("EnterLong"1 contract next bar at Highest(high10)[1limit;        // buy breakout of highest high latest 10 bars
    
Sellshort ("EnterShort"1 contract next bar at Lowest(Low10)[1limit;    // sell breakout of lowest low of latest 10 bars
end;

if 
MarketPosition 1 then begin
    
// Manage long order here
    // For example a stop below the Lowest low of the latest 10 bars
    
Sell("Stop"next bar at Lowest(Low10)[1stop;
end;

if 
MarketPosition = -1 then begin
    
// short orders
end
You can also choose to replace the MarketPosition reserved word with MarketPosition_at_broker (See PowerLanguage Help for more about this word).

Regards,

Edit: RM99 beat me to it. Funny to see the differences in approaches.

Reply With Quote
The following 2 users say Thank You to Jura for this post:
(login for full post details)
  #4 (permalink)
 RM99 
Austin, TX
 
Experience: Advanced
Platform: TradeStation
Trading: Futures
Posts: 839 since Mar 2011
Thanks Given: 124
Thanks Received: 704


Jura View Post
Hi Chippy,

I wouldn't suggest using the following code for automated trading (it might not work), but perhaps it can get you started until more knowledgeable futures.io (formerly BMT) members chime in
 
Code
                            
vars:
    
setupCondition(false);
 
if .... 
mysetup... then
    setupCondition 
true
else
    
setupCondition false;
 
// Submit entry orders as long as the setupCondition = true *and* there is no market position
if setupCondition true and MarketPositon 0 then begin
    Buy 
("EnterLong"1 contract next bar at Highest(high10)[1limit;        // buy breakout of highest high latest 10 bars
    
Sellshort ("EnterShort"1 contract next bar at Lowest(Low10)[1limit;    // sell breakout of lowest low of latest 10 bars
end;
 
if 
MarketPosition 1 then begin
    
// Manage long order here
    // For example a stop below the Lowest low of the latest 10 bars
    
Sell("Stop"next bar at Lowest(Low10)[1stop;
end;
 
if 
MarketPosition = -1 then begin
    
// short orders
end
You can also choose to replace the MarketPosition reserved word with MarketPosition_at_broker (See PowerLanguage Help for more about this word).

Regards,

Edit: RM99 beat me to it. Funny to see the differences in approaches.

In Jura's example, instead of using a fixed or "inputtable" stop order, he uses a criteria based order where...

The code searches the lowest value of the last 11 bars (10 bars previous to the last bar...[1]),.

As you can see in TS, there's virtually a limitless permutation of possibilities with respect to exits and money management.

Also take note that the order is a "stop" order....which has specific meanings in EL. It means better for entry orders and worse for exit orders (i.e. if you have a trailing stop on a long position, the stop exit order takes place at the price or worse (lower).

Reply With Quote
(login for full post details)
  #5 (permalink)
 RM99 
Austin, TX
 
Experience: Advanced
Platform: TradeStation
Trading: Futures
Posts: 839 since Mar 2011
Thanks Given: 124
Thanks Received: 704


Jura View Post
Hi Chippy,

I wouldn't suggest using the following code for automated trading (it might not work), but perhaps it can get you started until more knowledgeable futures.io (formerly BMT) members chime in
 
Code
                            
vars:
    
setupCondition(false);
 
if .... 
mysetup... then
    setupCondition 
true
else
    
setupCondition false;
 
// Submit entry orders as long as the setupCondition = true *and* there is no market position
if setupCondition true and MarketPositon 0 then begin
    Buy 
("EnterLong"1 contract next bar at Highest(high10)[1limit;        // buy breakout of highest high latest 10 bars
    
Sellshort ("EnterShort"1 contract next bar at Lowest(Low10)[1limit;    // sell breakout of lowest low of latest 10 bars
end;
 
if 
MarketPosition 1 then begin
    
// Manage long order here
    // For example a stop below the Lowest low of the latest 10 bars
    
Sell("Stop"next bar at Lowest(Low10)[1stop;
end;
 
if 
MarketPosition = -1 then begin
    
// short orders
end
You can also choose to replace the MarketPosition reserved word with MarketPosition_at_broker (See PowerLanguage Help for more about this word).

Regards,

Edit: RM99 beat me to it. Funny to see the differences in approaches.

I'm not familiar with marketposition_at_broker and I can't find it in EasyLanguage. Please esplain

Reply With Quote
(login for full post details)
  #6 (permalink)
 
Jura's Avatar
 Jura   is a Vendor
 
Posts: 775 since Apr 2010
Thanks Given: 2,352
Thanks Received: 690


RM99 View Post
I'm not familiar with marketposition_at_broker and I can't find it in EasyLanguage. Please esplain

My bad , I didn't realize the topic starter was using TradeStation instead of MultiCharts.

Here's what the MultiCharts help says about marketposition_at_broker:

Quoting 
MarketPosition_at_Broker

Returns a numerical value, indicating the type of the specified position at the broker for the symbol. A value of 1 indicates a long position, -1 indicates a short position, and 0 is returned only if the current position is specified and indicates that the current position is flat.


Usage MarketPosition_at_Broker


Notes
This function can only be used in signals and functions.
This function differs from the marketposition keyword in that it cannot take an argument to reference past values.
This function can only be used with Interactive Brokers, Patsystems, and Zen-Fire.


Example
MarketPosition_at_Broker will return a 1 if the current position at the broker for the strategy is long.
MarketPosition_at_Broker will return a -1 if the current position at the broker for the strategy is short.
MarketPosition_at_Broker will return a 0 if the current position at the broker for the strategy is flat.

With using MarketPosition_at_broker you can check, for example, if the order is executed by the broker.

Reply With Quote
(login for full post details)
  #7 (permalink)
 RM99 
Austin, TX
 
Experience: Advanced
Platform: TradeStation
Trading: Futures
Posts: 839 since Mar 2011
Thanks Given: 124
Thanks Received: 704


Jura View Post
My bad , I didn't realize the topic starter was using TradeStation instead of MultiCharts.

Here's what the MultiCharts help says about marketposition_at_broker:
With using MarketPosition_at_broker you can check, for example, if the order is executed by the broker.

Ahhh, TS addresses this issue in the setting tabs and also with GetAppInfo(aiRealTimeCalc);

Reply With Quote
(login for full post details)
  #8 (permalink)
chippy
Dallas, TX
 
Posts: 13 since Apr 2011
Thanks Given: 0
Thanks Received: 3

thanks guys! this helps

Reply With Quote
(login for full post details)
  #9 (permalink)
 SPTrading 
London, England
 
Experience: Intermediate
Platform: MC, TS, NT
Broker: TradeStation
Trading: ES
Posts: 41 since Oct 2009
Thanks Given: 12
Thanks Received: 21

In TS when you automate a strategy that has 2 exit orders, like the profit target (limit order) and stop loss (stop order), TS will only place one active order at a time, or so I thought, unless I am missing something....?

I thought this was inherent and unavoidable and of course a potentially bad situation if you get disconnected.

What happens is that trade manager will decide whether to activate the stop or the target order depending on which is closest to the price (or whether you are in profit or loss, can't remember which). This is only at best a sort of OCO order, more a "one or the other". It doesn't provide protection if you get disconnected.

The only way to get an OCO from a strategy is to issue a .placeorder macro from within the strategy, but in that case (1) many of the conventional trade management statements don't work and (2) the strategy cannot be backtested.

Reply With Quote
The following 2 users say Thank You to SPTrading for this post:
(login for full post details)
  #10 (permalink)
 RM99 
Austin, TX
 
Experience: Advanced
Platform: TradeStation
Trading: Futures
Posts: 839 since Mar 2011
Thanks Given: 124
Thanks Received: 704



SPTrading View Post
In TS when you automate a strategy that has 2 exit orders, like the profit target (limit order) and stop loss (stop order), TS will only place one active order at a time, or so I thought, unless I am missing something....?

I thought this was inherent and unavoidable and of course a potentially bad situation if you get disconnected.

What happens is that trade manager will decide whether to activate the stop or the target order depending on which is closest to the price (or whether you are in profit or loss, can't remember which). This is only at best a sort of OCO order, more a "one or the other". It doesn't provide protection if you get disconnected.

The only way to get an OCO from a strategy is to issue a .placeorder macro from within the strategy, but in that case (1) many of the conventional trade management statements don't work and (2) the strategy cannot be backtested.

Excellent points...the strategy toggles between the 2 orders, and like you, I'm not particularly familiar with the specific criteria for when it switches from one order to another.

In fairness, if you lose connection, even manually using the OCO from the matrix, the order(s) that are on the tradeserver still don't function properly. That is to say, if you enter and have a simple bracket placed out on the tradeserver, and you lose connection, whichever exit is triggered first, there's no way for the tradeserver to receive a cancellation order for the other end of the bracket.

In the end, there's really nothing that you can do to get around some of the issues with loss of connection. Even with a .placeorder, you get the orders maintained and you get temporary protection, but you still run the risk that if you're disconnected for an extended period of time, the open position can still potentially hit one of your stops, then enter a new trade based upon hitting the other stop.

I guess the only way to eliminate this issue is to simply run a singular stop (with a macro), like a trailing stop or fixed stoploss. Then use criteria based profit exits....that way if you lose connection, you're still protected by your stop, but your criteria based exits won't be active until you re-establish connection.

Reply With Quote
The following user says Thank You to RM99 for this post:





Last Updated on October 31, 2011


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts