ผมเขียนโค๊ดแบบนี้ใน MT5 พอเอาไปรันมันก็กินแรมไปเรื่อยๆ เลยครับ มันต้องแก้ไขอย่างไรครับ
//+------------------------------------------------------------------+
//| Martingale.mq5 |
//| Copyright 2021, MetaQuotes Ltd. |
//|
https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link "
https://www.mql5.com"
#property version "1.00"
#property strict
#include <Trade\Trade.mqh>
#include <Trade\PositionInfo.mqh>
#include <Indicators\Trend.mqh>
CiMA EMA1, EMA2, EMA3,
ema1, ema2, ema3, ema4;
CTrade Trade;
CPositionInfo m_position;
//-------------------------------------
input ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT;
input string __EMA__ = "=============== Moving Average Settings ==============="; // ====================
input int MA_1 = 3; //Period(fast)
input int MA_2 = 10; //Period(mediam)
input int MA_3 = 20; //Period(slow)
input ENUM_MA_METHOD MA_METHOD1 = MODE_EMA; //MA Method
input ENUM_APPLIED_PRICE MA_PRICE1 = PRICE_CLOSE; //Applied to
input int RangMA = 2; //Distance from MA3-20
input int RangMA2 = 2; //Distance from MA10-20
input string __Line__ = "=============== Line Notify ==============="; // ====================
input string extoken = "" ;
input bool LineNotifyAlert = true;
input bool MobileNotification = false;
input bool AlertonPC = false;
int OpenOrders=0, cnt=0;
int myOrderType=0;
int CountB, CountS;
int CountBar, LastBar;
int digit;
int Stoploss;
double BuyPrice=0, SellPrice=0;
double mylotsi=0;
double bid, ask, point;
string EaName, com, msg;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
EaName = MQLInfoString(MQL_PROGRAM_NAME);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
//----------------------------
//-------------------------------------------------------------------------------------------------------
digit = (int)SymbolInfoInteger(_Symbol,SYMBOL_DIGITS);
CountBar = iBars(_Symbol,TimeFrame);
point = SymbolInfoDouble(_Symbol,SYMBOL_POINT);
bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);
ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
if(LineNotifyAlert || MobileNotification || AlertonPC)
{
EMA1.Refresh();
EMA1.Create(_Symbol,TimeFrame,MA_1,0,MA_METHOD1,MA_PRICE1);
EMA2.Refresh();
EMA2.Create(_Symbol,TimeFrame,MA_2,0,MA_METHOD1,MA_PRICE1);
EMA3.Refresh();
EMA3.Create(_Symbol,TimeFrame,MA_3,0,MODE_SMA,MA_PRICE1);
}
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
Comment(" EMA3-SMA20 : ",DoubleToString(EMA1.Main(1)-EMA3.Main(1),2),
"\n EMA10-SMA20 : ",DoubleToString(EMA2.Main(1)-EMA3.Main(1),2));
//-------------------------------------------------------------------------------------------------------
if(EMA1.Main(1)-EMA3.Main(1)>=RangMA && EMA2.Main(1)-EMA3.Main(1)>=RangMA2 && LastBar!=CountBar)// && EMA1.Main(1)>EMA3.Main(1) && EMA2.Main(1)>EMA3.Main(1) && (bid<=ema1.Main(1) || bid<=ema2.Main(1) || bid<=ema3.Main(1) || bid<=ema4.Main(1))
{
com = "";
msg = "";
com="\n===================";
com=com+"\n Symbol : "+_Symbol+" 😘";
com=com+"\n 🟢 Buy Signal";
com=com+"\n Timeframe : "+StrToPeriod(TimeFrame);
com=com+"\n EMA 3 : "+DoubleToString(EMA1.Main(1),digit);
com=com+"\n EMA 10 : "+DoubleToString(EMA2.Main(1),digit);
com=com+"\n SMA 20 : "+DoubleToString(EMA3.Main(1),digit);
com=com+"\n Price : "+DoubleToString(bid,digit);
com=com+"\n Date/Time : "+TimeToString(TimeCurrent());
com=com+"\n===================";
msg = com;
{
LastBar = CountBar;
if(LineNotifyAlert){LineNotify(extoken,msg);}
msg = "";
msg = string(EaName+" : "+_Symbol+" Buy Signal");
if(MobileNotification){SendNotification(msg);}
if(AlertonPC){Alert(msg);}
}
}
//----------------------------------------------------------
if(EMA1.Main(1)-EMA3.Main(1)<= -RangMA && EMA2.Main(1)-EMA3.Main(1)<= -RangMA2 && LastBar!=CountBar)// && EMA1.Main(1)<EMA3.Main(1) && EMA2.Main(1)<EMA3.Main(1) && (bid>=ema1.Main(1) || bid>=ema2.Main(1) || bid>=ema3.Main(1) || bid>=ema4.Main(1))
{
com = "";
msg = "";
com="\n===================";
com=com+"\n Symbol : "+_Symbol+" 🤩";
com=com+"\n 🔴 Sell Signal";
com=com+"\n Timeframe : "+StrToPeriod(TimeFrame);
com=com+"\n EMA 3 : "+DoubleToString(EMA1.Main(1),digit);
com=com+"\n EMA 10 : "+DoubleToString(EMA2.Main(1),digit);
com=com+"\n SMA 20 : "+DoubleToString(EMA3.Main(1),digit);
com=com+"\n Price : "+DoubleToString(bid,digit);
com=com+"\n Date/Time : "+TimeToString(TimeCurrent());
com=com+"\n===================";
msg = com;
{
LastBar = CountBar;
if(LineNotifyAlert){LineNotify(extoken,msg);}
msg = "";
msg = string(EaName+" : "+_Symbol+" Sell Signal");
if(MobileNotification){SendNotification(msg);}
if(AlertonPC){Alert(msg);}
}
}
//-------------------------------------------------------------------------------------------------------
//------------------------------------End
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//-------------------------------------------------------------
void LineNotify(string token,string Massage){
string headers;
char post[], result2[];
headers="Content-Type: application/x-www-form-urlencoded\r\n"+"Authorization: Bearer "+token+"\r\n";
ArrayResize(post,StringToCharArray("message="+Massage,post,0,WHOLE_ARRAY,CP_UTF8)-1);
int res2 = WebRequest("POST", "
https://notify-api.line.me/api/notify", headers, 10000, post, result2, headers);
}
//----------------------------------
//----------------------------------
//+------------------------------------------------------------------+
//| Convert string to history period |
//+------------------------------------------------------------------+
string StrToPeriod(int period)
{
string strper="";
//--- месяц
if(period==PERIOD_CURRENT){strper = "Current" ;}
if(period==PERIOD_MN1){strper = "MONTH" ;}
if(period==PERIOD_W1){strper = "WEEK" ;}
if(period==PERIOD_D1){strper = "DAY" ;}
if(period==PERIOD_H1){strper = "H1" ;}
if(period==PERIOD_H12){strper = "H12" ;}
if(period==PERIOD_H8){strper = "H8" ;}
if(period==PERIOD_H6){strper = "H6" ;}
if(period==PERIOD_H4){strper = "H4" ;}
if(period==PERIOD_H3){strper = "H3" ;}
if(period==PERIOD_H2){strper = "H2" ;}
if(period==PERIOD_M1){strper = "M1" ;}
if(period==PERIOD_M30){strper = "M30" ;}
if(period==PERIOD_M20){strper = "M20" ;}
if(period==PERIOD_M15){strper = "M15" ;}
if(period==PERIOD_M12){strper = "M12" ;}
if(period==PERIOD_M10){strper = "M10" ;}
if(period==PERIOD_M6){strper = "M6" ;}
if(period==PERIOD_M5){strper = "M5" ;}
if(period==PERIOD_M4){strper = "M4" ;}
if(period==PERIOD_M3){strper = "M3" ;}
if(period==PERIOD_M2){strper = "M2" ;}
//---
return(strper);
}