MA-EA-Mark11

Author: Copyright(c) 2010 Masaru Sasaki
Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each barSeries array that contains close prices for each bar
Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It automatically opens orders when conditions are reached
Indicators Used
Momentum indicator
Miscellaneous
It issuies visual alerts to the screenIt sends emails
0 Views
0 Downloads
0 Favorites

Profitability Reports

GBP/USD Oct 2024 - Jan 2025
67.00 %
Total Trades 7
Won Trades 1
Lost trades 6
Win Rate 0.14 %
Expected payoff -1.43
Gross Profit 20.00
Gross Loss -30.00
Total Net Profit -10.00
-100%
-50%
0%
50%
100%
MA-EA-Mark11
//+------------------------------------------------------------------+
//|                                                 MA-EA-Mark11.mq4 |
//|                                  Copyright(c) 2010 Masaru Sasaki |
//|                                                                  |
//+------------------------------------------------------------------+
//
// < MetaTrader4 FX(ŠO‘ˆ×‘֏؋’‹àŽæˆø)Ž©“®”„”ƒƒVƒXƒeƒ€EA >
// uƒ\[ƒXƒR[ƒhŒöŠJ——Rv
//  *ˆê”Ê“I‚ȌlƒgƒŒ[ƒ_[‚̈êl‚Æ‚µ‚āAƒvƒƒOƒ‰ƒ€‚É•sе‚ê‚È•û‚Ö‚Ì
//   ŽQl‚Æ‚µ‚ÄŒöŠJ‚·‚鎖‚É‚µ‚Ü‚µ‚½B
//   Ž©•ª‚͍K‚¢‚É‚àƒvƒƒOƒ‰ƒ~ƒ“ƒO‚ðŽï–¡‚Æ‚µ‚Ä—ˆ‚½ƒTƒ“ƒf[ƒvƒƒOƒ‰ƒ}[
//   ‚Å‚ ‚鎖‚©‚çAƒVƒXƒeƒ€ƒvƒƒOƒ‰ƒ~ƒ“ƒO(EA)‚ª‚Å‚«‚Ü‚µ‚½B
//   ƒvƒƒOƒ‰ƒ~ƒ“ƒO‚͏K‚¤‚æ‚èAе‚ê‚낾‚ÆŽv‚¢‚Ü‚·B
//
// u‹ÖŽ~Ž–€v
//  *‚±‚̃vƒƒOƒ‰ƒ€ƒ\[ƒXƒR[ƒh‚ð‚»‚Ì‚Ü‚Ü—¬—p‚µ‚½ƒ\ƒtƒg‚̔̔„“™‚ð
//   ˆêØ‹ÖŽ~’v‚µ‚Ü‚·B
// 
// u–Ɛӎ–€v
//  *‚±‚̃vƒƒOƒ‰ƒ€‚ÉŠî‚­sˆ×‚ÌŒ‹‰Ê”­¶‚µ‚½áŠQA‘¹Ž¸‚Ȃǂɂ‚¢‚Ä
//    ’˜ìŽÒ‚ÍˆêØ‚̐ӔC‚𕉂¢‚Ü‚¹‚ñB
//
// uà–¾v
//  *ƒ‚ƒƒ“ƒ^ƒ€Žw•W‚ÆPivotŽw•W‚ð‘g‡‚킹‚½
//   ƒVƒXƒeƒ€‚Å‚·B
//
// ŽQl‘ÐFFXƒƒ^ƒgƒŒ[ƒ_[“ü–å (PanRolling)
//           FXƒƒ^ƒgƒŒ[ƒ_[ŽÀ‘HƒvƒƒOƒ‰ƒ~ƒ“ƒO (PanRolling)
//           ”„”ƒƒVƒXƒeƒ€“ü–å (PanRolling)
//           Ÿ—˜‚Ì”„”ƒƒVƒXƒeƒ€ with TradeStation (PanRolling)
//           ‚¿‚á‚ñ‚Ɩׂ¯‚½‚¢l‚ÌŠ”‰¿ƒ`ƒƒ[ƒg•ªÍ‘å‘S  (Ž©—R‘–¯ŽÐ)
//           ‚±‚±‚܂Ŏg‚¦‚郍[ƒ\ƒN‘«ƒ`ƒƒ[ƒg (“ú–{ŒoÏV•·ŽÐ)
//
#property copyright "Copyright(c) 2010 Masaru Sasaki"
#property link      "youtarou.blogzine.jp"
#include <stderror.mqh>

// ƒ}ƒWƒbƒNƒiƒ“ƒo[
#define MAGIC 20100913

// ƒXƒgƒbƒvƒƒXƒ^ƒCƒv
#define STOPLOSPIPS 1
#define STOPLOSRATE 2

// ƒXƒgƒbƒvƒƒX‚ðpips•‚É‚·‚é‚©‰¿Ši‚ɑ΂·‚éƒp[ƒZƒ“ƒe[ƒW‚·‚é‚©‚ð‘I‘ð
extern int STOPLosType = STOPLOSPIPS;    // 0=pips•  1=ƒŒ[ƒg•                       
extern int STOPpips = 50;     // ƒXƒgƒbƒvƒƒXpips•
extern double STOPrate = 0.01; // ƒXƒgƒbƒvƒƒXƒŒ[ƒg• 0.01=1“

// —˜H‚¢’l (Pips)
extern int TAKEProfit = 200;

// —˜H‚¢’l‚̃Iƒ“ƒIƒtÝ’è •W€ƒIƒ“
extern bool TAKEProfitFlag = true;

// ƒgƒŒ[ƒhŽžŠÔ‘ѐݒè
extern string STime = "22:00";  // ŠJŽnŽž
extern string ETime = "5:00";   // I—¹Žž
extern bool TradeTime = false;   // ƒgƒŒ[ƒhŽžŠÔ‘т̃Iƒ“ƒIƒt •W€‚̓Iƒt

// ƒŒƒoƒŒƒbƒW‚Ì‘I‘ð
extern double Leverage = 1.0; // 1.0 -> 1”{

// ƒ[ƒ‹ƒAƒ‰[ƒg’Ê’m‚Ì on/off
extern bool mail_flag = false;  // •W€Ý’è‚̓Iƒt

// Å¬ƒƒbƒg” ØŒ”‰ïŽÐ‚É‚æ‚èˆÙ‚È‚éB
extern double minlot  = 0.01;   // 1000’Ê‰Ý FOREX.COM Japan

// ƒ‚ƒƒ“ƒ^ƒ€ŠúŠÔ
extern int Mom_period = 20;

// ƒXƒŠƒbƒvƒx[ƒW
extern int Slippage = 3;      


// ƒfƒoƒbƒO on/off ƒtƒ‰ƒO
bool debug = false;

// ƒ|ƒWƒVƒ‡ƒ“ŒˆÏŠÖ” start‚ɂČďo‚µ‚ÄŽg—p
void ClosePositions()
{
   for( int i=0; i < OrdersTotal(); i++ ){
      if( OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false )
         break;
      if( OrderMagicNumber() != MAGIC || OrderSymbol() != Symbol() )
         continue;
      // ƒI[ƒ_[ƒ^ƒCƒv‚̃`ƒFƒbƒN
      if( OrderType() == OP_BUY )   // ”ƒ‚¢
      {
         OrderClose( OrderTicket(), OrderLots(), Bid, Slippage, White);
         break;
      }
      if( OrderType() == OP_SELL )  // ”„‚è
      {
         OrderClose( OrderTicket(), OrderLots(), Ask, Slippage, White);
         break;
      }
   }

}

// ƒI[ƒ_[—L–³‚Ì”»’èŠÖ” start‚ɂČďo‚µ‚ÄŽg—p
int OrderPosition()
{
   int r_type = 0;
   
   for( int i=0; i < OrdersTotal(); i++ ){
      if( OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false )
         break;
      if( OrderMagicNumber() != MAGIC || OrderSymbol() != Symbol() )
         continue;
      // ƒI[ƒ_[ƒ^ƒCƒv‚̃`ƒFƒbƒN
      if( OrderType() == OP_BUY || OrderType() == OP_SELL )
      {
         r_type = OrderType();
         break;
      }
   }
   return(r_type);
}

// ƒgƒŒ[ƒhŽžŠÔ‘уtƒBƒ‹ƒ^[ŠÖ”  start‚ɂČďo‚µ‚ÄŽg—p
bool SignalFilter()
{
   string Sdata = TimeToStr(TimeCurrent(), TIME_DATE);
   datetime s_time = StrToTime(Sdata + " " + STime);
   datetime e_time = StrToTime(Sdata + " " + ETime);
   
   bool r = false;
   if( s_time < e_time )
   {
      if( TimeCurrent() >= s_time && TimeCurrent() < e_time ) r = true;
      else r = false;
   }
   else
   {
      if( TimeCurrent() >= e_time && TimeCurrent() < s_time ) r = false;
      else r = true;
   }
   // ƒgƒŒ[ƒhŽžŠÔ‘уIƒt‚̏ꍇAí‚ɐ^
   if( TradeTime == false ) r = true;
   
   return(r);
}
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {

   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {

   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   // ƒo[‚ÌŽn’l‚ŃgƒŒ[ƒh‰Â”\‚©ƒ`ƒFƒbƒN
   if( Volume[0] > 1 || IsTradeAllowed() == false )
      return(0);
   
   // Pivot‚ÌŒvŽZ‚ƃuƒŒƒCƒNƒAƒEƒg”»’è (ŽžŠÔ˜g‚Í“ú‘«‚ðŽg—p)
   int s = iBarShift(NULL, PERIOD_D1, Time[1]) + 1;
   double LH = iHigh(NULL, PERIOD_D1, s);
   double LL = iLow(NULL, PERIOD_D1, s);
   double LC = iClose(NULL, PERIOD_D1, s);
   double P = (LH + LL + LC)/3;
   double R1 = P + (P - LL);
   double S1 = P - (LH - P);
   double R2 = P + (LH - LL);
   double S2 = P - (LH - LL);
   double HBOP = LH + 2*(P - LL);
   double LBOP = LL - 2*(LH - P); 
   if( Close[2] <= HBOP && Close[1] > HBOP ) bool Pivot_Up = true;
   if( Close[2] >= LBOP && Close[1] < LBOP ) bool Pivot_Down = true;
   
   // ƒ‚ƒƒ“ƒ^ƒ€‚ÌŒvŽZ
   double Mom1 = iMomentum(NULL, 0, Mom_period, PRICE_CLOSE, 1);   
     
   // ƒXƒgƒbƒvƒƒXŒvŽZ—p
   double StopType = 0.0;
   
   // —˜H‚¢’lŒvŽZ—p
   double TakeProfit = 0.0;
   
   // ƒƒbƒg”‚ÌŒvŽZ
   double Lots = NormalizeDouble(AccountFreeMargin()*Leverage/100000,1);
   if( Lots < minlot ) Lots = minlot;
   
   // ƒI[ƒ_[ƒ^ƒCƒ€ƒAƒEƒgŽžŠÔ 12•bŠÔ
   int OrderWaitTime = 12;
   int startTime;
   
   // ”ƒ‚¢ƒVƒOƒiƒ‹
   // ðŒFƒ‚ƒƒ“ƒ^ƒ€’l‚ª100‚æ‚èã‚©‚ÂPivotŽw•W‚ŏ㔲‚¯
   //
   if( SignalFilter() == true )
   if( Mom1 > 100 )
   if( Pivot_Up == true )
   {
      if( OrderPosition() == OP_BUY  )  // ”ƒ‚¢ƒI[ƒ_[‚ª‚·‚łɗL‚éê‡‚̓Lƒƒƒ“ƒZƒ‹‚·‚éBƒiƒ“ƒsƒ“‚µ‚È‚¢B
         return(0);
      ClosePositions();
      if( STOPLosType == STOPLOSPIPS ) StopType = Ask-STOPpips*Point;
      else
         StopType = Ask*(1-STOPrate);
      if( TAKEProfitFlag == true ) TakeProfit = Ask+TAKEProfit*Point;
      else
         TakeProfit = 0;
      
      // ’ʐMƒGƒ‰[‚ª‚ ‚Á‚½ê‡AƒI[ƒ_[‚ðŒJ‚è•Ô‚·B
      startTime = GetTickCount();
      while( true )
      {
         if( GetTickCount() - startTime > OrderWaitTime*1000)
         {
            Alert("OrderSend Time Out ERROR!! Check Experts Log!!");
            // ƒ[ƒ‹‘—M‰Â‚Å‚ ‚ê‚΁AƒGƒ‰[‚𑗐MB
            if( mail_flag == true )
               SendMail("MetaTrader 4 MAIL ƒAƒ‰[ƒg:", "OrderSend ”ƒ‚¢ƒ^ƒCƒ€ƒAƒEƒgƒGƒ‰[!!"+Symbol());
            return(false);
         }
         if( IsTradeAllowed() == true )
         {
            RefreshRates();
            if(OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopType, TakeProfit, "", MAGIC, 0, Red) != -1)
               return(true);
            int buyerror = GetLastError();
            Print("OrderSend Error : ", buyerror);
         }
         Sleep(100);
      }
      // ƒ[ƒ‹ƒAƒ‰[ƒg’Ê’m
      if( mail_flag == true )
         SendMail("MetaTrader4 MAIL ƒAƒ‰[ƒg:", "”ƒ‚¢" + Symbol() + "at" + DoubleToStr(Ask, Digits));
      return(0);
   }
   
   // ”„‚èƒVƒOƒiƒ‹
   // ðŒFƒ‚ƒƒ“ƒ^ƒ€’l‚ª100‚æ‚艺‚©‚ÂPivotŽw•W‚ʼnº”²‚¯
   //
   if( SignalFilter() == true )
   if( Mom1 < 100 )
   if( Pivot_Down == true )
   {
      if( OrderPosition() == OP_SELL  )  // ”„‚èƒI[ƒ_[‚ª‚·‚łɗL‚éê‡‚̓Lƒƒƒ“ƒZƒ‹‚·‚éBƒiƒ“ƒsƒ“‚µ‚È‚¢B
         return(0);
      ClosePositions();
      if( STOPLosType == STOPLOSPIPS ) StopType = Bid+STOPpips*Point;
      else
         StopType = Bid*(1+STOPrate);
      if( TAKEProfitFlag == true ) TakeProfit = Bid-TAKEProfit*Point;
      else
         TakeProfit = 0;
      // ’ʐMƒGƒ‰[‚ª‚ ‚Á‚½ê‡AƒI[ƒ_[‚ðŒJ‚è•Ô‚·B
      startTime = GetTickCount();
      while( true )
      {
         if( GetTickCount() - startTime > OrderWaitTime*1000)
         {
            Alert("OrderSend Time Out ERROR!! Check Experts Log!!");
            // ƒ[ƒ‹‘—M‰Â‚Å‚ ‚ê‚΁AƒGƒ‰[‚𑗐MB
            if( mail_flag == true )
               SendMail("MetaTrader 4 MAIL ƒAƒ‰[ƒg:", "OrderSend ”„‚èƒ^ƒCƒ€ƒAƒEƒgƒGƒ‰[!!"+Symbol());
            return(false);
         }
         if( IsTradeAllowed() == true )
         {
            RefreshRates();
            if(OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopType, TakeProfit, "", MAGIC, 0, Blue) != -1)
               return(true);
            int sellerror = GetLastError();
            Print("OrderSend Error : ", sellerror);   
         }
         Sleep(100);
      }
      // ƒ[ƒ‹ƒAƒ‰[ƒg’Ê’m
      if( mail_flag == true )
         SendMail("MetaTrader4 MAIL ƒAƒ‰[ƒg:", "”„‚è" + Symbol() + "at" + DoubleToStr(Bid, Digits));
      return(0);
   }
   
   // Ý’莞ŠÔ‘тŃ|ƒWƒVƒ‡ƒ“‚ª—L‚éê‡‚ÌŽèŽd•‘‚¢ˆ—
   if( OrderPosition() == OP_BUY )
   {
      if( SignalFilter() == false ) ClosePositions();
   }
   else
   if( OrderPosition() == OP_SELL )
   {
      if( SignalFilter() == false ) ClosePositions();
   }
   
   // ƒfƒoƒbƒO•\ަ
   if( debug == true )
   {
      Print("I’l :", Close[1]);
      Print("ƒ‚ƒƒ“ƒ^ƒ€ :", Mom1);
      Print("ƒoƒ“ƒh‰º”²‚¯:", Pivot_Down);
      Print("ƒoƒ“ƒhã”²‚¯:", Pivot_Up);
   }
   
   return(0);
  }
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---