Amps

Monday, December 21, 2015

Visual Back Test EA and Indicator MT4

Visual Back Test EA and Indicator MT4 

2 step Fastest Test Expert Adviser and Forex Indicator MT4

1. Select MT4 Expert Adviser Tester set properties and parameter TF for back testing click at Visual

Click the Start testing slide bar at visual mode to slowest position and then go to step 2


2. Drag the indicator want to check to the visual chart

Monday, December 14, 2015

Example MQL4 Code Moving Average EA Check Pending Order

Example MQL4 Code Moving Average EA Check Pending Order

In the last chapster we learn about how to build expert advisor properties and link the extern variable 

Moving Average EA function. In this chapster we would learn open order condition from MetaTrader 

Moving Average EA Code

Moving Average sample expert advisor by MetaQuotes designed the coding as 5 block of code
Calculate Pending order
Optimal Lot or Trading Money Management
Open order condition
Close order condition
Activate on Tick Function

This Chapter we would learn about Calculation The pending order.

 Calculate Pending order

Calculate Pending order including function as below
Function Feature
int OrdersTotal(); Returns the number of market and pending orders.
bool OrderSelect The function selects an order for further processing.
Order index or order ticket number of ticket
Selecting flags
SELECT_BY_POS index in the order pool
SELECT_BY_TICKET index is order ticket
pool=MODE_TRADES
MODE_TRADES opened and pending orders
MODE_HISTORY closed and canceled order
string OrderSymbol(); The symbol name of the currently selected order
string Symbol(); Returns a text string with the name of the current financial
int OrderMagicNumber(); The identifying (magic) number of the currently selected order
int OrderType();
OP_BUY buy order
OP_SELL sell order
OP_BUYLIMIT buy limit pending order
OP_BUYSTOP buy stop pending order
OP_SELLLIMIT sell limit pending order
OP_SELLSTOP sell stop pending order

Mention to the code and using function in this part


Basic MQL4 Function creation example from document page of MQL4


Explian the code MA EA calculate pending order

First Step specify function name and return value to function
From the MA EA code this part would return Integer value to function, which when we would like to use this 

function that we should call this function with (string variable)

for(int i=0;i<OrdersTotal();i++) // check total pending order

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; // no action if have pending order
//if have pending order Buy or Sell count buys and sells variable
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
        {
         if(OrderType()==OP_BUY)  buys++;
         if(OrderType()==OP_SELL) sells++;
        }

//--- return total orders pending
   if(buys>0) return(buys);
   else       return(-sells);
}

Check order pending by function OrderSelect, which command in this part would check total order pass minor function SELECT_BY_POS and trade was opened or trade pending MODE_TRADE.
This if not have pending order would call open order function pass OrderType function

This Chapter we learn about how to check pending order in next chapter we would learn about Optimal Lot or money management


Saturday, December 12, 2015

Forex MQL4 EA Properties code 2

External variable or Extern Variable MQL4

From Last Chapter

Extern ones also determine the input parameters of an mql4 EA
They are available from the Properties window
Extern variables can be modified in the Properties window and MQL4 Program

This chapter we would talk about how to coding EA properties

Learn to know Moving Average Indicators




Learn to know Moving Average Functions

Function Name
double iMA
Function Parameter
Function Value Function Value Name Function Meaning
symbol NULL
ENUM_TIMEFRAMES

0 PERIOD_CURRENT
1 PERIOD_M1
5 PERIOD_M5
15 PERIOD_M15
30 PERIOD_M30
60 PERIOD_H1
240 PERIOD_H4
1440 PERIOD_D1
10080 PERIOD_W1
43200 PERIOD_MN1
ma_period Averaging period for calculation
MA shift Indicators line offset relate to the chart by timeframe
ENUM_MA_METHOD

0 MODE_SMA
1 MODE_EMA
2 MODE_SMMA
3 MODE_LWMA
ENUM_APPLIED_PRICE

applied_price 0 PRICE_CLOSE Close price
applied_price 1 PRICE_OPEN Open price
applied_price 2 PRICE_HIGH The maximum price for the period
applied_price 3 PRICE_LOW The minimum price for the period
applied_price 4 PRICE_MEDIAN Median price, (high + low)/2
applied_price 5 PRICE_TYPICAL Typical price, (high + low + close)/3
applied_price 6 PRICE_WEIGHTED Weighted close price, (high + low + close + close)/4
shift
Current candle is 0 (candle 1-N is count back from current candle)

iMA Function Moving Average from MetaQuotes Example

iMA Function Moving Average in MetaQuotes EA or Expert Advisor Examples have 2 lines use iMA function 

that's

ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);

This we would learning how to build EA properties for this function

Basic variable Data Type

Every Vaiable should contain and specific data type as below
int (integers)
double (real numbers)
bool (Boolean values, that is logical values)
string (values of string type)
color (values of color type)
datetime (values of date and time)

Extern MQL4 Variable Group

1. Input Value directly (Like input to Edit Box) to the MQL4 EA properties
2. Input Value pass Boolean drop down list to the MQL4 EA properties
3. Input Value pass EA Methode Function


Time to change the properties of MetaQuotes EA or Expert Advisor Examples code

Function from original code
ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);

This we would add 3 lines to select Time Frame, Moving Everage and Apply Price, so add code as below to EA properties 



Input Enum Variable to the Moving Average Function to the MQL4 code

We have 3 enum variable now

TimeFrameUsed
EMA_method1
Applied_Price1

from original iMA function in the code
ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);

Change to
ma=iMA(NULL,TimeFrameUsed,MovingPeriod,MovingShift,EMA_method1,Applied_Price1,0);


Test Run Moving Average EA on youtube


Friday, December 11, 2015

Forex MQL4 EA Properties Coding Learn Free 1

MQL4 EA Properties Coding

Learning from MetaQuotes Moving Average EA Example

Access MetaQuotes Language Editor

Open Data Folder 



Copy File Moving Average EA and Rename to New one



Check Properties and Activate Auto Trading





Check The original code Moving Average EA

Input variable MQL 4
Input variable with the input modifier can't be changed inside mql4-programs
input variables can be changed only by a user from the program properties window

Example in original code of moving average ea

input double Lots          =0.1;
input double MaximumRisk   =0.02;
input double DecreaseFactor=3;
input int    MovingPeriod  =12;
input int    MovingShift   =6;



Change The Variable Type from Original EA code

External variable or Extern Variable MQL4
Extern ones also determine the input parameters of an mql4 EA
They are available from the Properties window
Extern variables can be modified in the Properties window and MQL4 Program

so, we would add External variable in the properties part of EA and change input variable to extern variable code as below



Sunday, November 29, 2015

MT4 EA build procedure 1 MQL4 EA Structure

MT4 EA build procedure 1 MT4 EA Structure

MQL4 Property structure


//+------------------------------------------------------------------+
//|                                             test_bistechn_ea.mq4 |
//|                               Copyright 2015, BIS and Technology |
//|                                                 www.bistechn.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, BIS and Technology"
#property link      "www.bistechn.com"
#property version   "1.00"
#property strict

This part for declare the property owner of this EA or MQL4 code after Meta Editor complied this MT4 EA property would show in Metatrader program (MT4) part of Expert Advisors during we point this mouse to this EA.

Also this part used for declare public variable. (public variable would able used in any function in MT4 EA)

MT4 EA properties for setting basic parameter would declared in this part

MQL4 Initialization function


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  } 

The Initialization function part used for initialize EA instance Change the Time Frame Trading and etc.

MQL4 Expert deinitialization function


//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }

This part used for clean all draw line, arrow, which build by EA after not using

MQL4 Expert Start function 


//+------------------------------------------------------------------+
//| Expert Start function                                             |
//+------------------------------------------------------------------+
int start()
  {
//---
   
  }return (result);
//+------------------------------------------------------------------+

The MQL4 Expert Start Function used for create function what we want this EA working or trade instance open buy or sell and all of  activities we would like to do


Tuesday, September 29, 2015

Forex MT4 coding 2 variable Structure


MT4 variable structure

Look at MACD Sample code for example.


Properties show the code owner


Global variable

This part used for declare  global variable, which variable in this part would able to see and able to used by every function of code
(so these variable name in this part should be unique name)



Function variable

Variable in this part able to used in this part only unable to used by other function.




Forex MT4 EA coding Step1 Starting build The EA


First Step MT4 EA coding

Goto Menu Tools => Metaquotes Language Editors or F4
To access MetaEditor code Editors


Use MQL Wizard to tell what type of code we would build => Select Expert Advisor Template to build Expert Advisor


Input the name of MT4 EA, Author and Link (if have your web sites)


Select Function would like to build instance MT4 work under Timer, on ChartEvent and etc.