EasyLanguage Collective2 Interface (MultiCharts to Collective 2) - futures io
futures io



EasyLanguage Collective2 Interface (MultiCharts to Collective 2)


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one Big Mike with 18 posts (12 thanks)
    2. looks_two gpw797 with 5 posts (0 thanks)
    3. looks_3 bomberone1 with 4 posts (0 thanks)
    4. looks_4 NicoVersailles with 3 posts (0 thanks)
    1. trending_up 20,378 views
    2. thumb_up 14 thanks given
    3. group 13 followers
    1. forum 41 posts
    2. attach_file 0 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
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

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

 
Search this Thread
 

EasyLanguage Collective2 Interface (MultiCharts to Collective 2)

(login for full post details)
  #1 (permalink)
 Big Mike 
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: Custom solution
Trading: Futures & Crypto
 
Big Mike's Avatar
 
Posts: 50,127 since Jun 2009
Thanks: 32,599 given, 98,768 received

I found myself needing an EasyLanguage way to submit orders to Collective2. If you aren't familiar with C2, you should check it out:

Find the trading strategy best for you

Their top performing systems earn about $10k a month.

So, I could write a C++ DLL interface, and write my own URL-fetching routines, my own XML parser, and more but it's late so I decided to see what I could hack out in an hour of "old school" methods.

I decided the easiest thing to do would be to write a Collective2 function, that I can call from my signal. The function will then build the proper query and output to a text file the URL query. From there, wget for Windows (free, GNU) seemed like the easiest way to execute the URL query without using C++.

Signal
Call C2 Function where Buy and Sellshort commands are used.

Function
Build URL query and output to text file.

DOS
Use a batch file to check for a new text file (new signal generated), then use wget to execute the signal (URL query).

I built the function using the Signal API guidelines from Collective 2:
C2 Signal Entry API

If there is interest in this, please let me know and I'll post the code on the condition you have an existing C2 system in place and will help me test it

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/

Visit other sites? Please spread the word about your experience with our community!
Follow me on Twitter Visit my futures io Trade Journal Started this thread Reply With Quote
The following 8 users say Thank You to Big Mike for this post:

Can you help answer these questions
from other members on futures io?
uptick/downtick vs bid/ask
NinjaTrader
Script to add a moving average
ThinkOrSwim
MacdBB V402 NT804 + gradient + pullback not working on N …
NinjaTrader
Tradestation order types - help
TradeStation
Eurex Denali vs dxFeed
Sierra Chart
 
Best Threads (Most Thanked)
in the last 7 days on futures io
Question about intraday margins
52 thanks
How quickly do algos go bad?
45 thanks
ZombiePack3 Indicators
19 thanks
Webinar: Building a System for Trading Psychology w/Jare …
18 thanks
Want your NinjaTrader indicator created, free?
15 thanks
 
(login for full post details)
  #3 (permalink)
 Big Mike 
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: Custom solution
Trading: Futures & Crypto
 
Big Mike's Avatar
 
Posts: 50,127 since Jun 2009
Thanks: 32,599 given, 98,768 received


I should also add that my method supports limit orders, stop orders (for entry), profit targets and stops (stop loss).

This is a big improvement over the limited functionality built-in to NinjaTrader with C2, as NT only submits market orders as they are filled.

With my function you can submit your profit target and stop loss orders, which are OCO, at the time of entry. You can also specify a limit order or a buy stop ahead of time to prevent slippage, which is a big issue with C2 systems in a volatile market.

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/

Visit other sites? Please spread the word about your experience with our community!
Follow me on Twitter Visit my futures io Trade Journal Started this thread Reply With Quote
 
(login for full post details)
  #4 (permalink)
 phyzfer 
Chicago
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus/Zen-FIre
Trading: GC, ES
 
Posts: 73 since Mar 2010
Thanks: 40 given, 33 received

BM,

I'm not quite sure I understand the purpose of this. Is your NT-C2 'connector' going to listen to C2 orders and place orders using NT? Or are you creating a strategy that will be hosted on C2 and need to know how to broadcast signals out?

thanks-

Reply With Quote
 
(login for full post details)
  #5 (permalink)
 Big Mike 
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: Custom solution
Trading: Futures & Crypto
 
Big Mike's Avatar
 
Posts: 50,127 since Jun 2009
Thanks: 32,599 given, 98,768 received


phyzfer View Post
BM,

I'm not quite sure I understand the purpose of this. Is your NT-C2 'connector' going to listen to C2 orders and place orders using NT? Or are you creating a strategy that will be hosted on C2 and need to know how to broadcast signals out?

thanks-

Take NT out of the equation, I was just listing the C2 support in NT for comparison only.

Yes, the purpose of this is for any EasyLanguage user to be able to send orders to their C2 strategies and specify stops, targets, etc. To my knowledge, the only apps/interfaces so far for TradeStation don't let you specify stops and targets or place orders ahead of time with limit orders (just like NT doesn't), and also they don't work with MultiCharts at all.

So I figured there was a need for this.

If you are trying to autotrade a C2 strategy as a client, that is not what this is for.

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/

Visit other sites? Please spread the word about your experience with our community!
Follow me on Twitter Visit my futures io Trade Journal Started this thread Reply With Quote
 
(login for full post details)
  #6 (permalink)
 Big Mike 
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: Custom solution
Trading: Futures & Crypto
 
Big Mike's Avatar
 
Posts: 50,127 since Jun 2009
Thanks: 32,599 given, 98,768 received

Ok here is the function code. I've not tested the buy stop and sell stop, but I have tested everything else and to my knowledge it all works as expected. Please make improvements and contribute them back to the community.

 
Code
                            
// Big Mike Trading https://futures.io

// Apr 5 2010

http://www.collective2.com/content/automationEncloser.htm }

{
Parameter      Value or Example      What it Means      Comments
cmd
=     signal            
systemid
=     123456     The system ID displayed as above.      
pw=     loginPassword           case sensitive
action
=     BTO     Buy To Open     open a long position
    SSHORT     Sell Short     used 
for stocks
    STO     Sell To Open     used 
for non-stocks
    BTC     Buy To Close     close a short position
    STC     Sell To Close     close a long position
quant
=     100     Number of shares or contracts      
instrument
=     stock           Note that ETFs like QQQ and DIA are traded on a stock exchange and thus are considered stocks.
      
option            
      future            
      forex            
symbol
=     IBM           You are responsible for looking up your own symbols. If you trade Forexyou know that Collective2 figures out Forex symbols automatically when you manually enter trades on the Web siteHoweveryou'll need to enter already-valid symbols when using the Web service interface. 
limit=     35.06           Only use if this is a limit order.
stop=     20.10           Only use if this is a stop order. For market orders, do not use either stop or limit parameters.
duration=     DAY     Day Order      
      GTC     Good Til Cancel      

}

{
The URL is in the following format:

http://www.collective2. com/cgi-perl/signal. mpl?[PARAMETERS]
}

inputs:
    cmd ( StringSimple ), { signal, closeallpositions }
    systemid ( NumericSimple ), { c2 system id }
    pw ( StringSimple ), { c2 password for said id }
    action ( StringSimple ), { BTO, SSHORT, STO, BTC, STC }
    quant ( NumericSimple ), { order quantity }
    instrument ( StringSimple ), { stock, option, future, forex }
    c2symbol ( StringSimple ), { symbol for instrument }
    c2limit ( NumericSimple ), { optional }
    c2stop ( NumericSimple ), { optional buy stop/sell stop }
    c2target ( NumericSimple ), { target price, 0 for none, use with stoploss for OCO }
    c2stoploss ( NumericSimple ), { stop loss price, 0 for none, use with target for OCO }
    duration ( StringSimple ); { DAY, GTC }

vars:
    result ( 0 ),
    filename ( "C:\Users\Mike\Documents\MultiCharts\Collective2\signal.txt" ),
    c2baseurl ( "http://www.collective2.com/cgi-perl/signal.mpl?" ),
    c2query ( "null" );


if cmd = "signal" then begin
    c2query = text(c2baseurl, "cmd=", cmd, "&systemid=", systemid:0:0, "&pw=", pw, "&action=", action, "&quant=", quant:0:0, "&instrument=", instrument, "&symbol=", c2symbol, "&duration=", duration);

    if c2limit > 0 then c2query = c2query + "&limit=" + text(c2limit:0:2);
    if c2stop > 0 then c2query = c2query + "&stop=" + text(c2stop:0:2);
    if c2target > 0 then c2query = c2query + "&profittarget=" + text(c2target:0:2);
    if c2stoploss > 0 then c2query = c2query + "&stoploss=" + text(c2stoploss:0:2);
end;

if cmd = "closeallpositions" then begin
    c2query = text(c2baseurl, "cmd=", cmd, "&systemid=", systemid:0:0, "&pw=", pw);

end;

if GetAppInfo(aiRealTimeCalc) = 1 then FileAppend(filename,c2query + newline);
Text_New(date, time, C, text("c2: ", cmd, action, quant:0:0));
if c2target > 0 then Text_New(date, time, c2target, text("c2: target ", c2target:0:2));
if c2stoploss > 0 then Text_New(date, time, c2stoploss, text("c2: stop ", c2stoploss:0:2)); 
Let me try to explain the logic:

a) if cmd = signal, we generate a query URL comprised of the system id, password, action (buy to open, sell to open, cover, etc), order quantity, instrument, and duration (GTC/DAY).

b) we further check for optional parameters of a limit price (if no limit price specified, we use a market order).

c) we further check for a stop price (this is a buy stop/sell stop, not a stop loss order). if no stop is specified, we use a market order.

d) we further check for a target price (profit target). if both target and stop loss specified, they are OCO.

e) we further check for a stop loss price. if both target and stop loss specified, they are OCO.

f) if cmd = "closeallpositions" we issue a close all positions order. everything except the systemid and password are ignored in this case.

g) now we've built our query URL.

h) we check to see if we are operating on real-time or historical bars. if real-time bars, we create our signal file. You should modify this to suit your needs. I put mine in C:\Users\Mike\Documents\MultiCharts\Collective2\signal.txt. You'll need something different.

We append to the file if it exists already. If it does not exist it is created. Don't try to put this in Program Files directory if you are using Vista or 7 because you won't have the admin rights to do it. Users\Documents is most logical place.

i) we draw some info to the chart to show what we submitted to c2. feel free to get rid of this, it is more debug.

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/

Visit other sites? Please spread the word about your experience with our community!
Follow me on Twitter Visit my futures io Trade Journal Started this thread Reply With Quote
 
(login for full post details)
  #7 (permalink)
 Big Mike 
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: Custom solution
Trading: Futures & Crypto
 
Big Mike's Avatar
 
Posts: 50,127 since Jun 2009
Thanks: 32,599 given, 98,768 received

Now let's talk about the signal itself and calling the function:

 
Code
                            
vars:

c2id(123456789),
c2pw("myc2password");

// example 1

// open a new long position (BTO)
// instrument QCLK0 (Crude Oil futures, May 2010)
// market order
// profit target is Close of this bar + 20 ticks
// stop loss is Close of this bar - 20 ticks
// order duration is DAY

Buy 1 Contracts This Bar At Close;

Value1 Collective2("signal"c2idc2pw"BTO"1"future""QCLK0"00, (Close + (20 MinMove/PriceScale)), (Close - (20 MinMove/PriceScale)), "DAY");


// example 2

// open a new short position (STO)
// instrument QCLK0 (Crude Oil futures, May 2010)
// market order
// profit target is Close of this bar - 20 ticks
// stop loss is Close of this bar + 20 ticks
// order duration is DAY

Sellshort 1 Contracts This Bar At Close;

Value1 Collective2("signal"c2idc2pw"STO"1"future""QCLK0"00, (Close - (20 MinMove/PriceScale)), (Close + (20 MinMove/PriceScale)), "DAY");


// example 3

// close all positions forcefully
// I do this as a precautionary measure when MarketPosition[1] <> MarketPosition, just to make sure we're closed
// all we need is the c2 id, password, and symbol

Value1 Collective2("closeallpositions"c2idc2pw"null"0"future""QCLK0"0000"DAY"); 
Some pointers:

a) if your order quantity is more than 1, but your targets and/or stops are different for each lot, you should submit multiple calls to the function (ie: value1 = collective2(), value2 = collective2(), etc) each with a quantity of 1 and the proper target/stop.

b) if your EL strat is flat, you should make sure your C2 strat is flat by submitting an extra close all positions command. this is because your EL strat may think a target or stop was hit, and exit the position internally, but yet C2 not have been hit and still remain in a position -- then when EL submits a new order, C2 gets real confused. just be safe and issue a manual "closeallpositions" command when MarketPosition[1] <> MarketPosition.

c) you can call the Collective2() function multiple times back to back. it will append to an existing signal file along the way.

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/

Visit other sites? Please spread the word about your experience with our community!
Follow me on Twitter Visit my futures io Trade Journal Started this thread Reply With Quote
The following user says Thank You to Big Mike for this post:
 
(login for full post details)
  #8 (permalink)
 Big Mike 
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: Custom solution
Trading: Futures & Crypto
 
Big Mike's Avatar
 
Posts: 50,127 since Jun 2009
Thanks: 32,599 given, 98,768 received

Now the third and final step is placing the orders with C2. We need to read our signal.txt generated by the function, parse the URL's within, and hit them on the C2 server. Fortunately, it is as easy as hitting a specific URL.

Using Wget for Windows (linked in first post) and this batch file (create a new file called "submit.cmd" in your Documents\MultiCharts\Collective2 directory), we'll scan for a new signal.txt file once per second and if found we'll move it temporarily, process it, then delete it and loop again starting over.

 
Code
                            
@echo off

:loop
if exist signal.txt goto submit
:delay
ping 1.1.1.1 
-n 1 >nul
goto loop
:submit
ren signal
.txt submit.txt
"c:\program files (x86)\gnuwin32\bin\wget" --spider -i submit.txt
del submit
.txt
goto loop 
Some notes:

a) make sure the filename is right, this will match the function filename from the above post.

b) the ping 1.1.1.1 -n 1 >nul command is just a quick and dirty way to pause for about 1-2 seconds. if you want to slow the whole process down (why?), change -n 1 to -n 10 or -n 60 etc, the number is equal to about 1-2 seconds.

c) you might need to change the c:\program files (x86).... path depending on where you installed wget for windows.

d) the --spider option means don't download the result file. the -i submit.txt is our input file, which we temporarily renamed from signal.txt above (just in the unlikely event a new signal is generated in the < 1 second it takes to run our batch file)

e) remember to run the submit.cmd batch file and just leave it open or minimized on your desktop. if you don't run it, no signals will get submitted. you might want to just add it to your startup folder for windows to load on boot, otherwise just dont forget about it.

THE END!

What do you think? It may be a bit ghetto, but it works great. For the adventurous, the better alternative to this three step process would be for the function itself to call an external C++/C# DLL which uses the HttpWebRequest engine and eliminates the DOS command line/wget step. It would also be nice to directly parse the resulting XML file to ensure the signal was processed by c2.

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/

Visit other sites? Please spread the word about your experience with our community!
Follow me on Twitter Visit my futures io Trade Journal Started this thread Reply With Quote
The following user says Thank You to Big Mike for this post:
 
(login for full post details)
  #9 (permalink)
 Big Mike 
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: Custom solution
Trading: Futures & Crypto
 
Big Mike's Avatar
 
Posts: 50,127 since Jun 2009
Thanks: 32,599 given, 98,768 received

Should mention in the function code you'll need to adjust all the "text(c2limit:0:2)" (and similar) based on how many digits your instrument has after the decimal. I'm not sure of an automatic way to do this, let me know. For CL it's 2 digits for instance.

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/

Visit other sites? Please spread the word about your experience with our community!
Follow me on Twitter Visit my futures io Trade Journal Started this thread Reply With Quote
The following user says Thank You to Big Mike for this post:
 
(login for full post details)
  #10 (permalink)
 Zoethecus 
United States of America
 
Experience: Advanced
Platform: NT
 
Posts: 1,149 since Aug 2009


So, this my provide for more accurate reporting of trades for the developer, but it won't have any bearing on a subscriber who uses C2 auto-trade correct? They will still be under lag and execution constraints because they are getting signals after the fact, correct?

If that's the case, then susbcriber slippage may actually increase from what C2 posts as exceuted trades and that is not a good thing.

Reply With Quote


futures io Trading Community Platforms and Indicators EasyLanguage Programming > EasyLanguage Collective2 Interface (MultiCharts to Collective 2)


Last Updated on June 8, 2014


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing

A Transparent Glimpse Into a Prop Traders Life w/Chris Gray @ Earn2Trade

Elite only
 

Our 12-year anniversary w/ $$,$$$ prizes (check soon)

August
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada), 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