Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

001 Free EA Source code: Simple_BollingerBand EA

Free Expert Adviser (EA) Source code: Simple_BollingerBand_EA

Welcome to our first free EA source code. This is a well-tested and working MT4 EA. you can either copy the code snippet and paste directly on your meta editor 4 or download the source code below.

Disclaimer: All users of this EA agree to take full responsibility of the risk that comes with forex trading. The Primary aim of uploading this EA source code is purely for educational purpose. This is to assist MT4 programmers with source codes, scripts, functions and logic library for their individual project. Forex traders are also free to compile, modify and use this Trading robot for their personal use bearing in mind the risk clause stated above. This code is totally free and should not be commercialized or sold.

Properties of the EA

Name of EA: Simple_BollingerBand_EA
Serial Number: 001
Code status: MetaQuote Language (MQL4)

Components of the EA

  1. Trading Indicators: Bollinger Band ((Settings: Default: 20 SMA) (we are using M15))
  2. Trading strategy: When the when candle_2 closes outside the bollinger band and candle_1 opens outside the bollinger band and closes inside the bollinger band.
    Trade management:
     This EA (Simple_BollingerBand_EA) has two simple trade execution parameters:
    1. Trade opening criteria: This involves fulfilling the trading strategy criteria.
    2. Trade closing criteria: This includes the stoploss and take profit parameters or criteria.
  3. Trading within Time ranges: The Simple_BollingerBand_EA also a component (Function) called “CheckTradingTime()” that allows trades to be open within specific time ranges. for example, between 7:00am GMT+1 to 5:00pm GMT+1. This is to avoid the night low trading volume period which happens to be the Asian Market session 

The working mechanism of this EA depends on the parameters of two trading indicators.

Buy Entry strategies:

  1. Candle_2: Bearish candle (close2
  2. Candle_1: Bullish candle (close1>open1)
  3. Bearish candle _2 closing outside the lower Bollinger band (close2
  4. Bullish candle_1 opening outside the lower Bollinger band (open1
  5. Bullish candle_1 closing inside the lower bollinger band (close1>lower1)
  6. High_1 is less than upper bollinger band (high1
  7. To ensure that trade opens between 8am and 5:30pm us (bool CheckTradingTime() ==true)

Sell Entry strategies:

  1. Candle_2: Bullish candle (close2>open2)
  2. Candle_1: Bearish candle (close1
  3. Bullish candle _2 closing outside the upper Bollinger band (close2>upper2)
  4. Bullish candle_1 opening outside the upper Bollinger band (open1>upper1)
  5. Bullish candle_1 closing inside the upper bollinger band (close1
  6. High_1 is less than upper bollinger band (low1>lower1)
  7. To ensure that trade opens between 8am and 5:30pm us (bool CheckTradingTime() ==true)

Trade closing criteria: The trade closing criteria tells us how a trade should be closed using which criteria. Here in this strategy, the trade closing criteria (exit) used by the EA will be as follows:

Stop Loss: The most important aspect of forex trading is protecting the capital before investing in the market for profit. here we will consider our stoploss position 4pips below the low or above the high of the candle_1.

  • Buy order stop loss: (low1-4*Point()
  • Sell order stop loss: (high1+4*Point())

Take Profit: the primary reason for trading the financial market is not for leisure but for profit that is why trading must be taken seriously. here we will consider our take profit criteria which should always be one deviation from the opening price of candle_1.

  • Buy Order Take profit: (Ask+Deviation);
  • Sell Order Take profit: (Bid-Deviation);

EA source code Begins here:

//+——————————————————————+
//                                          | Simple_BollingerBand_EA.mq4 |
//                                                                               | Danny2108. |
//                                                 | https://zgenmarketinfo.com |
//+——————————————————————+
#property copyright “Daniel Lions Arc.”
#property link “https://zgenmarketinfo.com”
#property version “1.00”
#property strict

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//

//Trade parameters (initial Capital $100)
input Double lot = 0.3;
input int magic = 2023;
input string comment = __FILE__;
input double slippage = 5;

input string StartTradingTime=”08:00″;
input string StopTradingTime=”5:30″;

string CurrentTime;

bool TradingIsAllowed=false;

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//

int OnInit()
{

      return(INIT_SUCCEEDED);

}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//

void OnDeinit(const int reason)
{

}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
void OnTick()
{

     if(!IsNewBar())

return;

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//

// This is where all the parameters of the candle anatomy are being defined.
double open1 = iOpen(Symbol(), Period(), 1);
double close1 = iClose(Symbol(), Period(), 1);
double open2 = iOpen(Symbol(), Period(), 2);
double close2 = iClose(Symbol(), Period(), 2);
double open3 = iOpen(Symbol(), Period(), 3);
double close3 = iClose(Symbol(), Period(), 3);

double high1 = iHigh(Symbol(), Period(), 1);
double low1 = iLow(Symbol(), Period(), 1);
double high2 = iHigh(Symbol(), Period(), 2);
double low2 = iLow(Symbol(), Period(), 2);
double high3 = iHigh(Symbol(), Period(), 3);
double low3 = iLow(Symbol(), Period(), 3);

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//

// This is where all Bollinger bands parameters are being defined
double upper1 = iBands(Symbol(), Period(), 20, 2, 0, PRICE_CLOSE, MODE_UPPER, 1);
double middle1 = iBands(Symbol(), Period(), 20, 2, 0, PRICE_CLOSE, MODE_MAIN, 1);
double lower1 = iBands(Symbol(), Period(), 20, 2, 0, PRICE_CLOSE, MODE_LOWER, 1);

double upper2 = iBands(Symbol(), Period(), 20, 2, 0, PRICE_CLOSE, MODE_UPPER, 2);
double middle2 = iBands(Symbol(), Period(), 20, 2, 0, PRICE_CLOSE, MODE_MAIN, 2);
double lower2 = iBands(Symbol(), Period(), 20, 2, 0, PRICE_CLOSE, MODE_LOWER, 2);

double upper3 = iBands(Symbol(), Period(), 20, 2, 0, PRICE_CLOSE, MODE_UPPER, 3);
double middle3 = iBands(Symbol(), Period(), 20, 2, 0, PRICE_CLOSE, MODE_MAIN, 3);
double lower3 = iBands(Symbol(), Period(), 20, 2, 0, PRICE_CLOSE, MODE_LOWER, 3);

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//

double high2limit = (high2+4*_Point);
double low2limit = (low2-4*_Point);

double BandWidth = (upper1-lower1);
double Deviation = (BandWidth/2);

double SellTP1 = (Bid-Deviation);
double BuyTP1 = (Ask+Deviation);

double BuySL1 = (low1 +4*Point());
double SellSL1 = (high1-4*Point());

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//

//Sell Conditions_1:
if(CheckTradingTime() ==true && close2>open2 && close1upper2 && close1>upper1 && close1lower1) 
{
       OrderSend(_Symbol,OP_SELL,lot,Bid,slippage,SellSL1,SellTP1,comment,magic,0,Red);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//

//Buy Conditions_1:
if(CheckTradingTime() ==true && close2open1 && close2lower1 && high1
      {
            OrderSend(_Symbol,OP_BUY,lot,Ask,slippage,BuySL1,BuyTP1,comment,magic,0,Green);
      }

      return;

}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
bool IsNewBar()
{

//Opening time for the current bar
datetime currentBarTime = iTime(Symbol(), Period(), 0);

//Initialize on first use
static datetime prevBarTime = currentBarTime;
if(prevBarTime
{
prevBarTime = currentBarTime;
return(true);
}

return(false);

}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//

//This is the function that allows the trade to trade in a certain time range

bool CheckTradingTime()
{
if(StringSubstr(CurrentTime,0,5)==StartTradingTime)
TradingIsAllowed=true;

if(StringSubstr(CurrentTime,0,5)==StopTradingTime)
TradingIsAllowed=false;

return (TradingIsAllowed);
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//

If you are looking for the MetaTrader 4 (MT4) Meta Quote Language 4 documentation for the bollinger band indicator you can always check here for the full documentation data of Bollinger Band

Popular Read Also:

10 Profitable Online business ideas for 2023

Global Industries and their Emerging Markets

The post 001 Free EA Source code: Simple_BollingerBand EA appeared first on Global Industries and emerging Market.



This post first appeared on My Personal, please read the originial post: here

Share the post

001 Free EA Source code: Simple_BollingerBand EA

×

Subscribe to My Personal

Get updates delivered right to your inbox!

Thank you for your subscription

×