Simple Tutorial: Ken, Y.K. Au 26 Apr, 2013

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 21

TradePlatform.

net & forexsharp

Simple Tutorial

Ken, Y.K. Au 26 Apr, 2013 kenykau@gmail.com


Disclamer
• All the logos and/or copyrighted materials are ow
ned by their respective owner.
• This is tutorial is only focus on how to make Trad
ePlatform.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 K
aloshin for their great effort to create forexsharp
and TradePlatform.net

Ken, Y.K. Au 26 Apr, 2013 kenykau@gmail.com


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.net
https://tradeplatform.codeplex.com
forexsharp
https://github.com/welly87/forexsharp

Ken, Y.K. Au 26 Apr, 2013 kenykau@gmail.com


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 26 Apr, 2013 kenykau@gmail.com


Step II – Compile the project
1. Open the FXSharp project
2. Click OK in the VS2012 dialog

Open It!!! 1

2
Click OK

Ken, Y.K. Au 26 Apr, 2013 kenykau@gmail.com


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 26 Apr, 2013 kenykau@gmail.com


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 26 Apr, 2013 kenykau@gmail.com


Step II (A)– Compile the project
• Once installed the NUNIT package, we can buil
d it now by Press F6
• There may have some warnings. You can ignor
e it.
• Now you can study the code for your own inte
rest.

Ken, Y.K. Au 26 Apr, 2013 kenykau@gmail.com


Step II(B) – Another Approach
• In Step II (A), we build the project and study th
e code. There is another approach that is muc
h easier.
• Recall after we download the project file, extra
ct 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 26 Apr, 2013 kenykau@gmail.com


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 f
older into the project:
TradePlatform.MT4.Core.dll
TradePlatform.MT4.Data.dll
TradePlatform.MT4.SDK.API.dll
TradePlatform.MT4.SDK.Library.dll

Ken, Y.K. Au 26 Apr, 2013 kenykau@gmail.com


Step III – Expert Advisor
• EA Purpose:
– Capture the screen when there is a new bar forme
d.
– The file name of the captured file will be in the for
m 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 i
s the number of bars

Ken, Y.K. Au 26 Apr, 2013 kenykau@gmail.com


Step III – Expert Advisor
using System; • Rename Class1.cs to ScreenCapture.cs
using System.Collections.Generic; • Type the following codes
using System.Text;
using TradePlatform.MT4.Core; • Please pay attention to the Arrows
using TradePlatform.MT4.SDK.API; • After complete coding, press F6 to build the solution
• You will get the FxTest.dll
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);
}
}
}

Ken, Y.K. Au 26 Apr, 2013 kenykau@gmail.com


Step III – Expert Advisor (config fil
e)
• I am not a programmer, it is my hobby to write sm
all programs to solve silly problem. I do not have e
nough 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 f
older or create add a new one.
• I added the Shell.exe.config to my project

Ken, Y.K. Au 26 Apr, 2013 kenykau@gmail.com


Step III – Expert Advisor (config fil
e)
I collapse some of the section and show the most important part only.
Please note the arrows!!!

A B C

A. Will be refer by mql code


B. The full class name of the EA
C. The assembly name

Ken, Y.K. Au 26 Apr, 2013 kenykau@gmail.com


Step III – Expert Advisor
• We are almost done here!
• Copy the assembly (FxTest.dll) and config (Shel
l.exe.config) files to Shell_Backup folder.
• We can leave the .NET part for a while.

Ken, Y.K. Au 26 Apr, 2013 kenykau@gmail.com


Step IV – MQL Part
• Copy the expert folder in the Terminal Folder t
o your MT4 folder.
• Use Meta Editor to open Expert_NET.mql in M
T4\expert folder.
• Let’s look at the mql code

Ken, Y.K. Au 26 Apr, 2013 kenykau@gmail.com


Step IV – MQL Part
#property copyright "Copyright ?2012, Vladimir Kaloshin"
#property link "http://solyanka.net/"
#property show_inputs
extern string System_NET_HandlerName = ""; IMPORTANT!!
// .NET Integration
#include <System_NET_API.mqh> This is the A setting in config file
#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"); I will remove some un-related codes in next slide
return("###NORESULT###");
}

Ken, Y.K. Au 26 Apr, 2013 kenykau@gmail.com


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";


NOT RECOMMENTED in practice!
int init()
You can type your Handler name in input form!
{
System_NET_Init(); Remember this?
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###");
}

Ken, Y.K. Au 26 Apr, 2013 kenykau@gmail.com


Step V – Taste It
• After compile the mql code, we are almost the
re.
• Run the Shell.exe in the Shell_Backup folder. (I
f there is problem in running the Shell.exe, ple
ase try run as Administrator)

Ken, Y.K. Au 26 Apr, 2013 kenykau@gmail.com


Step V – Taste It
• Attach Expert_NET into your chart. For instant r
esult, I recommend you to put it into M1 chart.

• Nice! Isn’t it! You can find you captured file in e


xperts/files folder

Ken, Y.K. Au 26 Apr, 2013 kenykau@gmail.com


Final Words
• Thanks Welly Tambunan and Vladimir Kaloshin
again. With their works, programing and tradi
ng is going to be more fun!
• Suggest: I have not make any performance che
ck for the TradePlatform. In it’s codeplex websi
te, Vladimir has pointed out there will be slow
er compare with the native mql.
• Hope both of us can contribute to the project .

Ken, Y.K. Au 26 Apr, 2013 kenykau@gmail.com

You might also like