139 lines
4.8 KiB
Text
139 lines
4.8 KiB
Text
//+------------------------------------------------------------------+
| |||
//| AxiumMicroScalper.mq5|
| |||
//| Copyright 2026, Quant Dev Team |
| |||
//+------------------------------------------------------------------+
| |||
#property copyright "Copyright 2026"
| |||
#property link ""
| |||
#property version "1.00"
| |||
#property strict
| |||
| |||
// Include Trade Library
| |||
#include <Trade\Trade.mqh>
| |||
#include <Trade\PositionInfo.mqh>
| |||
| |||
//--- Input Parameters
| |||
input group "=== Strategy Settings ==="
| |||
input double InpLotSize = 0.01; // Base Lot Size
| |||
input double InpBasketTargetUSD = 1.50; // Basket Profit Target ($ per cycle)
| |||
input int InpGridDistance = 15; // Minimum Distance Between Grid Trades (Points)
| |||
input int InpMaxPositions = 15; // Maximum Concurrent Open Positions
| |||
input ulong InpMagicNumber = 888123; // EA Magic Number
| |||
input ulong InpSlippage = 10; // Max Slippage Points
| |||
| |||
//--- Global Objects
| |||
CTrade m_trade;
| |||
CPositionInfo m_position;
| |||
| |||
//+------------------------------------------------------------------+
| |||
//| Expert initialization function |
| |||
//+------------------------------------------------------------------+
| |||
int OnInit()
| |||
{
| |||
m_trade.SetExpertMagicNumber(InpMagicNumber);
| |||
m_trade.SetDeviationInPoints(InpSlippage);
| |||
m_trade.SetMarginMode();
| |||
m_trade.SetTypeFillingBySymbol(_Symbol);
| |||
| |||
return(INIT_SUCCEEDED);
| |||
}
| |||
| |||
//+------------------------------------------------------------------+
| |||
//| Expert deinitialization function |
| |||
//+------------------------------------------------------------------+
| |||
void OnDeinit(const int reason)
| |||
{
| |||
}
| |||
| |||
//+------------------------------------------------------------------+
| |||
//| Expert tick function |
| |||
//+------------------------------------------------------------------+
| |||
void OnTick()
| |||
{
| |||
// 1. Calculate Floating Basket Profit & Count Open Positions
| |||
double currentBasketProfit = 0.0;
| |||
int buyCount = 0;
| |||
int sellCount = 0;
| |||
| |||
double lastBuyPrice = 0.0;
| |||
double lastSellPrice = 0.0;
| |||
| |||
int totalPositions = 0;
| |||
| |||
for(int i = PositionsTotal() - 1; i >= 0; i--)
| |||
{
| |||
if(m_position.SelectByIndex(i))
| |||
{
| |||
if(m_position.Symbol() == _Symbol && m_position.Magic() == InpMagicNumber)
| |||
{
| |||
totalPositions++;
| |||
currentBasketProfit += m_position.Profit() + m_position.Swap() + m_position.Commission();
| |||
| |||
if(m_position.PositionType() == POSITION_TYPE_BUY)
| |||
{
| |||
buyCount++;
| |||
if(lastBuyPrice == 0.0 || m_position.PriceOpen() < lastBuyPrice)
| |||
lastBuyPrice = m_position.PriceOpen();
| |||
}
| |||
else if(m_position.PositionType() == POSITION_TYPE_SELL)
| |||
{
| |||
sellCount++;
| |||
if(lastSellPrice == 0.0 || m_position.PriceOpen() > lastSellPrice)
| |||
lastSellPrice = m_position.PriceOpen();
| |||
}
| |||
}
| |||
}
| |||
}
| |||
| |||
// 2. Execution Logic: Basket Profit Target Reached -> Close All Positions Immediately
| |||
if(totalPositions > 0 && currentBasketProfit >= InpBasketTargetUSD)
| |||
{
| |||
CloseAllPositions();
| |||
return;
| |||
}
| |||
| |||
// 3. Grid Entry Execution
| |||
if(totalPositions >= InpMaxPositions)
| |||
return;
| |||
| |||
double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
| |||
double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
| |||
double point = SymbolInfoDouble(_Symbol, SYMBOL_POINT);
| |||
| |||
// Initial cycle entry (opens buy/sell momentum starter if no positions exist)
| |||
if(totalPositions == 0)
| |||
{
| |||
m_trade.Buy(InpLotSize, _Symbol, ask, 0, 0, "Axium Start Buy");
| |||
m_trade.Sell(InpLotSize, _Symbol, bid, 0, 0, "Axium Start Sell");
| |||
return;
| |||
}
| |||
| |||
// Stack BUY positions if price dips by Grid Distance
| |||
if(buyCount > 0 && (lastBuyPrice - ask) >= (InpGridDistance * point))
| |||
{
| |||
m_trade.Buy(InpLotSize, _Symbol, ask, 0, 0, "Axium Grid Buy");
| |||
}
| |||
| |||
// Stack SELL positions if price rallies by Grid Distance
| |||
if(sellCount > 0 && (bid - lastSellPrice) >= (InpGridDistance * point))
| |||
{
| |||
m_trade.Sell(InpLotSize, _Symbol, bid, 0, 0, "Axium Grid Sell");
| |||
}
| |||
}
| |||
| |||
//+------------------------------------------------------------------+
| |||
//| Fast Basket Closure Routine |
| |||
//+------------------------------------------------------------------+
| |||
void CloseAllPositions()
| |||
{
| |||
for(int i = PositionsTotal() - 1; i >= 0; i--)
| |||
{
| |||
if(m_position.SelectByIndex(i))
| |||
{
| |||
if(m_position.Symbol() == _Symbol && m_position.Magic() == InpMagicNumber)
| |||
{
| |||
m_trade.PositionClose(m_position.Ticket());
| |||
}
| |||
}
| |||
}
| |||
}
| |||
//+------------------------------------------------------------------+
|