Fix code

MQL5 专家

指定

//+------------------------------------------------------------------+
//|                                                      MA Bot.mq5  |
//|  Simple Martingale MA-based Trading Bot for Gold (XAUUSD)       |
//+------------------------------------------------------------------+
#include <Trade/Trade.mqh>
CTrade trade;

input int               maPeriod       = 13;
input ENUM_MA_METHOD    maMethod       = MODE_EMA;
input double            tradeGapUSD    = 2.0;
input double            tpInCents      = 20;     // 20 cents
input double            slInCents      = 200;    // 200 cents
input ENUM_TIMEFRAMES   timeframe      = PERIOD_M5;
input double            lot1 = 0.07;
input double            lot2 = 0.10;
input double            lot3 = 0.15;
input double            lot4 = 0.35;

double lotSizes[];

int maHandle;
double lastBuyPrice = 0;
double lastSellPrice = 0;
int buyCount = 0;
int sellCount = 0;

//+------------------------------------------------------------------+
//| Expert initialization                                            |
//+------------------------------------------------------------------+
int OnInit()
{
   maHandle = iMA(_Symbol, timeframe, maPeriod, 0, maMethod, PRICE_CLOSE);
   if(maHandle == INVALID_HANDLE)
   {
      Print("Failed to create MA handle");
      return(INIT_FAILED);
   }
   ArrayResize(lotSizes, 4);
   lotSizes[0] = lot1;
   lotSizes[1] = lot2;
   lotSizes[2] = lot3;
   lotSizes[3] = lot4;
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
   double maBuffer[1];
   if(CopyBuffer(maHandle, 0, 0, 1, maBuffer) <= 0) return;
   double maValue = maBuffer[0];

   double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
   double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);

   // Buy logic
   if (bid > maValue && buyCount < ArraySize(lotSizes))
   {
      if (buyCount == 0 || MathAbs(bid - lastBuyPrice) >= tradeGapUSD)
      {
         if (trade.Buy(lotSizes[buyCount], _Symbol, ask, 0, 0))
         {
            lastBuyPrice = bid;
            buyCount++;
         }
      }
   }

   // Sell logic
   if (ask < maValue && sellCount < ArraySize(lotSizes))
   {
      if (sellCount == 0 || MathAbs(ask - lastSellPrice) >= tradeGapUSD)
      {
         if (trade.Sell(lotSizes[sellCount], _Symbol, bid, 0, 0))
         {
            lastSellPrice = ask;
            sellCount++;
         }
      }
   }

   ManageRisk();
}

//+------------------------------------------------------------------+
//| Risk Management                                                  |
//+------------------------------------------------------------------+
void ManageRisk()
{
   double totalProfitCents = 0.0;
   for (int i = PositionsTotal() - 1; i >= 0; i--)
   {
      if (PositionGetTicket(i) != 0 && PositionGetString(POSITION_SYMBOL) == _Symbol)
      {
         double profitInCents = PositionGetDouble(POSITION_PROFIT) * 100.0;
         totalProfitCents += profitInCents;
      }
   }

   if (totalProfitCents >= tpInCents)
   {
      CloseAll();
      Print("TP Hit: ", totalProfitCents, " cents");
   }
   else if (totalProfitCents <= -slInCents)
   {
      CloseAll();
      Print("SL Hit: ", totalProfitCents, " cents");
   }
}

//+------------------------------------------------------------------+
//| Close all open positions                                         |
//+------------------------------------------------------------------+
void CloseAll()
{
   for (int i = PositionsTotal() - 1; i >= 0; i--)
   {
      if (PositionGetTicket(i) != 0 && PositionGetString(POSITION_SYMBOL) == _Symbol)
      {
         ulong ticket = PositionGetInteger(POSITION_TICKET);
         trade.PositionClose(ticket);
      }
   }
   buyCount = 0;
   sellCount = 0;
   lastBuyPrice = 0;
   lastSellPrice = 0;
}

反馈

1
开发者 1
等级
(234)
项目
335
24%
仲裁
19
63% / 21%
逾期
1
0%
已载入
2
开发者 2
等级
项目
0
0%
仲裁
0
逾期
0
空闲
3
开发者 3
等级
(221)
项目
227
29%
仲裁
0
逾期
3
1%
空闲
发布者: 2 代码
4
开发者 4
等级
(1)
项目
0
0%
仲裁
0
逾期
0
空闲
5
开发者 5
等级
(15)
项目
19
37%
仲裁
2
0% / 100%
逾期
0
空闲
发布者: 1 代码
6
开发者 6
等级
(1)
项目
1
0%
仲裁
0
逾期
0
空闲
7
开发者 7
等级
(1)
项目
1
0%
仲裁
1
0% / 0%
逾期
0
工作中
8
开发者 8
等级
项目
0
0%
仲裁
0
逾期
0
工作中
9
开发者 9
等级
(530)
项目
607
34%
仲裁
33
39% / 45%
逾期
9
1%
已载入
10
开发者 10
等级
(46)
项目
57
23%
仲裁
8
38% / 38%
逾期
5
9%
空闲
11
开发者 11
等级
项目
0
0%
仲裁
0
逾期
0
空闲
12
开发者 12
等级
项目
0
0%
仲裁
0
逾期
0
空闲
相似订单
Need an expert coder to convert my tradingview pine script to mt5 indicator for me, the indicator is very simple I need you to go through it very well before sending message, make very sure you can do it
Everyday market open: 1. Every minute from market open calculate the upper and lower bands based on the formula in the paper. Average move for every minute for each of the last 14 days-check the paper. You can create these bands as an indicator as well so I can apply it to charts. 2. Also calculate the recursive vwap for every minute of the trading day. And create this indicator as well. 3. Every
I have almost created my EA with help of AI 's need some fixed in certain areas where the strategy is little bit complex where slight human interference is needed to make it a perfect EA
Please, I need a programmer to create me an expert advisor that can yield more profits and few losses. You should be able to explain to understanding how it works and how to go about it. Thanks
A robot 30+ USD
hy i have a robot already i want someone who can fix only my entries and takeprofit .my entry are order blocks ...you only fix my entries ..i have pictures to give u
fully automated mt5 bot with trailing stop loss one that can grow a small account take trade base on the market trend i would love to work with someone who is understand
Need An EA for Prop Firm challenges, for my live Account Must have Draw Down % : 1-2 % Lot Size : Depending on the Challenge Account . Risk : An Assessment Panel on the Chart covering all the Essentials showing the requirements to pass the challenge . S.L : Accordingly . T.p : Accordingly . t should NOT use martingale. NO high frequency. It should NOT trade during high-impact news (News filter is necessary)
I would like a panel to put in the expert advisor. The panel is movable, has buttons to control the window (minimize or lock), results and position statistics. And I would like a cool design! I would like it to work well so I can add the code to my EA Surprise me
### NO SHIT TALKERS AND TIME WASTERS PLEASE ### I am an investor and seriously looking for the best MT5 EA on Live Account results to buy from you. I do not want any development work. I want a ready and good EA product. Requirements: - Live Account Report - No need Demo Reports ! - Super low Drawdown - Stable Equity curve - Give me free Demo Version to Backtest myself
The EA must support trading with Cash Indices, Stocks, and Forex. The EA's strategy is simple: It creates a custom time frame called S60 (the range is in seconds, set via input) and works exclusively with S60 candles; It uses the corresponding second candle to determine two boundaries — the High Price as the upper boundary and the Low Price as the lower boundary (these boundaries are updated with every new “second

项目信息

预算
30 USD

客户

所下订单2
仲裁计数0