MetaTrader5
รีวิว AK-47 Scalper EA: ระบบเทรดที่ควรมีใน MetaTrader 5
สวัสดีครับเพื่อนนักเทรดทุกท่าน! วันนี้เราจะมาพูดถึง AK-47 Scalper EA กัน ซึ่งเป็น ระบบเทรด ที่ออกแบบมาเพื่อใช้งานกับ MetaTrader 5 โดยเฉพาะ
1. พารามิเตอร์การตั้งค่า
#define ExtBotName "AK-47 EA" // ชื่อบอท
#define Version "1.00" // เวอร์ชัน
// นำเข้าคลาสที่จำเป็น
#include <Trade\PositionInfo.mqh>
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\AccountInfo.mqh>
#include <Trade\OrderInfo.mqh>
//--- ประกาศตัวแปรที่ใช้ในโค้ด
#define Ask SymbolInfoDouble(_Symbol, SYMBOL_ASK)
#define Bid SymbolInfoDouble(_Symbol, SYMBOL_BID)
//--- พารามิเตอร์การตั้งค่า
input string EASettings = "---------------------------------------------"; //-------- <EA Settings> --------
input int InpMagicNumber = 124656; // หมายเลขเวทมนตร์
input string MoneySettings = "---------------------------------------------"; //-------- <Money Settings> --------
input bool isVolume_Percent = true; // อนุญาตให้ใช้เปอร์เซ็นต์ของวอลลุ่ม
input double InpRisk = 3; // เปอร์เซ็นต์ความเสี่ยงของยอดคงเหลือ (%)
input string TradingSettings = "---------------------------------------------"; //-------- <Trading Settings> --------
input double Inpuser_lot = 0.01; // ขนาดล็อต
input double InpSL_Pips = 3.5; // Stoploss (ใน Pips)
input double InpTP_Pips = 7; // TP (ใน Pips) (0 = ไม่มี TP)
input int InpMax_slippage = 3; // ความล่าช้าสูงสุดที่อนุญาต (ใน Pips)
input double InpMax_spread = 5; // สเปรดสูงสุดที่อนุญาต (ใน Points) (0 = ลอยตัว)
input string TimeSettings = "---------------------------------------------"; //-------- <Trading Time Settings> --------
input bool InpTimeFilter = true; // การกรองเวลาในการเทรด
input int InpStartHour = 2; // ชั่วโมงเริ่มต้น
input int InpStartMinute = 30; // นาทีเริ่มต้น
input int InpEndHour = 21; // ชั่วโมงสิ้นสุด
input int InpEndMinute = 0; // นาทีสิ้นสุด
2. การเริ่มต้นตัวแปรในท้องถิ่น
//--- ตัวแปร
int Pips2Points; // slippage 3 pips = 3 points
double Pips2Double; // Stoploss 15 pips = 0.015
bool isOrder = false;
int slippage;
long acSpread;
string strComment = "";
CPositionInfo m_position; // อ็อบเจ็กต์การเทรด
CTrade m_trade; // อ็อบเจ็กต์การเทรด
CSymbolInfo m_symbol; // อ็อบเจ็กต์ข้อมูลสัญลักษณ์
CAccountInfo m_account; // ห่อข้อมูลบัญชี
COrderInfo m_order; // อ็อบเจ็กต์คำสั่งค้างรอ
3. โค้ดหลัก
a/ ฟังก์ชันเริ่มต้นของ EA
int OnInit() {
//ตรวจจับจำนวนหลักการของจุด
if(_Digits % 2 == 1) {
Pips2Double = _Point * 10;
Pips2Points = 10;
slippage = 10 * InpMax_slippage;
} else {
Pips2Double = _Point;
Pips2Points = 1;
slippage = InpMax_slippage;
}
if(!m_symbol.Name(Symbol())) // ตั้งชื่อสัญลักษณ์
return(INIT_FAILED);
RefreshRates();
m_trade.SetExpertMagicNumber(InpMagicNumber);
m_trade.SetMarginMode();
m_trade.SetTypeFillingBySymbol(m_symbol.Name());
m_trade.SetDeviationInPoints(slippage);
return(INIT_SUCCEEDED);
}
b/ ฟังก์ชัน OnTick ของ EA
void OnTick() {
if(TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) == false) {
Comment("LazyBot\nTrade not allowed.");
return;
}
MqlDateTime structTime;
TimeCurrent(structTime);
structTime.sec = 0;
// ตั้งเวลาที่จะเริ่ม
structTime.hour = InpStartHour;
structTime.min = InpStartMinute;
datetime timeStart = StructToTime(structTime);
// ตั้งเวลาที่จะสิ้นสุด
structTime.hour = InpEndHour;
structTime.min = InpEndMinute;
datetime timeEnd = StructToTime(structTime);
acSpread = SymbolInfoInteger(_Symbol, SYMBOL_SPREAD);
strComment = "\n" + ExtBotName + " - v." + (string)Version;
strComment += "\nSever time = " + TimeToString(TimeCurrent(),TIME_DATE|TIME_SECONDS) + " - " + DayOfWeekDescription(structTime.day_of_week);
strComment += "\nTrading time = [" + (string)InpStartHour + "h" + (string)InpStartMinute + " --> " + (string)InpEndHour + "h" + (string)InpEndMinute + "]";
strComment += "\nCurrent Spread = " + (string)acSpread + " Points";
Comment(strComment);
// อัปเดตค่า
UpdateOrders();
TrailingStop();
// เงื่อนไขการเทรดตามช่วงเวลา
if(InpTimeFilter) {
if(TimeCurrent() >= timeStart && TimeCurrent() < timeEnd) {
if(!isOrder) OpenOrder();
}
} else {
if(!isOrder) OpenOrder();
}
}
3.1 คำนวณสัญญาณเพื่อส่งคำสั่ง
void OpenOrder() {
ENUM_ORDER_TYPE OrdType = ORDER_TYPE_SELL; // ประเภทคำสั่ง
double TP = 0;
double SL = 0;
string comment = ExtBotName;
// คำนวณขนาดล็อต
double lot1 = CalculateVolume();
if(OrdType == ORDER_TYPE_SELL) {
double OpenPrice = Bid - NormalizeDouble(InpSL_Pips/2 * Pips2Double, _Digits);
TP = OpenPrice - NormalizeDouble(InpTP_Pips * Pips2Double, _Digits);
SL = Ask + NormalizeDouble(InpSL_Pips/2 * Pips2Double, _Digits);
if(CheckSpreadAllow() && CheckVolumeValue(lot1) && CheckOrderForFREEZE_LEVEL(ORDER_TYPE_SELL_STOP, OpenPrice) && CheckStopLoss(OpenPrice, SL, TP) && CheckMoneyForTrade(m_symbol.Name(), lot1, ORDER_TYPE_SELL)) {
if(!m_trade.SellStop(lot1, OpenPrice, m_symbol.Name(), SL, TP, ORDER_TIME_GTC, 0, comment))
Print(__FUNCTION__, "--> OrderSend error ", m_trade.ResultComment());
}
}
}
สรุป
AK-47 Scalper EA เป็นเครื่องมือที่ช่วยให้การเทรดของคุณมีประสิทธิภาพมากขึ้น โดยเฉพาะกับการตั้งค่าที่สามารถปรับแต่งได้ตามความต้องการของคุณเอง หากคุณเป็นนักเทรดที่ชอบการเทรดในช่วงเวลาสั้น ๆ บอทนี้อาจจะเป็นตัวช่วยที่ดีในการทำกำไรให้กับคุณได้!
2023.06.12