{"id":310,"date":"2016-10-15T13:38:28","date_gmt":"2016-10-15T11:38:28","guid":{"rendered":"http:\/\/script-trading.com\/en\/?p=310"},"modified":"2024-01-29T21:30:41","modified_gmt":"2024-01-29T20:30:41","slug":"integrate-an-agenascript-dll-into-agenatrader","status":"publish","type":"post","link":"https:\/\/script-trading.com\/en\/integrate-an-agenascript-dll-into-agenatrader\/","title":{"rendered":"Integrate an AgenaScript DLL into AgenaTrader"},"content":{"rendered":"<p>The integration of an AgenaScript DLL into the AgenaTrader is an extremely useful option, because you can centrally classify classes, extensions and global functions, and you do not have to duplicate this source code in scripts such as indicators or conditions (duplicate code\u00a0= error!).<\/p>\n<p>Our\u00a0test-DLL shown in this article\u00a0was created in Visual Studio and integrated into AgenaTrader with the following setup:<\/p>\n<ul>\n<li>Windows 10 64bit<\/li>\n<li>Agena Trader Andromeda 1.0.8.453<\/li>\n<li>Visual Studio Ultimate 2013 (community edition also possible)<\/li>\n<li>For all activities we are using .NET Framework\u00a03.5<\/li>\n<li>Visual Studio was launched with the\u00a0Administrator account to make it possible to\u00a0copy the DLL\u00a0into the GAC.<\/li>\n<\/ul>\n<p>For AgenaTrader in version 1.9 and above, Visual Studio 2015 is recommended and .NET Framework 4.6 is required.<\/p>\n<h2>Create an AgenaScript DLL in Visual Studio<\/h2>\n<p>F\u00fcr die Erstellung unserer sehr einfache DLL nutzen wir Visual Studio und erstellen ein Projekt mit dem Typ Klassenbibliothek. Der Name unserer Projektes ist AgenaTraderDLL da dieser Name sp\u00e4ter ben\u00f6tigt wird. Unsere sehr einfache DLL\u00a0besteht aus folgendem Code:<\/p>\n<p>To create\u00a0our very simple DLL, we use Visual Studio and create a project with the type <strong>classlibrary<\/strong>. The name of our projects is <strong>AgenaTraderDLL.<\/strong>\u00a0This name is needed later. Our very simple DLL consists of the following code:<\/p>\n<p><em>using System;<\/em><br \/>\n<em>namespace AgenaTraderDLL<\/em><br \/>\n<em>{<\/em><br \/>\n<em>public static class ExternalHelper {<\/em><br \/>\n<em>public static String Test() {<\/em><br \/>\n<em>return &#8220;Hello World!&#8221;;<\/em><br \/>\n<em>}<\/em><br \/>\n<em>}<\/em><br \/>\n<em>}<\/em><\/p>\n<p>Before we compile the script we need to sign the project first. You will find the settings for signing within the project settings.<\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-medium wp-image-301\" src=\"http:\/\/script-trading.com\/wp-content\/uploads\/2016\/10\/signate_visual_studio-300x186.png\" alt=\"signate_visual_studio\" width=\"300\" height=\"186\" srcset=\"https:\/\/script-trading.com\/wp-content\/uploads\/2016\/10\/signate_visual_studio-300x186.png 300w, https:\/\/script-trading.com\/wp-content\/uploads\/2016\/10\/signate_visual_studio-768x475.png 768w, https:\/\/script-trading.com\/wp-content\/uploads\/2016\/10\/signate_visual_studio-830x514.png 830w, https:\/\/script-trading.com\/wp-content\/uploads\/2016\/10\/signate_visual_studio-230x142.png 230w, https:\/\/script-trading.com\/wp-content\/uploads\/2016\/10\/signate_visual_studio-350x217.png 350w, https:\/\/script-trading.com\/wp-content\/uploads\/2016\/10\/signate_visual_studio-480x297.png 480w, https:\/\/script-trading.com\/wp-content\/uploads\/2016\/10\/signate_visual_studio.png 855w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>The DLL created by us has to be copied to the GAC (Global Assembly Cache) using gacutil.exe. An alternative is to create an MSI package. Using gacutil is the better (faster) solution\u00a0during development. Since we use .Net 3.5, we have to use gacutil from the following folder:<\/p>\n<p><em>C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\Bin\\gacutil.exe<\/em><\/p>\n<p>To reduce the workload\u00a0while copying to the GAC, the Visual Studio post-build process can be used, so after each build process, Visual Studio copies the newly created DLL to the GAC.<br \/>\n<img decoding=\"async\" class=\"aligncenter size-medium wp-image-302\" src=\"http:\/\/script-trading.com\/wp-content\/uploads\/2016\/10\/visual_studio_build_process-300x192.png\" alt=\"visual_studio_build_process\" width=\"300\" height=\"192\" srcset=\"https:\/\/script-trading.com\/wp-content\/uploads\/2016\/10\/visual_studio_build_process-300x192.png 300w, https:\/\/script-trading.com\/wp-content\/uploads\/2016\/10\/visual_studio_build_process-230x147.png 230w, https:\/\/script-trading.com\/wp-content\/uploads\/2016\/10\/visual_studio_build_process-350x224.png 350w, https:\/\/script-trading.com\/wp-content\/uploads\/2016\/10\/visual_studio_build_process-480x307.png 480w, https:\/\/script-trading.com\/wp-content\/uploads\/2016\/10\/visual_studio_build_process.png 673w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><em>C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\Bin\\gacutil.exe&#8221; \/i &#8220;$(TargetPath)<\/em><\/p>\n<p>Now you are ready to\u00a0compiled the DLL and it will be automatically copied to the GAC.<\/p>\n<p>To ensure that the DLL\u00a0is actually present in the GAC, the following command can be used:<\/p>\n<p><em>C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\Bin\\gacutil.exe&#8221; \/l &#8220;AgenaTraderDLL<\/em><\/p>\n<p>If you want to manually remove the DLL from the GAC, you can do this by using the following command:<\/p>\n<p><em>C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\Bin\\gacutil.exe&#8221; \/u &#8220;AgenaTraderDLL<\/em><\/p>\n<p><strong>Caution gacutil was executed in ADMINISTRATOR mode on command line!<\/strong><\/p>\n<h2>Using our DLL in AgenaTrader<\/h2>\n<p>Lets\u00a0start AgenaTrader and click on: Tools =&gt; Programming =&gt; Programming References. In the &#8220;Select References&#8221; window we recognize our DLL in the GAC. Via the tap &#8220;Browse&#8221; we load our DLL into the AgenaTrader\u00a0and then we will find the path to the local DLL in\u00a0the bottom window.<\/p>\n<p>If we add the &#8216;using&#8217; statement into\u00a0our AgenaScript files like indicators or conditions, we can access the encapsulated functions from\u00a0our DLL.<\/p>\n<p><em>using AgenaTraderDLL;<\/em><\/p>\n<p>In the OnBarUpdate() event of an AgenaScript indicator or AgenaScript condition, we access the static helper from our DLL and write the value to the output of the AgenaTrader.<\/p>\n<p><em>protected override void OnBarUpdate() {<\/em><br \/>\n<em>String helloDLLworld = ExternalHelper.Test();<\/em><br \/>\n<em>Print(helloDLLworld);<\/em><br \/>\n<em>}<\/em><\/p>\n<p>In the end we have to compile all scripts in AgenaTrader.<\/p>\n<p><a href=\"https:\/\/github.com\/ScriptTrading\/Tutorials\/tree\/master\/AgenaTraderDLL\">The source code for this article is available on our GitHub project.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The integration of an AgenaScript DLL into the AgenaTrader is an extremely useful option, because you can centrally classify classes, extensions and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":294,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","footnotes":""},"categories":[29,30,27,28,64,62],"tags":[17,34,22],"class_list":["post-310","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-agenascript","category-agenascript-en","category-agenatrader","category-agenatrader-en","category-deutsch-en","category-english","tag-agenascript-en","tag-tutorial","tag-visual-studio-en"],"_links":{"self":[{"href":"https:\/\/script-trading.com\/en\/wp-json\/wp\/v2\/posts\/310","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/script-trading.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/script-trading.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/script-trading.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/script-trading.com\/en\/wp-json\/wp\/v2\/comments?post=310"}],"version-history":[{"count":16,"href":"https:\/\/script-trading.com\/en\/wp-json\/wp\/v2\/posts\/310\/revisions"}],"predecessor-version":[{"id":1179,"href":"https:\/\/script-trading.com\/en\/wp-json\/wp\/v2\/posts\/310\/revisions\/1179"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/script-trading.com\/en\/wp-json\/wp\/v2\/media\/294"}],"wp:attachment":[{"href":"https:\/\/script-trading.com\/en\/wp-json\/wp\/v2\/media?parent=310"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/script-trading.com\/en\/wp-json\/wp\/v2\/categories?post=310"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/script-trading.com\/en\/wp-json\/wp\/v2\/tags?post=310"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}