SMC_BOS_EA/PRINCE
2026-06-17 14:11:58 +00:00

228 lines
No EOL
3.8 KiB
Text

#property strict
#include <Trade/Trade.mqh>
CTrade trade;
double LotSize = 0.01;
int Slippage = 3;
double StopLossPrice = 0;
double TakeProfitPrice = 0;
bool BuyTradeOpen = false;
bool SellTradeOpen = false;
int MagicNumber = 12345;
bool AutoTradingEnabled = true;
int MaxTrades = 1;
int CurrentTrades = 0;
bool UseStopLoss = true;
bool UseTakeProfit = true;
double RiskPercent = 1.0;
bool DemoMode = true;
bool PrintDebugMessages = true;
int OnInit()
{
Print("SMC_BOS_EA Loaded");
return(INIT_SUCCEEDED);
}
void OnTick()
{
if(IsSwingHigh(2))
Print("Swing High Found");
if(IsSwingLow(2))
Print("Swing Low Found");
if(BuyLiquiditySweep(1))
Print("BUY Liquidity Sweep Found");
if(SellLiquiditySweep(1))
Print("SELL Liquidity Sweep Found");
if(BullishBOS(1))
Print("Bullish BOS Found");
if(BearishBOS(1))
Print("Bearish BOS Found");
if(HigherLow(1))
Print("Higher Low Found");
if(LowerHigh(1))
Print("Lower High Found");
if(BullishTrend())
Print("Bullish Trend Confirmed");
if(BearishTrend())
Print("Bearish Trend Confirmed");
}
if(BuySetup() && !BuyTradeOpen && CurrentTrades < MaxTrades)
{
Print("BUY SETUP READY");
OpenBuy();
}
if(SellSetup() && !SellTradeOpen && CurrentTrades < MaxTrades)
{
Print("SELL SETUP READY");
OpenSell();
}
bool IsSwingHigh(int shift)
{
return High[shift] > High[shift+1] &&
High[shift] > High[shift+2] &&
High[shift] > High[shift-1] &&
High[shift] > High[shift-2];
}
bool IsSwingLow(int shift)
{
return Low[shift] < Low[shift+1] &&
Low[shift] < Low[shift+2] &&
Low[shift] < Low[shift-1] &&
Low[shift] < Low[shift-2];
}
bool BuyLiquiditySweep(int shift)
{
return Low[shift] < Low[shift+1] - 5 * _Point &&
Close[shift] > Low[shift+1];
}
bool SellLiquiditySweep(int shift)
{
return High[shift] > High[shift+1] + 5 * _Point &&
Close[shift] < High[shift+1];
}
bool BullishBOS(int shift)
{
return Close[shift] > High[shift+1];
}
bool BearishBOS(int shift)
{
return Close[shift] < Low[shift+1];
}
bool HigherLow(int shift)
{
return Low[shift] > Low[shift+1];
}
bool LowerHigh(int shift)
{
return High[shift] < High[shift+1];
}
bool BullishTrend()
{
return HigherLow(1) && BullishBOS(1);
}
bool BearishTrend()
{
return LowerHigh(1) && BearishBOS(1);
}
bool BuySetup()
{
return BullishTrend() &&
BuyLiquiditySweep(1) &&
BullishBOS(1);
}
bool SellSetup()
{
return BearishTrend() &&
SellLiquiditySweep(1) &&
BearishBOS(1);
}
void OpenBuy()
{
StopLossPrice = Low[1];
TakeProfitPrice = High[10];
Print("BUY ORDER EXECUTED");
if(trade.Buy(LotSize, _Symbol, 0, StopLossPrice, TakeProfitPrice))
Print("BUY ORDER SENT SUCCESSFULLY");
else
Print("BUY ORDER FAILED");
Print("SL: ", StopLossPrice);
Print("TP: ", TakeProfitPrice);
double EntryPrice = Ask;
Print("BUY ENTRY PRICE: ", EntryPrice);
BuyTradeOpen = true;
SellTradeOpen = false;
CurrentTrades++;
Print("CURRENT TRADES: ", CurrentTrades);
}
void OpenSell()
{
StopLossPrice = High[1];
TakeProfitPrice = Low[10];
Print("SELL ORDER EXECUTED");
if(trade.Sell(LotSize, _Symbol, 0, StopLossPrice, TakeProfitPrice))
Print("SELL ORDER SENT SUCCESSFULLY");
else
Print("SELL ORDER FAILED");
Print("SL: ", StopLossPrice);
Print("TP: ", TakeProfitPrice);
double EntryPrice = Bid;
Print("SELL ENTRY PRICE: ", EntryPrice);
SellTradeOpen = true;
BuyTradeOpen = false;
CurrentTrades++;
Print("CURRENT TRADES: ", CurrentTrades);
}
void ResetBuyTrade()
{
BuyTradeOpen = false;
if(CurrentTrades > 0)
CurrentTrades--;
Print("BUY TRADE RESET");
Print("CURRENT TRADES: ", CurrentTrades);
}
void ResetSellTrade()
{
SellTradeOpen = false;
if(CurrentTrades > 0)
CurrentTrades--;
Print("SELL TRADE RESET");
Print("CURRENT TRADES: ", CurrentTrades);
}