EasyLanguage Collective2 Interface (MultiCharts to Collective 2) - EasyLanguage Programming | futures io social day trading
futures io futures trading


EasyLanguage Collective2 Interface (MultiCharts to Collective 2)
Updated: Views / Replies:16,208 / 41
Created: by Big Mike 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 Collective2 Interface (MultiCharts to Collective 2)

  #1 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,240 since Jun 2009
Thanks: 29,356 given, 83,237 received

EasyLanguage Collective2 Interface (MultiCharts to Collective 2)

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

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
The following 8 users say Thank You to Big Mike for this post:
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,240 since Jun 2009
Thanks: 29,356 given, 83,237 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

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
 
  #4 (permalink)
Elite Member
Chicago
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Mirus/Zen-FIre
Favorite Futures: GC, ES
 
Posts: 73 since Mar 2010
Thanks: 40 given, 31 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
 
  #5 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,240 since Jun 2009
Thanks: 29,356 given, 83,237 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

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
 
  #6 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,240 since Jun 2009
Thanks: 29,356 given, 83,237 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

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
 
  #7 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,240 since Jun 2009
Thanks: 29,356 given, 83,237 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

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
The following user says Thank You to Big Mike for this post:
 
  #8 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,240 since Jun 2009
Thanks: 29,356 given, 83,237 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

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
The following user says Thank You to Big Mike for this post:
 
  #9 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,240 since Jun 2009
Thanks: 29,356 given, 83,237 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

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
The following user says Thank You to Big Mike for this post:
 
  #10 (permalink)
Membership Revoked
United States of America
 
Futures Experience: Advanced
Platform: NT
 
Posts: 1,149 since Aug 2009
Thanks: 262 given, 471 received


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

Reply



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

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
VIDEO TUTORIAL: How to create an advanced MultiCharts EasyLanguage Strategy Big Mike MultiCharts 39 November 9th, 2017 04:35 AM
Global Variables (GV) in EasyLanguage for TradeStation/MultiCharts Big Mike EasyLanguage Programming 19 October 29th, 2013 04:07 PM
BMT Collective MA Blz17 The Elite Circle 31 March 2nd, 2012 11:59 AM
Using EleXcel, interface to Excel arjfca MultiCharts 2 June 16th, 2011 09:18 AM
OHLCPeriodsAgo EasyLanguage/MultiCharts ccfeldt EasyLanguage Programming 4 April 6th, 2011 08:23 AM


All times are GMT -4. The time now is 06:55 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-18 in 0.16 seconds with 19 queries on phoenix via your IP 54.163.209.109