//+==================================================================+
//| Exp_6.mq4 |
//| Copyright © 2007, Nikolay Kositsin |
//| Khabarovsk, [email protected] |
//+==================================================================+
#property copyright "Copyright © 2007, Nikolay Kositsin"
#property link "[email protected]"
//----+ +-------------------------------------------------------------------------------+
//---- EA INPUT PARAMETERS FOR BUY TRADES
extern bool Test_Up = true;//filter of trade calculations direction
extern int Timeframe_Up = 240;
extern double Money_Management_Up = 0.1;
extern int LengthA_Up = 4; // smoothing depth of the quick moving
extern int PhaseA_Up = 100; // parameter changing in the range
//-100 ... +100, influences the quality of transient process of quick moving
extern int IPCA_Up = 0;/* Selecting prices, on which the indicator will be
calculated by the quick moving (0-CLOSE, 1-OPEN, 2-HIGH, 3-LOW, 4-MEDIAN, 5-TYPICAL,
6-WEIGHTED, 7-Heiken Ashi Close, 8-SIMPL, 9-TRENDFOLLOW, 10-0.5*TRENDFOLLOW,
11-Heiken Ashi Low, 12-Heiken Ashi High, 13-Heiken Ashi Open,
14-Heiken Ashi Close.) */
extern int LengthB_Up = 4; // smoothing depth increment of slow moving to quick one
extern int PhaseB_Up = 100; // parameter changing in the range
//-100 ... +100, influences the quality of transient process of slow moving;
extern int IPCB_Up = 0;/* Selecting prices, on which the indicator will be
calculated by the slow moving (0-CLOSE, 1-OPEN, 2-HIGH, 3-LOW, 4-MEDIAN, 5-TYPICAL,
6-WEIGHTED, 7-Heiken Ashi Close, 8-SIMPL, 9-TRENDFOLLOW, 10-0.5*TRENDFOLLOW,
11-Heiken Ashi Low, 12-Heiken Ashi High, 13-Heiken Ashi Open,
14-Heiken Ashi Close.) */
extern int STOPLOSS_Up = 50; // stop loss
extern int TAKEPROFIT_Up = 100; // take profit
extern bool ClosePos_Up = true; // forced position closing allowed
//----+ +-------------------------------------------------------------------------------+
//---- EA INPUT PARAMETERS FOR SELL TRADES
extern bool Test_Dn = true;//filter of trade calculations direction
extern int Timeframe_Dn = 240;
extern double Money_Management_Dn = 0.1;
extern int LengthA_Dn = 4; // smoothing depth of the quick moving
extern int PhaseA_Dn = 100; // parameter changing in the range
// -100 ... +100, influences the quality of transient process of quick moving;
extern int IPCA_Dn = 0;/* Selecting prices, on which the indicator will be
calculated by the quick moving (0-CLOSE, 1-OPEN, 2-HIGH, 3-LOW, 4-MEDIAN, 5-TYPICAL,
6-WEIGHTED, 7-Heiken Ashi Close, 8-SIMPL, 9-TRENDFOLLOW, 10-0.5*TRENDFOLLOW,
11-Heiken Ashi Low, 12-Heiken Ashi High, 13-Heiken Ashi Open,
14-Heiken Ashi Close.) */
extern int LengthB_Dn = 4; // smoothing depth increment of slow moving to quick one
extern int PhaseB_Dn = 100; // parameter changing in the range
// -100 ... +100, influences the quality of transient process of slow moving;
extern int IPCB_Dn = 0;/* Selecting prices, on which the indicator will be
calculated by the slow moving(0-CLOSE, 1-OPEN, 2-HIGH, 3-LOW, 4-MEDIAN, 5-TYPICAL,
6-WEIGHTED, 7-Heiken Ashi Close, 8-SIMPL, 9-TRENDFOLLOW, 10-0.5*TRENDFOLLOW,
11-Heiken Ashi Low, 12-Heiken Ashi High, 13-Heiken Ashi Open,
14-Heiken Ashi Close.) */
extern int STOPLOSS_Dn = 50; // stop loss
extern int TAKEPROFIT_Dn = 100; // take profit
extern bool ClosePos_Dn = true; // forced position closing allowed
//----+ +-------------------------------------------------------------------------------+
//---- Integer variables for the minimum of calculation bars
int MinBar_Up, MinBar_Dn;
//+==================================================================+
//| Custom Expert functions |
//+==================================================================+
#include <Lite_EXPERT1.mqh>
//+==================================================================+
//| Custom Expert initialization function |
//+==================================================================+
int init()
{
//---- Checking the correctness of Timeframe_Up variable value
if (Timeframe_Up != 1)
if (Timeframe_Up != 5)
if (Timeframe_Up != 15)
if (Timeframe_Up != 30)
if (Timeframe_Up != 60)
if (Timeframe_Up != 240)
if (Timeframe_Up != 1440)
Print(StringConcatenate("Parameter Timeframe_Up cannot ",
"be equal to ", Timeframe_Up, "!!!"));
//---- Checking the correctness of Timeframe_Dn variable value
if (Timeframe_Dn != 1)
if (Timeframe_Dn != 5)
if (Timeframe_Dn != 15)
if (Timeframe_Dn != 30)
if (Timeframe_Dn != 60)
if (Timeframe_Dn != 240)
if (Timeframe_Dn != 1440)
Print(StringConcatenate("Parameter Timeframe_Dn cannot ",
"be equal to ", Timeframe_Dn, "!!!"));
//---- Initialization of variables
MinBar_Up = 4 + 30;
MinBar_Dn = 4 + 30;
//---- end of initialization
return(0);
}
//+==================================================================+
//| expert deinitialization function |
//+==================================================================+
int deinit()
{
//----+
//---- End of EA deinitialization
return(0);
//----+
}
//+==================================================================+
//| Custom Expert iteration function |
//+==================================================================+
int start()
{
//----+ Declaring local variables
int bar;
double MovA[2], MovB[2];
//----+ Declaring static variables
static int LastBars_Up, LastBars_Dn;
static bool BUY_Sign, BUY_Stop, SELL_Sign, SELL_Stop;
//----++ CODE FOR LONG POSITIONS
if (Test_Up)
{
int IBARS_Up = iBars(NULL, Timeframe_Up);
if (IBARS_Up >= MinBar_Up)
{
if (LastBars_Up != IBARS_Up)
{
//----+ Initialization of variables
BUY_Sign = false;
BUY_Stop = false;
LastBars_Up = IBARS_Up;
//----+ CALCULATING INDICATOR VALUES AND UPLOADING THEM TO BUFFERS
for(bar = 1; bar < 3; bar++)
MovA[bar - 1] =
iCustom(NULL, Timeframe_Up,
"JJMA", LengthA_Up, PhaseA_Up,
0, IPCA_Up, 0, bar);
for(bar = 1; bar < 3; bar++)
MovB[bar - 1] =
iCustom(NULL, Timeframe_Up,
"JJMA", LengthA_Up + LengthB_Up, PhaseB_Up,
0, IPCB_Up, 0, bar);
//----+ DEFINING SIGNALS FOR TRADES
if ( MovA[1] < MovB[1])
if ( MovA[0] > MovB[0])
BUY_Sign = true;
if ( MovA[0] > MovB[0])
BUY_Stop = true;
}
//----+ EXECUTION OF TRADES
if (!OpenBuyOrder1(BUY_Sign, 1, Money_Management_Up,
STOPLOSS_Up, TAKEPROFIT_Up))
return(-1);
if (ClosePos_Up)
if (!CloseOrder1(BUY_Stop, 1))
return(-1);
}
}
//----++ CODE FOR SHORT POSITIONS
if (Test_Dn)
{
int IBARS_Dn = iBars(NULL, Timeframe_Dn);
if (IBARS_Dn >= MinBar_Dn)
{
if (LastBars_Dn != IBARS_Dn)
{
//----+ Initialization of variables
SELL_Sign = false;
SELL_Stop = false;
LastBars_Dn = IBARS_Dn;
//----+ CALCULATING INDICATOR VALUES AND UPLOADING THEM TO BUFFERS
for(bar = 1; bar < 3; bar++)
MovA[bar - 1] =
iCustom(NULL, Timeframe_Dn,
"JJMA", LengthA_Dn, PhaseA_Dn,
0, IPCA_Dn, 0, bar);
for(bar = 1; bar < 3; bar++)
MovB[bar - 1] =
iCustom(NULL, Timeframe_Dn,
"JJMA", LengthA_Dn + LengthB_Dn, PhaseB_Dn,
0, IPCB_Dn, 0, bar);
//----+ DEFINING SIGNALS FOR TRADES
if ( MovA[1] > MovB[1])
if ( MovA[0] < MovB[0])
SELL_Sign = true;
if ( MovA[0] < MovB[0])
SELL_Stop = true;
}
//----+ EXECUTION OF TRADES
if (!OpenSellOrder1(SELL_Sign, 2, Money_Management_Dn,
STOPLOSS_Dn, TAKEPROFIT_Dn))
return(-1);
if (ClosePos_Dn)
if (!CloseOrder1(SELL_Stop, 2))
return(-1);
}
}
//----+
return(0);
}
//+------------------------------------------------------------------+