支持中心 帮助文档 联系我们
📱 微信: 18391752892 | 💬 QQ: 3313198376 | ✈️ Telegram | 📧 fishfx123@gmail.com
EURUSD 1.0856 +0.12% GBPUSD 1.2678 +0.08% USDJPY 149.23 -0.15% XAUUSD 2034.56 +0.34% EURUSD 1.0856 +0.12% GBPUSD 1.2678 +0.08% USDJPY 149.23 -0.15% XAUUSD 2034.56 +0.34%

UT Alart Bot

👤 作者: Menaka Sachin Thorat

4.8 分

¥0.00

📌 版本: v1.3
📥 下载: 0
⭐ 评分: 4.8

📝 产品详情

UT Alart Bot

作者Menaka Sachin Thorat
版本v1.3
更新2025-01-18T16:19:39
激活数2

To get access to MT4 version please click  https://www.mql5.com/en/market/product/130055 

- This is the exact conversion from TradingView: "Ut Alart Bot Indicator".

- You can message in private chat for further changes you need.

Here is the source code of a simple Expert Advisor operating based on signals from Ut Bot Indicator.

#property copyright "This EA is only education purpose only use it ur own risk"
#property link      "https://sites.google.com/view/automationfx/home"
#property version   "1.00"

#include <Trade\Trade.mqh>
CTrade trade;

int indicator_handle;

input group "EA Setting"
input int magic_number = 123456; // Magic number
input double fixed_lot_size = 0.01; // Fixed lot size
input double AtrCoef = 2; // ATR Coefficient (Sensitivity)
input int AtrLen = 10; // ATR Period


input string IndicatorName = "Market/UT Alart Bot"; // Ind icator name

// Buffers for indicator
double BullBuffer[];
double BearBuffer[];

datetime timer = NULL;

int OnInit() {
   trade.SetExpertMagicNumber(magic_number);

    // Load the custom indicator
    indicator_handle = iCustom(NULL, 0, IndicatorName);
    if (indicator_handle == INVALID_HANDLE) {
        Print("Failed to load indicator. Error: ", GetLastError());
        return(INIT_FAILED);
    }

    // Initialize buffers
    ArraySetAsSeries(BullBuffer, true);
    ArraySetAsSeries(BearBuffer, true);

    return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason) {
    IndicatorRelease(indicator_handle);
}

void OnTick() {
    if (!isNewBar()) return;

    // Get the latest buffer values
    if (CopyBuffer(indicator_handle, 0, 0, 1, BullBuffer) <= 0 ||
        CopyBuffer(indicator_handle, 1, 0, 1, BearBuffer) <= 0) {
        Print("Failed to copy buffer. Error: ", GetLastError());
        return;
    }

    // Buy conditions
    bool buy_condition = true;
    buy_condition &= (BuyCount() == 0);
    buy_condition &= IsUTBuy(1);
    if (buy_condition) {
        CloseSell();
        Buy();
    }

    // Sell conditions
    bool sell_condition = true;
    sell_condition &= (SellCount() == 0);
    sell_condition &= IsUTSell(1);
    if (sell_condition) {
        CloseBuy();
        Sell();
    }
}

bool IsUTBuy(int i) {
    double array[];
    ArraySetAsSeries(array, true);
    CopyBuffer(indicator_handle, 0, i, 1, array);
    double val1 = array[0];
    CopyBuffer(indicator_handle, 1, i, 1, array);
    double val2 = array[0];
    return val1 > val2;
}

bool IsUTSell(int i) {
    double array[];
    ArraySetAsSeries(array, true);
    CopyBuffer(indicator_handle, 0, i, 1, array);
    double val1 = array[0];
    CopyBuffer(indicator_handle, 1, i, 1, array);
    double val2 = array[0];
    return val1 < val2;
}

int BuyCount()
{
   int buy=0;
   for(int i=0;i<PositionsTotal();i++)
   {
      ulong ticket=PositionGetTicket(i);
      if(ticket==0) continue;
      if(PositionGetInteger(POSITION_TYPE) != POSITION_TYPE_BUY) continue;
      if(PositionGetInteger(POSITION_MAGIC) != magic_number) continue;
      buy++;
   }  
   return buy;
}

int SellCount()
{
   int sell=0;
   for(int i=0;i<PositionsTotal();i++)
   {
      ulong ticket=PositionGetTicket(i);
      if(ticket==0) continue;
      if(PositionGetInteger(POSITION_TYPE) != POSITION_TYPE_SELL) continue;
      if(PositionGetInteger(POSITION_MAGIC) != magic_number) continue;
      sell++;
   }  
   return sell;
}


void Buy()
{
   double Ask=SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   if(!trade.Buy(fixed_lot_size, _Symbol, Ask, 0, 0, ""))
   {
      Print("Error executing order: ", GetLastError());
      //ExpertRemove();
   }
}

void Sell()
{
   double Bid=SymbolInfoDouble(_Symbol, SYMBOL_BID);
   if(!trade.Sell(fixed_lot_size, _Symbol, Bid, 0, 0, ""))
   {
      Print("Error executing order: ", GetLastError());
      //ExpertRemove();
   }
}


void CloseBuy()
{
   for(int i=PositionsTotal()-1;i>=0;i--)
   {
      ulong ticket=PositionGetTicket(i);
      if(ticket==0) continue;
      if(PositionGetInteger(POSITION_TYPE) != POSITION_TYPE_BUY) continue;
      if(PositionGetInteger(POSITION_MAGIC) != magic_number) continue;
      if(trade.PositionClose(ticket)==false)
      {
         Print("Error closing position: ", GetLastError());
         //ExpertRemove();
      }
   }  
}

void CloseSell()
{
   for(int i=PositionsTotal()-1;i>=0;i--)
   {
      ulong ticket=PositionGetTicket(i);
      if(ticket==0) continue;
      if(PositionGetInteger(POSITION_TYPE) != POSITION_TYPE_SELL) continue;
      if(PositionGetInteger(POSITION_MAGIC) != magic_number) continue;
      if(trade.PositionClose(ticket)==false)
      {
         Print("Error closing position: ", GetLastError());
      }
   }  
}

bool isNewBar()
{
   datetime candle_start_time= (int)(TimeCurrent()/(PeriodSeconds()))*PeriodSeconds();
   if(timer==NULL) {}
   else if(timer==candle_start_time) return false;
   timer=candle_start_time;
   return true;
}

安全须知

本产品仅通过 MQL5.com 官方渠道获取。其他渠道版本可能缺少完整功能和技术支持。

EA 配置

交易品种XAUUSD
时间框架H1 (推荐)
推荐经纪商IC Markets, IC Trading
最低存款$300 / 0.01手

📸 截图预览