Experts: AIS2 Trading Robot

 

AIS2 Trading Robot:

Trading Robot

Author: Airat Safin

 

Hello

Which timeframe do you use?

 
Hello Tigersoft
Standard preset of AIS2 Trading Robot's main timeframe is M15.
In next modification AIS2 Trading Robot will have direct timeframe control.
Best regards
Ais
 

Hi AIS, I'm trying to do a back-test but seems like it is not placing any orders at all. I'm sure I'm following the correct procedure mentioned in the list of instructions. Don't know what else needs to be done. Is back-testing possible ? Please suggest.

 
Hi Parrymcd

Back-testing of AIS2 Trading Robot is possible.
First, try to start test with deposit value greater than 10000-100000 USD.
Then check order sizes in "Results" tab of Tester.

Best regards

Ais

 

Thank you for your prompt response. I have tried depositing 10,000 USD but it still does not place any orders. Tried to do a back-testing since Jan-2006 till date, no orders placed. Please help.

If you have any back-testing results that you can share with us that will be good.

 
Another probable reason is tester caches corruption.
Just delete "../tester" folder and rerun terminal.
 

A System: Alpari Ltd


Account: 1480225

Name: Airat Safin

Currency: USD

2009 March 23, 18:16

Closed Transactions:

Ticket

Open Time

Type

Size

Item

Price

S / L

T / P

Close Time

Price

Commission

Taxes

Swap

Profit

41007369

2009.03.23 00:00

buy

2.65

eurusd

1.36582

1.35444

1.36721

2009.03.23 03:35

1.36721

0.00

0.00

0.00

368.35

40959206

2009.03.20 11:48

sell

2.29

eurusd

1.35480

1.36843

1.34224

2009.03.23 04:51

1.36843

0.00

0.00

-7.79

-3 121.27

41014676

2009.03.23 03:35

buy

9.33

eurusd

1.36736

1.36412

1.37008

2009.03.23 08:16

1.37008

0.00

0.00

0.00

2 537.76

41025873

2009.03.23 08:16

buy

9.23

eurusd

1.37034

1.36696

1.37326

2009.03.23 08:31

1.37326

0.00

0.00

0.00

2 695.16

41027599

2009.03.23 08:31

buy

5.10

eurusd

1.37353

1.36720

1.37897

2009.03.23 09:51

1.36720

0.00

0.00

0.00

-3 228.30

41034974

2009.03.23 09:51

sell

8.12

eurusd

1.36720

1.37101

1.36395

2009.03.23 09:58

1.36464

0.00

0.00

0.00

2 078.72

41035873

2009.03.23 09:58

sell

4.85

eurusd

1.36445

1.37101

1.36120

2009.03.23 10:22

1.36343

0.00

0.00

0.00

494.70

41038687

2009.03.23 10:23

sell

6.44

eurusd

1.36259

1.36757

1.35763

2009.03.23 13:20

1.35889

0.00

0.00

0.00

2 382.80

41053084

2009.03.23 13:21

sell

5.03

eurusd

1.35857

1.36512

1.35481

2009.03.23 14:11

1.35481

0.00

0.00

0.00

1 891.28

41058013

2009.03.23 14:11

sell

4.81

eurusd

1.35486

1.35319

1.35076

2009.03.23 14:53

1.35076

0.00

0.00

0.00

1 972.10

41062660

2009.03.23 14:53

sell

3.88

eurusd

1.35061

1.34972

1.34493

2009.03.23 14:56

1.34972

0.00

0.00

0.00

345.32

41063312

2009.03.23 14:56

sell

3.48

eurusd

1.34956

1.35950

1.34388

2009.03.23 18:07

1.35950

0.00

0.00

0.00

-3 459.12

41079658

2009.03.23 18:07

buy

3.93

eurusd

1.35950

1.35104

1.36785

2009.03.23 18:16

1.36047

0.00

0.00

0.00

381.21

0.00

0.00

-7.79

5 338.71

Closed P/L:

5 330.92

Open Trades:

Ticket

Open Time

Type

Size

Item

Price

S / L

T / P

Price

Commission

Taxes

Swap

Profit

No transactions

0.00

0.00

0.00

0.00

Floating P/L:

0.00

Working Orders:

Ticket

Open Time

Type

Size

Item

Price

S / L

T / P

Market Price

No transactions

Summary:

Deposit/Withdrawal:

0.00

Credit Facility:

0.00

Closed Trade P/L:

5 330.92

Floating P/L:

0.00

Margin:

0.00

Balance:

83 580.36

Equity:

83 580.36

Free Margin:

83 580.36

Details:

Graph

Gross Profit:

15 147.40

Gross Loss:

9 816.48

Total Net Profit:

5 330.92

Profit Factor:

1.54

Expected Payoff:

410.07

Absolute Drawdown:

2 760.71

Maximal Drawdown:

3 459.12 (3.99%)

Relative Drawdown:

4.00% (3 228.30)

Total Trades:

13

Short Positions (won %):

8 (75.00%)

Long Positions (won %):

5 (80.00%)

Profit Trades (% of total):

10 (76.92%)

Loss trades (% of total):

3 (23.08%)

Largest

profit trade:

2 695.16

loss trade:

-3 459.12

Average

profit trade:

1 514.74

loss trade:

-3 272.16

Maximum

consecutive wins ($):

6 (9 164.92)

consecutive losses ($):

1 (-3 459.12)

Maximal

consecutive profit (count):

9 164.92 (6)

consecutive loss (count):

-3 459.12 (1)

Average

consecutive wins:

3

consecutive losses:

1

 

3.2. Sample 2 "Capital defence":
     3.2.1. this Sample is part of AIS2 Trading Robot: Modification AIS20004;
     3.2.2. main feature is that predefined part of account equity conservation guaranteed;
     3.2.3. code of the Sample:
 
//< Sample 2 "Capital defence" >
 
//< 3.1. Risk Management Preset 2 >```````````````````````````````````````````````````````````````````````````//<  32>
                                                                                                              //<  33>
extern double aed.AccountReserve      = 0.20                                                                ; //<  34>
extern double aed.OrderReserve        = 0.04                                                                ; //<  35>
                                                                                                              //<  36>
//</3.1. Risk Management Preset 2 >```````````````````````````````````````````````````````````````````````````//<  37>
...
//< 4.2. System Controls 28 >`````````````````````````````````````````````````````````````````````````````````//<  64>
...
int           avi.SystemFlag                                                                                ; //<  66>
...
double        avd.Capital                                                                                   ; //<  86>
double        avd.PeakTime                                                                                  ; //<  87>
double        avd.PeakEquity                                                                                ; //<  88>
double        avd.InitialEquity                                                                             ; //<  89>
double        avd.InitialCapital                                                                            ; //<  90>
double        avd.EquityReserve                                                                             ; //<  91>
...
//</4.2. System Controls 28 >`````````````````````````````````````````````````````````````````````````````````//<  99>
...
//< 4.7. Risk Management Data 9 >`````````````````````````````````````````````````````````````````````````````//< 178>
...
double        avd.VARLimit                                                                                  ; //< 185>
...
//</4.7. Risk Management Data 9 >`````````````````````````````````````````````````````````````````````````````//< 190>
...
//< 5. Program Initialization 21 >============================================================================//< 194>
                                                                                                              //< 195>
int    init                          ()                                                                       //< 196>
{                                                                                                             //< 197>
...
avd.PeakTime             = TimeLocal     ()                                                                 ; //< 204>
avd.PeakEquity           = AccountEquity ()                                                                 ; //< 205>
avd.InitialEquity        = AccountEquity ()                                                                 ; //< 206>
avd.InitialCapital       = avd.PeakEquity   * ( 1 - aed.AccountReserve )                                    ; //< 207>
...
}                                                                                                             //< 246>
//</5. Program Initialization 21 >============================================================================//< 247>
...
//< 7. Main Program 266 >=====================================================================================//< 276>
                                                                                                              //< 277>
int    start                         ()                                                                       //< 278>
{                                                                                                             //< 279>
...
//< 7.3. Equity Control 6 >```````````````````````````````````````````````````````````````````````````````````//< 382>
                                                                                                              //< 383>
if   ( AccountEquity ()  - avd.PeakEquity > 0      )                                                          //< 384>
     { avd.PeakEquity    = AccountEquity ()                                                                 ; //< 385>
       avd.PeakTime      = TimeLocal     ()                                                               ; } //< 386>
                                                                                                              //< 387>
       avd.Capital       = avd.PeakEquity          * ( 1 - aed.AccountReserve )                             ; //< 388>
       avd.EquityReserve = AccountEquity ()        - avd.Capital                                            ; //< 389>
       avd.VARLimit      = AccountEquity ()        * aed.OrderReserve                                       ; //< 390>
                                                                                                              //< 391>
if   ( avd.EquityReserve - avd.VARLimit   < 0      )                                                          //< 392>
     { avs.SystemMessage = "System stop"                                             ; avi.SystemFlag = 0 ; } //< 393>
                                                                                                              //< 394>
//</7.3. Equity Control 6 >```````````````````````````````````````````````````````````````````````````````````//< 395>
...
}                                                                                                             //< 705>
//</7. Main Program 266 >=====================================================================================//< 706>
   
//</Sample 2 "Capital defence" >   
 
 
3.2.4. clarification of Sample 2 "Capital defence": 3.2.4.1. this techinque is total control principle implementation; 3.2.4.2. this techinque is risk management method;      3.2.4.3. essence of this one is to forbid system activity in case of deposit reserve exhausting:                3.2.4.3.1. size of deposit reserve is "aed.AccountReserve = 0.20" according to p.2.3.4.2.;                 3.2.4.3.2. size of order reserve is "aed.OrderReserve = 0.04";            3.2.4.3.3. deposit reserve value is equal to "avd.EquityReserve";             3.2.4.3.4. current deposit reserve value is computing in lines 388-390;              3.2.4.3.5. in line 392, there is deposit reserve check;              3.2.4.3.6. if deposit reserve less than order reserve flag "avi.SystemFlag = 0" is set;                 3.2.4.3.7. flag "avi.SystemFlag = 0" forbids system activity. 3.3. One of the samples of maximum information principle implementation is AIS1 Advanced Indicator, that: 3.3.1. indicates tens of market measures in both graphical and alphanumeric presentations; 3.3.2. remains easy to use for decision making and monitoring purposes.

AIS1 Advanced Indicator

3.4. Another sample of maximum information principle implementation is AIS2 Trading Robot's monitoring panel, that:   3.4.1. indicates in real time a lot of robot's data; 3.4.2. advantages to make substantiated decisions about immediate human intervention.

AIS2 Trading Robot

4. Conclusion 4.1. The Ultimate Certainty Concept is one of a number possible ones. 4.2. Aforestated implementation samples are always in continuous progress. About the author Name        Airat Safin Born        09 December 1967 Location    Kazan, Russia Experience  radiophysics             programming             financial analysis             project financing             risk management Education   1985-1990, Kazan State University, Faculty of Physics             1995-1998, Moscow University of Consumer Cooperation, Special Faculty
 
Ultimate Certainty: Automatic Trading Concept of AIS Series Software
 
 
 
Content:
 
1. Introduction
2. Fundamentals and core principles
3. Implementation samples
4. Conclusion
 
 
 
1. Introduction
 
1.1. Automatic trading is a rapidly growing field of financial industry.
1.2. Today there is wide spectrum of approaches to creating automatic trading systems.
1.3. Main purpose of this article is to clarify underlying concept of following MQL4 software products:
     1.3.1. AIS Trading Robots;
     1.3.2. AIS Indicators.
1.4. This article is addressed to the automatic trading system developers.
1.5. Notion "trading systems" means marginal trading systems for MetaTrader 4 Client Terminal.
 
 
 
2. Fundamentals and core principles
 
2.1. Concept of AIS series software is Ultimate Certainty.
 
2.2. Ultimate Certainty means highest quality of preparation for decision making and execution.
 
2.3. Fundamentals of Ultimate Certainty Concept are:
 
     2.3.1. automatic trading system functional model:
            2.3.1.1. data feeding,
            2.3.1.2. data processing,
            2.3.1.3. decision making,
            2.3.1.4. execution;
 
     2.3.2. marginal trading model:
            2.3.2.1. target of the activity is capital gain by price fluctuations exploiting;
            2.3.2.2. market risk is extremely high due to following conditions:
                     2.3.2.2.1. directions of fluctuations are equiprobable,
                     2.3.2.2.2. rate of fluctuations is very high,
                     2.3.2.2.3. amplitude of fluctuations has high speed of growth;
            2.3.2.3. return = sum of trade profits - sum of trade losses;
            2.3.2.4. trade losses are strictly controlled values;
 
     2.3.3. market risk model:
            2.3.3.1. market risk, that thereafter is denoted "risk", is threat of loss due to price fluctuations;
            2.3.3.2. main risk evaluation unit is monetary unit;
            2.3.3.3. risk evaluation formula:
                     2.3.3.3.1. risk of single trade = estimate of loss probabilty x estimate of loss value,
                     2.3.3.3.2. estimate of loss probabilty = loss trades / total trades,
                     2.3.3.3.3. estimate of loss value = distance between open price and stop-level x order size;
 
     2.3.4. risk management model:
            2.3.4.1. deposit, that is account equity, is sum of two parts:
                     2.3.4.1.1. capital,
                     2.3.4.1.2. reserve for eventual losses, or simply "deposit reserve";
            2.3.4.2. capital size and deposit reserve size are fixed shares of deposit;
            2.3.4.3. capital is margin facility;
            2.3.4.4. deposit reserve is trade losses compensation facility;
            2.3.4.5. deposit reserve size must be set by investor;
            2.3.4.6. trade losses decrease deposit reserve size;
            2.3.4.7. in case of deposit reserve exhausting system activity is stopped;
            2.3.4.8. trade profits increase deposit reserve size;
            2.3.4.9. in case of deposit reserve filling, capital and deposit values are enlarging;
            2.3.4.10. for each trade fixed share of deposit reserve, that is order reserve, is assigning,
            2.3.4.11. single trade risk is limited by order reserve value according to following algorithm:
                      2.3.4.11.1. create fixed size order reserve,
                      2.3.4.11.2. define price drawdown limit for the single trade,
                      2.3.4.11.3. compute order size limit for given order reserve and price drawdown limit,
                      2.3.4.11.4. compute maximal allowed order size for the obtained order size limit;
            2.3.4.12. hence, the risk management methods defend investor's capital from possible losses.
 
2.4. Core principles of Ultimate Certainty Concept are:
     2.4.1. maximum information principle;
     2.4.2. total control principle.
 
2.5. Maximum information principle:
     2.5.1. means that decision making must be based on maximum available information;
     2.5.2. is aimed to increasing "profit trades / loss trades" ratio;
     2.5.3. is contained in set of data feeding and data processing algorithms.
 
2.6. Total control principle:
     2.6.1. means that accepted decisions must have highest level of execution reliability;
     2.6.2. is aimed to improve and enhance methods of control;
     2.6.3. is contained in set of following algorithms:
            2.6.3.1. trading system and human interaction;
            2.6.3.1. trading system and external control software interaction;
            2.6.3.2. trading system modules interaction.
 
 
 
3. Implementation samples
 
3.1. Sample 1 "External control":
     3.1.1. this Sample is part of AIS2 Trading Robot: Modification AIS20004;
     3.1.2. main feature is control interface for human trader or external MQL4 software;
     3.1.3. code of the Sample:
 
//< Sample 1 "External control" >
 
//< 1. Property 7 >===========================================================================================//<   1>
                                                                                                              //<   2>
#property     copyright                 "Copyright (C) 2009, MetaQuotes Software Corp."                       //<   3>
#property     link                      "http://www.metaquotes.net"                                           //<   4>
                                                                                                              //<   5>
#define       A.System.Series           "AIS"                                                                 //<   6>
#define       A.System.Modification     "20004"                                                               //<   7>
#define       A.System.ReleaseDate      "2009.03.22"                                                          //<   8>
#define       A.System.Program          "Trading Robot"                                                       //<   9>
#define       A.System.Programmer       "Airat Safin                           https://www.mql5.com/en/users/Ais" //<  10>
                                                                                                              //<  11>
//</1. Property 7 >===========================================================================================//<  12>
...
//< 4.2. System Controls 28 >`````````````````````````````````````````````````````````````````````````````````//<  64>
...
int           avi.SystemFlag                                                                                ; //<  66>
int           avi.TradingFlag                                                                               ; //<  67>
int           avi.MonitorFlag                                                                               ; //<  68>
int           avi.LiveModeFlag                                                                              ; //<  69>
...
//</4.2. System Controls 28 >`````````````````````````````````````````````````````````````````````````````````//<  99>
...
//< 4.3.3. Trading Preset Setup 6 >                                                                           //< 113>
string        avs.SetupTrading                                                                              ; //< 114>
...
//</4.3.3. Trading Preset Setup 6 >                                                                           //< 120>
...
//< 5. Program Initialization 21 >============================================================================//< 194>
                                                                                                              //< 195>
int    init                          ()                                                                       //< 196>
{                                                                                                             //< 197>
...
afr.CreateSetup                      ()                                                                     ; //< 237>
...
}                                                                                                             //< 246>
//</5. Program Initialization 21 >============================================================================//< 247>
...
//< A.System.Extra: Function 02 >`````````````````````````````````````````````````````````````````````````````//< 807>
int    afr.CreateSetup               ()                                                               //   29 //< 808>
{                                                                                                             //< 809>
       avs.SetupPrefix      = A.System.Series      + A.System.Modification + ".Setup."                      ; //< 810>
...
       avs.SetupTrading     = avs.SetupPrefix      + "2.1." + "Trading"                                     ; //< 815>
...
}                                                                                                             //< 845>
//</A.System.Extra: Function 02 >`````````````````````````````````````````````````````````````````````````````//< 846>
...
//< 7. Main Program 266 >=====================================================================================//< 276>
                                                                                                              //< 277>
int    start                         ()                                                                       //< 278>
{                                                                                                             //< 279>
...
//< 7.1.3. All Modes Subroutine 8 >                                                                           //< 313>
if (   GlobalVariableGet      ( avs.SetupTrading )  == 1 )                                                    //< 314>
   {   avi.SystemFlag         = 1                                                                         ;   //< 315>
       avi.TradingFlag        = 1                                                                         ;   //< 316>
       avs.SystemMessage      = "Trading is enabled"                                                      ; } //< 317>
else                                                                                                          //< 318>
   {   avi.SystemFlag         = 0                                                                         ;   //< 319>
       avi.TradingFlag        = 0                                                                         ;   //< 320>
       avs.SystemMessage      = "Trading is disabled"                                                     ; } //< 321>
//</7.1.3. All Modes Subroutine 8 >                                                                           //< 322>
...
}                                                                                                             //< 705>
//</7. Main Program 266 >=====================================================================================//< 706>
 
//</Sample 1 "External control" >
     3.1.4. clarification of Sample 1 "External control":             3.1.4.1. this techinque is total control principle implementation;             3.1.4.2. essence of this one is to give external control via global variables of terminal;                      3.1.4.2.1. "avi.TradingFlag" variable controls trading module activity permission;                      3.1.4.2.2. "avs.SetupTrading" variable is the name of global variable;                      3.1.4.2.3. in lines 316 and 320 "avi.TradingFlag" value depends on the global variable value;                      3.1.4.2.4. the global variable is accessible for human trader or external MQL4 program;                      3.1.4.2.5. hence, "avs.SetupTrading" variable is a system control interface;      3.1.5. demonstration of Sample 1 "External control":             3.1.5.1. create "ACONTROL.MQ4" file with below stated content;             3.1.5.1. copy "ACONTROL.MQ4" file to ".../experts/indicators" folder;             3.1.5.2. compile "ACONTROL.MQ4" file;             3.1.5.3. find "ACONTROL" item in "Custom Indicator" list;             3.1.5.4. drag-and-drop it on the chart with AIS2 Trading Robot: Modification AIS20004;             3.1.5.5. change of following trading robot's parameters will start:                      3.1.5.5.1. order limit size "Order Limit",                      3.1.5.5.2. trailing factor "Preset Trail";             3.1.5.6. code of "ACONTROL.MQ4" program:
//< Content of ACONTROL.MQ4 >
 
#property                        indicator_chart_window                                                       //<   1>
                                                                                                              //<   2>
#define                          acs.Control.TradingFlag   "AIS20003.Setup.2.1.Trading"                       //<   3>
#define                          acs.Control.Parameter.1   "AIS20003.Setup.1.1.OrderReserve"                  //<   4>
#define                          acs.Control.Parameter.2   "AIS20003.Setup.2.6.TrailFactor"                   //<   5>
                                                                                                              //<   6>
int    start ()                                                                                               //<   7>
{                                                                                                             //<   8>
double ald.Control.Parameter.1 = GlobalVariableGet       ( acs.Control.Parameter.1 )                        ; //<   9>
double ald.Control.Parameter.2 = GlobalVariableGet       ( acs.Control.Parameter.2 )                        ; //<  10>
                                                                                                              //<  11>
static int    ali.ControlFlag                                                                               ; //<  12>
                                                                                                              //<  13>
if   ( ( High [ 1 ] - Low [ 1 ] ) - ( High [ 2 ] - Low [ 2 ] ) > 0 )                                          //<  14>
       ali.ControlFlag         = 1                                                                          ; //<  15>
else   ali.ControlFlag         = 0                                                                          ; //<  16>
                                                                                                              //<  17>
if   ( ali.ControlFlag         > 0                       )                                                    //<  18>
     {                                                                                                        //<  19>
       ald.Control.Parameter.1 = ald.Control.Parameter.1 * 1.001                                            ; //<  20>
       ald.Control.Parameter.2 = ald.Control.Parameter.2 * 0.99                                             ; //<  21>
     }                                                                                                        //<  22>
else                                                                                                          //<  23>
     {                                                                                                        //<  24>
       ald.Control.Parameter.1 = ald.Control.Parameter.1 * 0.99                                             ; //<  25>
       ald.Control.Parameter.2 = ald.Control.Parameter.2 * 1.001                                            ; //<  26>
     }                                                                                                        //<  27>
                                                                                                              //<  28>
GlobalVariableSet              ( acs.Control.TradingFlag , 0                       )                        ; //<  29>
GlobalVariableSet              ( acs.Control.Parameter.1 , ald.Control.Parameter.1 )                        ; //<  30>
GlobalVariableSet              ( acs.Control.Parameter.2 , ald.Control.Parameter.2 )                        ; //<  31>
}                                                                                                             //<  32>
 
//</Content of ACONTROL.MQ4 > 
 

I noticed that it likes to by on the top :)

Reason: