+1 888 340 6572 



Post new topic Reply to topic 
[Advanced Topic] Programming DLL   [ ]
Author Message
#1 posted 30 Mar 2011 
User avatar

Status: Offline
Posts: 4804
Thanks Received: 1172 times
Thanks Given: 772 times
Joined: 29 Aug 2006
TradeStation EasyLanguage Extension Software Development Kit (SDK)
provides users with the ability to write code in a programming language that allows for the creation of DLLs (for example, C++, Pascal, Delphi, or Visual Basic) and call that code from within an EasyLanguage analysis technique.
http://www.multicharts.com/multicharts/ ... mentation/




see also:
[Advanced Topic] MultiCharts 64 bit Resources
viewtopic.php?f=16&t=10094


PS. If you search using the keywords [Advanced Topic], you will find additional useful posts.



For this message the author TJ has received thanks:
A.see


#2 posted 21 Apr 2011 

Status: Offline
Hi,

Is MultiCharts has a sdk to develop using C#. I want to use Visual Studio and build .dll files than import to MultiCharts. Is there a mechanism like that in Wealth-Lab.


#3 posted 21 Apr 2011 
User avatar

Status: Offline
Posts: 963
Thanks Received: 302 times
Thanks Given: 368 times
Joined: 18 Dec 2009
MultiCharts can use external DLL files from PowerLanguage script. You can use the following keywords to access external DLLs:

external method: "myfile.dll"

However, keep in mind that PLE is available only the regular version of MultiCharts.


#4 posted 29 Feb 2012 

Status: Offline
Posts: 943
Thanks Received: 170 times
Thanks Given: 538 times
Joined: 23 Nov 2010
Stan Bokov wrote:
MultiCharts can use external DLL files from PowerLanguage script. You can use the following keywords to access external DLLs:

external method: "myfile.dll"

However, keep in mind that PLE is available only the regular version of MultiCharts.


Stan,

Under witch directory does the dll file need to reside? I got problem to access special dll functions

Martin


#5 posted 01 Mar 2012 
User avatar

Status: Offline
Posts: 4762
Thanks Received: 1496 times
Thanks Given: 427 times
Joined: 25 Aug 2011
Hello Martin,

If you do not specify the path to the dll then the script will search for it in the MultiCharts folder

32 bit: C:\Program Files (x86)\TS Support\MultiCharts
64 bit: C:\Program Files\TS Support\MultiCharts64

If you specify the path to the dll then the script will search for it in the specified folder.



For this message the author Henry MultiСharts has received thanks:
arjfca


#6 posted 01 Mar 2012 

Status: Offline
Posts: 1030
Thanks Received: 686 times
Thanks Given: 1386 times
Joined: 20 May 2011
power wrote:
Is MultiCharts has a sdk to develop using C#.


Stan Bokov wrote:
MultiCharts can use external DLL files from PowerLanguage script.

If I'm not mistaken, MultiCharts can not work with C# DLL's? (C++ works, and the EL and ADE are also written in this if I recall correctly)

I'm wondering because I could not make C# DLL's to work with MultiCharts, and was advised by support to use C++ code for what I was trying to achieve.

I know more C# than C++, hence my question. :)


#7 posted 02 Mar 2012 
User avatar

Status: Offline
Posts: 4762
Thanks Received: 1496 times
Thanks Given: 427 times
Joined: 25 Aug 2011
You can make C# DLLs to work in MultiCharts.
You can find more information regarding the subject in
TradeStation EasyLanguage Extension Software Development Kit.

You can also submit a feature request to the Project Management: "use .NET assemblies from PowerLanguage" with detailed explanation how do you want to use it.



For this message the author Henry MultiСharts has received thanks: 2
arjfca, JoshM


#8 posted 05 Mar 2012 

Status: Offline
Posts: 120
Thanks Received: 4 times
Thanks Given: 7 times
Joined: 08 Jan 2006
https://developer.tradestation.com/docu ... on_SDK.pdf

indicates that tskit.dll should be imported to write dlls. However that is a 32 bit dll, which presumably is incompatible with MC64. Do you have a tskit.dll substitute for writing 64 bit dlls, or alternatively, suggestions on how to write DLLs without tskit?


#9 posted 06 Mar 2012 
User avatar

Status: Offline
Posts: 4762
Thanks Received: 1496 times
Thanks Given: 427 times
Joined: 25 Aug 2011
Hello Trader39,

You need to use PLkit.dll to write 64 bit DLLs.
This dll can be found in MultiCharts folder.




moderator's note:
[Advanced Topic] MultiCharts 64 bit Resources
viewtopic.php?f=16&t=10094



For this message the author Henry MultiСharts has received thanks: 2
JoshM, trader39


#10 posted 06 Mar 2012 

Status: Offline
Posts: 120
Thanks Received: 4 times
Thanks Given: 7 times
Joined: 08 Jan 2006
Great.

What (preferably free and available online) compiler (Java or C or C++) would you recommend to write MC64 compatible dlls? I presume a 64 bit compiler is required, but I note that cc1plus.exe *32 (presumably 32 bit?) is active in the task manager when MC64 power language scripts are compiled.


#11 posted 06 Mar 2012 

Status: Offline
Posts: 120
Thanks Received: 4 times
Thanks Given: 7 times
Joined: 08 Jan 2006
I note that Visual Studio 2010 is available for free 30 day trial download so that would be an option, if you recommend it, although it does not seem to support Java. (Please advise whether to run it in 32 or 64 bit mode if you do recommend it).


#12 posted 06 Mar 2012 

Status: Offline
Posts: 268
Thanks Received: 16 times
Thanks Given: 53 times
Joined: 21 May 2009
Hi

VS DLL are not compatible with MC.

Emmanuel


#13 posted 06 Mar 2012 

Status: Offline
Posts: 120
Thanks Received: 4 times
Thanks Given: 7 times
Joined: 08 Jan 2006
So what compiler do you recommend?


#14 posted 12 Mar 2012 
User avatar

Status: Offline
Posts: 1669
Thanks Received: 451 times
Thanks Given: 49 times
Joined: 16 Apr 2010
Emmanuel wrote:
Hi
VS DLL are not compatible with MC.
Emmanuel


VS DLL are compatible with MultiCharts. Please use Microsoft Visual Studio 2008 or 2010 C++

For MC 64 bit compile dll for x64 platform.
For MC 32 bit compile dll for Win32 platform.



For this message the author Dave Masalov has received thanks: 2
Emmanuel, JoshM


#15 posted 12 Mar 2012 
User avatar

Status: Offline
Posts: 1669
Thanks Received: 451 times
Thanks Given: 49 times
Joined: 16 Apr 2010
trader39 wrote:
What (preferably free and available online) compiler (Java or C or C++) would you recommend to write MC64 compatible dlls? I presume a 64 bit compiler is required, but I note that cc1plus.exe *32 (presumably 32 bit?) is active in the task manager when MC64 power language scripts are compiled.
trader39 wrote:
So what compiler do you recommend?


Basically, you can use any software that you are familiar with as long as it compiles Win32 and x64 dlls.

See more discussions here:
viewtopic.php?f=1&t=8391&p=39052&hilit=DLLS#p39052



For this message the author Dave Masalov has received thanks:
JoshM


#16 posted 22 Jun 2012 

Status: Offline
Posts: 1030
Thanks Received: 686 times
Thanks Given: 1386 times
Joined: 20 May 2011
Henry Multicharts wrote:
You can make C# DLLs to work in MultiCharts. You can find more information regarding the subject in TradeStation EasyLanguage Extension Software Development Kit.

Can you explain how to make a C# dll? I've followed the EasyLanguage Extension SDK to the letter, but run into problems with step 1: importation of tskit.dll (which I don't have). If I add the elkit32.dll from the MultiCharts program folder as a reference to the Visual Studio DLL, I get the

Quote:
Could not load file or assembly 'elkit32.dll' or one of it dependencies. The module was expected to contain an assembly manifest.

This file may not be a managed assembly.


error message. If I try to import it as an unmanaged assembly (through DLLImport), I don't know how to make the accompanying method/entry point, since well, I can't look into that DLL for the correct method name.

If I go ahead and make the DLL without the elkit32.dll reference, I get the "can't find function .. in dll" error message when adding the indicator.

So to summarize; does someone has a working C# project (that can be reverse engineered to learn how it works), or willing/able to write down the needed steps? :)


#17 posted 27 Jun 2012 

Status: Offline
Posts: 103
Thanks Received: 158 times
Thanks Given: 4 times
Joined: 28 Aug 2007
JoshM wrote:
So to summarize; does someone has a working C# project (that can be reverse engineered to learn how it works), or willing/able to write down the needed steps? :)

The question like "How I can use .NET assembly in MultiCharts (PL)" is same as question "How I can use .NET assembly in any unmanaged application". There are many ways exists.

PL code for example:
Code:
EXTERNAL: "net_assembly_interop.dll", double, "Summ", double, double;
if close + open <> Summ(close, open) then raiseruntimeerror(":-(");


You do not have the required permissions to view the files attached to this post.



For this message the author Dru has received thanks: 8
csharpstudent, Henry MultiСharts, JoshM, Laurent, PK1, Roman MultiCharts, Stan Bokov, TJ


#18 posted 27 Jun 2012 

Status: Offline
Posts: 1030
Thanks Received: 686 times
Thanks Given: 1386 times
Joined: 20 May 2011
Thanks Dru for your example! :)

If you allow me another newbie question, can you (or someone else) tell how to use this generated DLL in MultiCharts from the VS project? Here's what I've done:

1) Opened the project file Call_dotNET_code_from_PL in Visual Studio,
2) Visual Studio converted both projects to VS10 project format,
3) Hit F6 to build solution,
4) Copied the net_assembly_interop.dll file from '\Call_dotNET_code_from_PL\Debug\' to 'C:\Program Files\MultiCharts\'.
5) Added the following PowerLanguage code in an empty indicator:

Code:
EXTERNAL: "net_assembly_interop.dll", double, "Summ", double, double;

if (LastBarOnChart_s = True) then begin

   Print("10 + 231.2 = ", Summ(10, 231.2));

end;

6) Got an application error after adding the indicator to the chart.
Image

If I use the net_assembly.dll, I get the "Can't find function 'Summ' in dll." error message.


You do not have the required permissions to view the files attached to this post.


#19 posted 28 Jun 2012 

Status: Offline
Posts: 103
Thanks Received: 158 times
Thanks Given: 4 times
Joined: 28 Aug 2007
JoshM wrote:
4) Copied the net_assembly_interop.dll file from '\Call_dotNET_code_from_PL\Debug\' to 'C:\Program Files\MultiCharts\'.

net_assembly_interop.dll is the C++/CLI "mixed" dll (native dll + managed code). i.e. it is PROXY that delegate all work to net_assembly.dll - is the pure managed dll (assembly) that do all job.
You need copy both dll to MC dir
P.S. During build take attention to Solution Configuration and MultiCharts.exe bit depth (x64 vs x86)



For this message the author Dru has received thanks: 3
alanyangbo, dahmen walter, JoshM


#20 posted 28 Oct 2012 

Status: Offline
Posts: 3
Thanks Received: 0 time
Thanks Given: 1 time
Joined: 28 Oct 2012
Dru wrote:
JoshM wrote:
4) Copied the net_assembly_interop.dll file from '\Call_dotNET_code_from_PL\Debug\' to 'C:\Program Files\MultiCharts\'.

net_assembly_interop.dll is the C++/CLI "mixed" dll (native dll + managed code). i.e. it is PROXY that delegate all work to net_assembly.dll - is the pure managed dll (assembly) that do all job.
You need copy both dll to MC dir
P.S. During build take attention to Solution Configuration and MultiCharts.exe bit depth (x64 vs x86)


good job! Another question:if c# function return String and its parameters also string,then how to correct write c++ dll?It is big problems for me :( Looking forward to your reply!
Alan.


#21 posted 29 Oct 2012 
User avatar

Status: Offline
Posts: 4762
Thanks Received: 1496 times
Thanks Given: 427 times
Joined: 25 Aug 2011
alanyangbo wrote:
Another question:if c# function return String and its parameters also string,then how to correct write c++ dll?It is big problems for me :( Looking forward to your reply!
Alan.


Here is how you need to define the functions that should receive the strings in C++/CLI dll:
Code:
System::String ^ __clrcall TestString(System::String ^ s1)


Here is how such function should be described in PLE:
Code:
DefineDLLFunc: "net_assembly_interop.dll", string, "TestString", string;


#22 posted 21 Nov 2012 

Status: Offline
Posts: 1
Thanks Received: 0 time
Thanks Given: 0 time
Joined: 20 Nov 2012
my c++ source MyDllFile.cpp:
Code:
#import "D:\Prog\TS Support\MultiCharts\tskit.dll"  no_namespace
#include <atlbase.h>

//////////////////////////////////////////////////////////////
// Calculate simple moving average value

double __stdcall MovAvg
( IEasyLanguageObject * pELObj, int iAvgLength )
{
  double dMovAvg ;
  dMovAvg = 0 ;
   
  // verify that sufficient bars have passed before back-referencing historical prices
   //if( pELObj->CloseMD[data1]->BarsBack > iAvgLength && iAvgLength > 0 )

  {
    double dSum = 0.0 ;
    for (int i = 0; i < iAvgLength; i++)
    {
      dSum += pELObj->CloseMD[data1]->AsDouble[ i ] ;
    }
    dMovAvg = dSum / iAvgLength ;
  }
  //return dMovAvg ;
  return 1.1;
}

//////////////////////////////////////////////////////////////
//  Generate a run-time error in TradeStation
//  This function is called internally by other DLL functions when an error in TradeStation
//  is to be produced.

void fnGenRunTimeError
( IEasyLanguageObject * pEL, int iErrorNum )
{
  TSRuntimeErrorItem tsItem;
  int m_HistErr ;
  tsItem.sCompany = _bstr_t("TradeStation Securities, Inc.").copy();
  tsItem.sErrorLocation = _bstr_t("Example Code Library").copy();
  tsItem.sErrorCategory = _bstr_t("Error").copy();
  tsItem.sLongString = NULL;
  tsItem.nParameters = 0;
     
    switch ( iErrorNum )
  {
  case 1:
    {
      // Error 1
tsItem.sShortString = _bstr_t("Error  –  Description of Error 1 goes here.").copy();
      tsItem.sSourceString = _bstr_t("Additional detailed description goes here.").copy();
      tsItem.nErrorCode = iErrorNum ;
    }
    break ;
    case 2: 
    {
      // Error 2
      tsItem.sShortString = _bstr_t("Error  –  Description of Error 2 goes here.").copy();
      tsItem.sSourceString = _bstr_t("Additional detailed description goes here.").copy();
      tsItem.nErrorCode = iErrorNum ;
    }
    break ;
    default:
    {
      // Generate a run-time error of undefined type or origin
      tsItem.sShortString = _bstr_t("Undefined error in "
        "MyDLL.dll.").copy();
      tsItem.sSourceString = _bstr_t("Error origin undefined.").copy();
      tsItem.nErrorCode = 9999 ;
    }
  }

  m_HistErr = pEL->Errors->RegisterError( &tsItem ) ;
    pEL->Errors->RaiseRuntimeError( m_HistErr ) ;
}


//////////////////////////////////////////////////////////////
// Server field call
double __stdcall GETSERVERFIELD
(IEasyLanguageObject *pEL, LPSTR szFName)
{
//  IEasyLanguageServerField *iSF = pEL->ServerField[_bstr_t(szFName)][dataDefault];
//  return iSF->AsDouble[0];
   return 1.0;



//////////////////////////////////////////////////////////////
// Sort an EasyLanguage array using this DLL function

void __stdcall MYARRAYSORT
( IEasyLanguageObject* pELObj, char* MyArrayName )
{
  int nOuter, nInner ; 
  IEasyLanguageVariable* pELVar = pELObj->Variables[ MyArrayName ] ;
  if ( pELVar->Dimensions == 1 )
  {
    int nSize = pELVar->DimensionSize[0] ;
    for ( nOuter = 0; nOuter < nSize - 1; nOuter++ )
    {
      for ( nInner = nOuter + 1; nInner < nSize; nInner++ )
      {   
        pELVar->SelectedIndex[0] = nInner ;
        double dSecondValue = pELVar->Value[0] ;
        pELVar->SelectedIndex[0] = nOuter ;
        double dFirstValue = pELVar->Value[0] ;
        if ( dSecondValue < dFirstValue )
        {
          double dTmp = dFirstValue ;
          pELVar->Value[0] = dSecondValue ;
          pELVar->SelectedIndex[0] = nInner ;
          pELVar->Value[0] = dTmp ;
        }
      }
    } 
  } 
}


//////////////////////////////////////////////////////////////
// Fill dynamic EasyLanguage array

void __stdcall FILLDYNARRAY
(IEasyLanguageObject * pEL, LPSTR PassedVar)
{
  IEasyLanguageVariablePtr pMyVar = NULL;
  IELFrameworkArrayPtr pDynArray = NULL;
 
  IEasyLanguageDateTime * pMyDateTime = pEL->DateTimeMD[ dataDefault ] ;
  double myDT = pMyDateTime->AsDateTime [0] ;
   
  long nTotVars = pEL->VariablesCount;
  for (long n = 0; n < nTotVars; n++)
  {
    pMyVar = pEL->Variables[n];
    _bstr_t mybstr = pMyVar->Name;
    if (pMyVar->DataType == dtHandle)
    {
      int nValue = pMyVar->GetAsInteger(0);
      CComVariant xx(pEL->Close[0]);
      if (pEL->System->Array->IsValidHandle( (int) nValue ) && (mybstr == (_bstr_t) PassedVar))
      {
        pDynArray = pEL->System->Array;
        pDynArray->SetValue(nValue, 0, CComVariant(xx));
      }
    }
  }
}
//////////////////////////////////////////////////////////////
// Sum upticks and downticks from intraday chart to get volume in DLL  –  store in global DLL variable

double dMyDLLDouble = 0; //global variable

int __stdcall SetdMyDLLDouble 
( IEasyLanguageObject * ELObjP )
{
  dMyDLLDouble = ELObjP->UpTicksMD[dataDefault]->AsDouble[0]
    + ELObjP->DownTicksMD[dataDefault]->AsDouble[0] ;   
  return 1;
}


===============================
my pl source :

Code:
external: "MyDllFile.dll", double, "MovAvg", IEasyLanguageObject {self}, int {Length};

inputs:
  Length( 10 ) ;

variables:
  double MyELVar( 0 ) ;

MyELVar = MovAvg( self, Length ) ;

plot1(MyELVar ,"MyELVar ");


======================================
when I add the indicator to the chart , I got a error message cannot find the "MovAvg" function.

I have copied the MyDllFile.dll into MultiCharts directory.

Can you help me?


#23 posted 21 Nov 2012 
User avatar

Status: Offline
Posts: 4762
Thanks Received: 1496 times
Thanks Given: 427 times
Joined: 25 Aug 2011
beolee, the function is not defined as external in your dll.
You need to define it as an external function or create a def file in VS and add this function to it.


#24 posted 21 Jan 2013 

Status: Offline
Posts: 103
Thanks Received: 158 times
Thanks Given: 4 times
Joined: 28 Aug 2007
alanyangbo wrote:
if c# function return String and its parameters also string,then how to correct write c++ dll?

Example updated.
Code:
EXTERNAL: "net_assembly_interop.dll", lpstr, "ReturnStringExample", lpstr;
plot1( ReturnStringExample("from PL") );


You do not have the required permissions to view the files attached to this post.



For this message the author Dru has received thanks:
JoshM


#25 posted 25 Jan 2013 

Status: Offline
Posts: 1030
Thanks Received: 686 times
Thanks Given: 1386 times
Joined: 20 May 2011
Dru wrote:
alanyangbo wrote:
if c# function return String and its parameters also string,then how to correct write c++ dll?

Example updated.
Code:
EXTERNAL: "net_assembly_interop.dll", lpstr, "ReturnStringExample", lpstr;
plot1( ReturnStringExample("from PL") );

Dru, can you tell something about how you created the net_assembly_interop C++ dll? That way I can create another DLL with a different name. I know practically nothing about C++, so if it's not to much to ask, can you say, in "Dummy language" which steps you took?

(Edit: Since the PowerLanguage code calls the interop dll, I assume that every C# dll need its own accompanying interop dll, hence the question. Don't know though if this assumption is valid.)


#26 posted 26 Feb 2013 

Status: Offline
Posts: 103
Thanks Received: 158 times
Thanks Given: 4 times
Joined: 28 Aug 2007
JoshM wrote:
Dru, can you tell something about how you created the net_assembly_interop C++ dll?

Hmm ...
Do you want to know how I am writing a program in C++? :)
You can take the example and change project properties for new dll name.
Keywords for studying: C++/CLI, MS VS 2008, export functions from dll


#27 posted 26 Feb 2013 

Status: Offline
Posts: 103
Thanks Received: 158 times
Thanks Given: 4 times
Joined: 28 Aug 2007
JoshM wrote:
Since the PowerLanguage code calls the interop dll, I assume that every C# dll need its own accompanying interop dll, hence the question. Don't know though if this assumption is valid.)

This is not necessary. The ONE interop dll can be the "bridge" for many .NET (C#) assemblies.



For this message the author Dru has received thanks:
JoshM


#28 posted 12 Mar 2013 

Status: Offline
Posts: 4
Thanks Received: 0 time
Thanks Given: 4 times
Joined: 12 Mar 2013
Hello all.
I have tried to follow the very helpful responses above on how to build a dll for MC.

I would REEEEALLLY be thankfyl if anyone could help me get the following accomplished:

Objective of the DLL - Send from PowerLanguage code, date and time and read an ASCII file and pass the value back to MC 32 bit.

Format of file

1/1/2012 12:04 565.6
1/1/2012 12:05 675.4

Format is
<dd/mm/yyyy> <hh:mm> <numeric value>

So I would send the date and time into the DLL via PowerLanguage and receive back the value.

I would via this exercise love to learn how to write DLLs to be used, so some clarity on how to integrate it into MC 32 bit (and eventually MC64).

I really look forward to your help.

Best Reagrds


#29 posted 13 Mar 2013 

Status: Offline
Posts: 943
Thanks Received: 170 times
Thanks Given: 538 times
Joined: 23 Nov 2010
csharpstudent wrote:
Hello all.
I have tried to follow the very helpful responses above on how to build a dll for MC.

I would REEEEALLLY be thankfyl if anyone could help me get the following accomplished:

Objective of the DLL - Send from PowerLanguage code, date and time and read an ASCII file and pass the value back to MC 32 bit.

Format of file

1/1/2012 12:04 565.6
1/1/2012 12:05 675.4

Format is
<dd/mm/yyyy> <hh:mm> <numeric value>

So I would send the date and time into the DLL via PowerLanguage and receive back the value.

I would via this exercise love to learn how to write DLLs to be used, so some clarity on how to integrate it into MC 32 bit (and eventually MC64).

I really look forward to your help.

Best Reagrds


Not answering your question but,
If I remenber, there is ElCollection.dll that could read/write asci file.

Martin



For this message the author arjfca has received thanks:
csharpstudent


#30 posted 13 Mar 2013 

Status: Offline
Posts: 4
Thanks Received: 0 time
Thanks Given: 4 times
Joined: 12 Mar 2013
Martin,
Thanx for the pointer. Where would I find this ElCollection.dll , its docs/usage steps etc.

Best


#31 posted 13 Mar 2013 

Status: Offline
Posts: 42
Thanks Received: 6 times
Thanks Given: 13 times
Joined: 29 Mar 2012
You can find it there :

http://www.multicharts.com/discussion/viewtopic.php?f=5&t=2483



For this message the author youn56 has received thanks:
csharpstudent


#32 posted 13 Mar 2013 

Status: Offline
Posts: 943
Thanks Received: 170 times
Thanks Given: 538 times
Joined: 23 Nov 2010
csharpstudent wrote:
Martin,
Thanx for the pointer. Where would I find this ElCollection.dll , its docs/usage steps etc.

Best

CsharpStudent. Look on this post from user TJ: viewtopic.php?f=16&t=10094#p48319


Martin :)



For this message the author arjfca has received thanks:
csharpstudent


#33 posted 25 Jan 2014 

Status: Offline
Posts: 17
Thanks Received: 0 time
Thanks Given: 5 times
Joined: 09 May 2011
Hi,

I'm sorry. Seems i'm a bit late of discussing about C# dll called in Easylanguage.

Hope someone still can help me because a bit confuse after reading the topic from above. I have downloaded dru's example but doesn't look like in example in tradestation sample which is using c/c++.

I'm using MC 64 bit. Do i still need to import PLkit.dll in creating C# dll or i do not need to import PLkit.dll ? Appreciate someone explain further details or step by step.

Thanks.



Post new topic Reply to topic