Easylanguage OCO orders - EasyLanguage Programming | futures io social day trading
futures io futures trading


Easylanguage OCO orders
Updated: Views / Replies:12,686 / 20
Created: by chippy Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

Easylanguage OCO orders

  #1 (permalink)
Trading Apprentice
Dallas, TX
 
Futures Experience: Beginner
Platform: Ninja
Favorite Futures: Gold
 
Posts: 13 since Apr 2011
Thanks: 0 given, 3 received

Easylanguage OCO orders

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
 
  #2 (permalink)
Fortitudo et Honor
Austin, TX
 
Futures Experience: Advanced
Platform: TradeStation
Favorite Futures: Futures
 
Posts: 882 since Mar 2011
Thanks: 128 given, 703 received


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:
 
  #3 (permalink)
 Vendor: tradingcode.net 
The Netherlands
 
Futures Experience: None
Platform: MultiCharts, TradingView
Favorite Futures: ...
 
Jura's Avatar
 
Posts: 774 since Apr 2010
Thanks: 2,347 given, 661 received



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:
 
  #4 (permalink)
Fortitudo et Honor
Austin, TX
 
Futures Experience: Advanced
Platform: TradeStation
Favorite Futures: Futures
 
Posts: 882 since Mar 2011
Thanks: 128 given, 703 received


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
 
  #5 (permalink)
Fortitudo et Honor
Austin, TX
 
Futures Experience: Advanced
Platform: TradeStation
Favorite Futures: Futures
 
Posts: 882 since Mar 2011
Thanks: 128 given, 703 received


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
 
  #6 (permalink)
 Vendor: tradingcode.net 
The Netherlands
 
Futures Experience: None
Platform: MultiCharts, TradingView
Favorite Futures: ...
 
Jura's Avatar
 
Posts: 774 since Apr 2010
Thanks: 2,347 given, 661 received


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
 
  #7 (permalink)
Fortitudo et Honor
Austin, TX
 
Futures Experience: Advanced
Platform: TradeStation
Favorite Futures: Futures
 
Posts: 882 since Mar 2011
Thanks: 128 given, 703 received


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
 
  #8 (permalink)
Trading Apprentice
Dallas, TX
 
Futures Experience: Beginner
Platform: Ninja
Favorite Futures: Gold
 
Posts: 13 since Apr 2011
Thanks: 0 given, 3 received

thanks guys! this helps

Reply With Quote
 
  #9 (permalink)
Elite Member
London, England
 
Futures Experience: Intermediate
Platform: MC, TS, NT
Broker/Data: TradeStation
Favorite Futures: ES
 
Posts: 41 since Oct 2009
Thanks: 12 given, 18 received

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 user says Thank You to SPTrading for this post:
 
  #10 (permalink)
Fortitudo et Honor
Austin, TX
 
Futures Experience: Advanced
Platform: TradeStation
Favorite Futures: Futures
 
Posts: 882 since Mar 2011
Thanks: 128 given, 703 received



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:

Reply



futures io > > > > > Easylanguage OCO orders

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Server side synthetic orders (OCO, trailing stops) GentleTrader NinjaTrader 20 March 8th, 2014 10:40 PM
EasyLanguage, Mulitcharts and Limit Orders nismo EasyLanguage Programming 28 April 4th, 2013 06:47 AM
OCO orders from easylanguage? skan EasyLanguage Programming 2 August 13th, 2011 10:10 PM
Catching breakouts using OCO stop limit bracket orders for entries dennho Traders Hideout 4 October 1st, 2010 09:51 AM
OCO Entry Order from Strategy decs0057 NinjaTrader Programming 1 March 24th, 2010 03:48 PM


All times are GMT -4. The time now is 11:33 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-12-14 in 0.17 seconds with 19 queries on phoenix via your IP 54.227.51.103