trader
Taweesak Pintakam
Taweesak Pintakam
//+------------------------------------------------------------------+
//| SMC_Pro_Scalper_V4_Elite.mq5 |
//| Copyright 2026, Gemini Adaptive |
//+------------------------------------------------------------------+
#property version "4.00"
#property strict

#include

//--- INPUT PARAMETERS
input double InpLot = 0.01; // Volume ต่อไม้
input double InpMinNetProfit = 4.0; // กำไรสุทธิขั้นต่ำต่อไม้ ($4.0)
input double InpMaxNetProfit = 7.0; // กำไรสุทธิสูงสุดที่ควรปิด ($7.0)
input int InpTP_Points = 1500; // TP เผื่อไว้ไกลๆ (150 pips)
input int InpSL_Points = 40; // SL หลัก (4 pips) - เฉลี่ยตามกลยุทธ์
input int InpMaxOrders = 100; // สับสูงสุด 100 ไม้
input int InpBatchSize = 10; // หน่วงเวลาทุก 10 ไม้
input int InpDelay_MS = 500; // หน่วง 0.5 วิ
input int InpMagicNum = 8844; // Magic Number (Matching Port 8844)

CTrade trade;

//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
// 1. ตรวจสอบและปิดกำไรรายไม้ (คำนวณหัก Commission/Slippage)
CloseSmartProfits();

// 2. ตรวจสอบ Spread (0.3 pips)
if((int)SymbolInfoInteger(_Symbol, SYMBOL_SPREAD) > 30) return;

// 3. ระบบสับไม้ Grid
ManageHighFreqGrid();
}

//+------------------------------------------------------------------+
//| ฟังก์ชันปิดกำไรสุทธิรายไม้ (Net Profit Calculation) |
//+------------------------------------------------------------------+
void CloseSmartProfits()
{
for(int i = PositionsTotal() - 1; i >= 0; i--)
{
ulong ticket = PositionGetTicket(i);
if(PositionSelectByTicket(ticket))
{
if(PositionGetInteger(POSITION_MAGIC) == InpMagicNum)
{
// คำนวณกำไรสุทธิ: Profit + Commission + Swap
double rawProfit = PositionGetDouble(POSITION_PROFIT);
double commission = PositionGetDouble(POSITION_COMMISSION);
double swap = PositionGetDouble(POSITION_SWAP);
double netProfit = rawProfit + commission + swap;

// ปิดเมื่อกำไรสุทธิอยู่ในช่วง $4 - $7
if(netProfit >= InpMinNetProfit)
{
if(trade.PositionClose(ticket))
{
PrintFormat("Elite Close: Ticket #%d | Net: $%.2f (Raw: $%.2f, Comm: $%.2f)",
ticket, netProfit, rawProfit, commission);
}
}
}
}
}
}

//+------------------------------------------------------------------+
//| ระบบวาง Grid สำหรับ High Frequency Scalping |
//+------------------------------------------------------------------+
void ManageHighFreqGrid()
{
int total = CountAllOrders();

if(total < InpMaxOrders)
{
double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
int toOpen = InpMaxOrders - total;

// จำกัดการยิงไม้ใหม่ไม่เกินครั้งละ 10 เพื่อคุม Latency
int currentBatch = (toOpen > 10) ? 10 : toOpen;

for(int i = 1; i <= currentBatch; i++)
{
// หน่วงเวลาทุกๆ Batch
if(i > 1 && i % InpBatchSize == 1) Sleep(InpDelay_MS);

// ระยะห่าง Grid (Step 2 pips)
double price = ask - (i * 20 * _Point);
double sl = price - InpSL_Points * _Point;
double tp = price + InpTP_Points * _Point;

trade.BuyLimit(InpLot, price, _Symbol, sl, tp, ORDER_TIME_GTC, 0, "Elite_SMC");
}
}
}

int CountAllOrders()
{
int c = 0;
for(int i=PositionsTotal()-1; i>=0; i--)
if(PositionSelectByTicket(PositionGetTicket(i)) && PositionGetInteger(POSITION_MAGIC) == InpMagicNum) c++;
for(int i=OrdersTotal()-1; i>=0; i--)
if(OrderSelect(OrderGetTicket(i)) && OrderGetInteger(ORDER_MAGIC) == InpMagicNum) c++;
return c;
}
Taweesak Pintakam
Taweesak Pintakam
//+------------------------------------------------------------------+
//| Simple_MA_Cross.mq5 |
//| Copyright 2026, Gemini AI User |
//+------------------------------------------------------------------+
#property strict
#include

// Input parameters
input int FastMAPeriod = 10; // Fast Moving Average Period
input int SlowMAPeriod = 20; // Slow Moving Average Period
input double LotSize = 0.1; // Trading Lot Size
input int StopLoss = 100; // Stop Loss in Points
input int TakeProfit = 200; // Take Profit in Points

// Global variables
CTrade trade; // Trading class
int fastMAHandle; // Handle for fast MA
int slowMAHandle; // Handle for slow MA

//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// Initialize Moving Average indicators
fastMAHandle = iMA(_Symbol, _Period, FastMAPeriod, 0, MODE_SMA, PRICE_CLOSE);
slowMAHandle = iMA(_Symbol, _Period, SlowMAPeriod, 0, MODE_SMA, PRICE_CLOSE);

if(fastMAHandle == INVALID_HANDLE || slowMAHandle == INVALID_HANDLE)
{
Print("Error creating indicator handles");
return(INIT_FAILED);
}
return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double fastMA[], slowMA[];

// Copy indicator values to arrays
ArraySetAsSeries(fastMA, true);
ArraySetAsSeries(slowMA, true);

if(CopyBuffer(fastMAHandle, 0, 0, 3, fastMA) < 3 ||
CopyBuffer(slowMAHandle, 0, 0, 3, slowMA) < 3) return;

// Check if we already have a position open
bool hasPosition = PositionSelect(_Symbol);

// Buy Logic: Fast MA crosses ABOVE Slow MA
if(!hasPosition && fastMA[0] > slowMA[0] && fastMA[1] <= slowMA[1])
{
double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
double sl = ask - StopLoss * _Point;
double tp = ask + TakeProfit * _Point;
trade.Buy(LotSize, _Symbol, ask, sl, tp, "MA Cross Buy");
}

// Sell Logic: Fast MA crosses BELOW Slow MA
if(!hasPosition && fastMA[0] < slowMA[0] && fastMA[1] >= slowMA[1])
{
double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
double sl = bid + StopLoss * _Point;
double tp = bid - TakeProfit * _Point;
trade.Sell(LotSize, _Symbol, bid, sl, tp, "MA Cross Sell");
}
}
Taweesak Pintakam
Registrato sulla MQL5.community