TradePlatform.NET simple tutorial

Preview:

DESCRIPTION

This is my first tutorial on TradePlateform.NET which is managed by Vladimir Kaloshin in Codeplex website. You can find more information about the project on https://tradeplatform.codeplex.com/

Citation preview

Ken, Y.K. Au kenykau@gmail.com26 Apr, 2013

TradePlatform.net & forexsharp

Simple Tutorial

Ken, Y.K. Au kenykau@gmail.com26 Apr, 2013

Disclamer

• All the logos and/or copyrighted materials are owned by their respective owner.

• This is tutorial is only focus on how to make TradePlatform.net work. No forex trading at all.

• I am not a professional programmer and not very good in English.

• I want to thanks Welly Tambunan and Vladimir Kaloshin for their great effort to create forexsharp and TradePlatform.net

Ken, Y.K. Au kenykau@gmail.com26 Apr, 2013

Introduction

• I gain a lot from the community.• I use MT4 to trade.• I used MQL4 to write the EAs, but it limited the

extensibility.• I tried C++, but not easy as I am a C# guy.• Until I found TradePlatform.net and forexsharp• Please visit:

TradePlatform.nethttps://tradeplatform.codeplex.com

forexsharp https://github.com/welly87/forexsharp

Ken, Y.K. Au kenykau@gmail.com26 Apr, 2013

Step I – Download the projects

• You can download the project file from github or codeplex.

• Deployment tools – vs2012• Demonstration of using github• https://github.com/welly87/forexsharp/archiv

e/master.zip• Extract the file in a folder

Ken, Y.K. Au kenykau@gmail.com26 Apr, 2013

Step II – Compile the project

Open It!!!

2

Click OK

1

1. Open the FXSharp project2. Click OK in the VS2012 dialog

Ken, Y.K. Au kenykau@gmail.com26 Apr, 2013

Step II (A) – Compile the project• DON’T rush to build the solution!!!• Call the Package Mange Console first!

TOOL Library Package Manager Package Manager Console

Ken, Y.K. Au kenykau@gmail.com26 Apr, 2013

Step II (A) – Compile the project• Install UNITE package in the console• In the console:• Default project: FXSharp.EA.NewsBox.Specs (The red box part)• Then, type install-package nunit, then press Enter

Success!!!

Ken, Y.K. Au kenykau@gmail.com26 Apr, 2013

Step II (A)– Compile the project

• Once installed the NUNIT package, we can build it now by Press F6

• There may have some warnings. You can ignore it.

• Now you can study the code for your own interest.

Ken, Y.K. Au kenykau@gmail.com26 Apr, 2013

Step II(B) – Another Approach

• In Step II (A), we build the project and study the code. There is another approach that is much easier.

• Recall after we download the project file, extract the file in a folder (source folder).

• Copy the folder called: TradePlatform.NET 2.0.0.0 Beta in to a new folder.

Ken, Y.K. Au kenykau@gmail.com26 Apr, 2013

Step III – Expert Advisor

• Open a new Class Library Project in VS2012• Make sure your target framework is .NET 4.5• Let’s call it FxTest.• Add following assemblies in the SHELL_BACKUP

folder into the project:TradePlatform.MT4.Core.dllTradePlatform.MT4.Data.dllTradePlatform.MT4.SDK.API.dllTradePlatform.MT4.SDK.Library.dll

Ken, Y.K. Au kenykau@gmail.com26 Apr, 2013

Step III – Expert Advisor

• EA Purpose:– Capture the screen when there is a new bar

formed.– The file name of the captured file will be in the

form of Symbol-Timeframe-BarNumber.gif– For eg. I will put the EA in EURUSD, M1 Chart, the

file name will be EURUSD-1-XXXX.gif where XXXX is the number of bars

Ken, Y.K. Au kenykau@gmail.com26 Apr, 2013

Step III – Expert Advisorusing System;using System.Collections.Generic;using System.Text;using TradePlatform.MT4.Core;using TradePlatform.MT4.SDK.API;

namespace FxTest{ public class ScreenCapture: TradePlatform.MT4.Core.ExpertAdvisor { private int currentBars; protected override int Init() { currentBars = this.Bars(); return (1); } protected override int Start() { if (this.currentBars < this.Bars()) { this.WindowScreenShot(string.Format("{0}-{1}-{2}.gif", this.Symbol(), this.Period(), this.currentBars), 640, 480); this.currentBars = this.Bars(); } return (1); } protected override int DeInit() { return (1); } }}

• Rename Class1.cs to ScreenCapture.cs• Type the following codes• Please pay attention to the Arrows• After complete coding, press F6 to build the solution• You will get the FxTest.dll

Ken, Y.K. Au kenykau@gmail.com26 Apr, 2013

Step III – Expert Advisor (config file)

• I am not a programmer, it is my hobby to write small programs to solve silly problem. I do not have enough knowledge in C# & .NET.

• Now come to the config file and the rest of stuff.• We need the Shell.exe.config to make sure the EA

run correctly.• You can copy the Shell.exe.config to your project

folder or create add a new one.• I added the Shell.exe.config to my project

Ken, Y.K. Au kenykau@gmail.com26 Apr, 2013

Step III – Expert Advisor (config file)

I collapse some of the section and show the most important part only.Please note the arrows!!!

A CB

A. Will be refer by mql codeB. The full class name of the EAC. The assembly name

Ken, Y.K. Au kenykau@gmail.com26 Apr, 2013

Step III – Expert Advisor

• We are almost done here!• Copy the assembly (FxTest.dll) and config

(Shell.exe.config) files to Shell_Backup folder.• We can leave the .NET part for a while.

Ken, Y.K. Au kenykau@gmail.com26 Apr, 2013

Step IV – MQL Part

• Copy the expert folder in the Terminal Folder to your MT4 folder.

• Use Meta Editor to open Expert_NET.mql in MT4\expert folder.

• Let’s look at the mql code

Ken, Y.K. Au kenykau@gmail.com26 Apr, 2013

Step IV – MQL Part#property copyright "Copyright ?2012, Vladimir Kaloshin"#property link "http://solyanka.net/"#property show_inputsextern string System_NET_HandlerName = "";// .NET Integration#include <System_NET_API.mqh>#include <System_NET_MQL.mqh>#include <System_NET.mqh>int init(){

System_NET_Init();System_NET_API_Init();System_NET_CallFunction(System_NET_HandlerName, "SendMail", "Expert initialized|Expert initialized");

}int start(){

System_NET_CallFunction("TickCounter", "Begin");System_NET_API_Start();System_NET_CallFunction("TickCounter", "End");

}int deinit(){

System_NET_CallFunction(System_NET_HandlerName, "SendMail", "Expert terminated|Expert terminated");System_NET_API_DeInit(); System_NET_DeInit();

}

string System_NET_MQL_Custom(string message[]){

if(message[1] == "METHOD_NAME")return("RETURN_VALUE");

return("###NORESULT###");}

IMPORTANT!!This is the setting in config fileA

I will remove some un-related codes in next slide

Ken, Y.K. Au kenykau@gmail.com26 Apr, 2013

Step IV – MQL Part#property copyright "Copyright ?2012, Vladimir Kaloshin"#property link "http://solyanka.net/"#property show_inputs#include <System_NET_API.mqh>#include <System_NET_MQL.mqh>#include <System_NET.mqh>

extern string System_NET_HandlerName = "ScreenCapture";

int init(){ System_NET_Init(); System_NET_API_Init();}int start(){ System_NET_API_Start();}int deinit(){ System_NET_API_DeInit(); System_NET_DeInit();}string System_NET_MQL_Custom(string message[]){ if(message[1] == "METHOD_NAME") return("RETURN_VALUE"); return("###NORESULT###");}

Remember this?

NOT RECOMMENTED in practice! You can type your Handler name in input form!

Ken, Y.K. Au kenykau@gmail.com26 Apr, 2013

Step V – Taste It

• After compile the mql code, we are almost there.

• Run the Shell.exe in the Shell_Backup folder. (If there is problem in running the Shell.exe, please try run as Administrator)

Ken, Y.K. Au kenykau@gmail.com26 Apr, 2013

Step V – Taste It

• Attach Expert_NET into your chart. For instant result, I recommend you to put it into M1 chart.

• Nice! Isn’t it! You can find you captured file in experts/files folder

Ken, Y.K. Au kenykau@gmail.com26 Apr, 2013

Final Words

• Thanks Welly Tambunan and Vladimir Kaloshin again. With their works, programing and trading is going to be more fun!

• Suggest: I have not make any performance check for the TradePlatform. In it’s codeplex website, Vladimir has pointed out there will be slower compare with the native mql.

• Hope both of us can contribute to the project .