Nayan4602

MQL5 专家

指定

"""
Market entry on EUR/USD with 0.01 lot, using the account that is ALREADY
logged in inside the running MetaTrader 5 terminal.
"""

import MetaTrader5 as mt5

# ---------------- Config ----------------
SYMBOL = "EURUSD"
LOT = 0.01
SIDE = "BUY"           # "BUY" or "SELL"
DEVIATION = 20         # max slippage in points
MAGIC = 234000
SL_POINTS = 0          # 0 = no stop loss, 200 = 20 pips on a 5-digit feed
TP_POINTS = 0          # 0 = no take profit
COMMENT = "python entry"
# ----------------------------------------

# MQL5 SYMBOL_FILLING_* flags, not exported by the Python package
SYMBOL_FILLING_FOK = 1
SYMBOL_FILLING_IOC = 2


def resolve_symbol(base):
    if mt5.symbol_info(base) is not None:
        return base
    for s in mt5.symbols_get():
        if s.name.upper().startswith(base.upper()):
            return s.name
    return None


def pick_filling_mode(info):
    allowed = info.filling_mode
    if allowed & SYMBOL_FILLING_IOC:
        return mt5.ORDER_FILLING_IOC
    if allowed & SYMBOL_FILLING_FOK:
        return mt5.ORDER_FILLING_FOK
    return mt5.ORDER_FILLING_RETURN


def normalize_volume(info, lot):
    step = info.volume_step
    lot = max(info.volume_min, min(info.volume_max, lot))
    return round(round(lot / step) * step, 8)


def is_filled(result):
    """Your terminal returns retcode 0 with comment 'Done' on success instead
    of TRADE_RETCODE_DONE (10009), so a nonzero deal ticket is the real signal."""
    if result.retcode in (mt5.TRADE_RETCODE_DONE,
                          mt5.TRADE_RETCODE_DONE_PARTIAL,
                          mt5.TRADE_RETCODE_PLACED):
        return True
    return result.deal != 0 or result.order != 0


def place_market_order(symbol, lot, side, sl_points=0, tp_points=0):
    info = mt5.symbol_info(symbol)
    if info is None:
        return None, f"Symbol {symbol} not found"

    if not info.visible and not mt5.symbol_select(symbol, True):
        return None, f"Could not select {symbol} in Market Watch"

    info = mt5.symbol_info(symbol)
    if info.trade_mode == mt5.SYMBOL_TRADE_MODE_DISABLED:
        return None, f"Trading is disabled for {symbol}"

    tick = mt5.symbol_info_tick(symbol)
    if tick is None or tick.ask == 0 or tick.bid == 0:
        return None, "No live price available (market closed or no quotes)"

    is_buy = side.upper() == "BUY"
    order_type = mt5.ORDER_TYPE_BUY if is_buy else mt5.ORDER_TYPE_SELL
    price = tick.ask if is_buy else tick.bid
    point, digits = info.point, info.digits

    sl = tp = 0.0
    if sl_points:
        sl = round(price - sl_points * point if is_buy else price + sl_points * point, digits)
    if tp_points:
        tp = round(price + tp_points * point if is_buy else price - tp_points * point, digits)

    request = {
        "action": mt5.TRADE_ACTION_DEAL,
        "symbol": symbol,
        "volume": normalize_volume(info, lot),
        "type": order_type,
        "price": price,
        "sl": sl,
        "tp": tp,
        "deviation": DEVIATION,
        "magic": MAGIC,
        "comment": COMMENT,
        "type_time": mt5.ORDER_TIME_GTC,
        "type_filling": pick_filling_mode(info),
    }

    result = mt5.order_send(request)
    if result is None:
        return None, f"order_send returned None: {mt5.last_error()}"
    if not is_filled(result):
        return result, f"Order rejected. retcode={result.retcode} ({result.comment})"
    return result, None


def main():
    if not mt5.initialize():
        print("initialize() failed:", mt5.last_error())
        return

    try:
        acc = mt5.account_info()
        if acc is None:
            print("No account info. Is the terminal logged in?")
            return
        print(f"Account {acc.login} | {acc.server} | balance {acc.balance} {acc.currency}")

        if not acc.trade_allowed:
            print("Trading not allowed. Check 'Allow Algo Trading' in the terminal.")
            return

        symbol = resolve_symbol(SYMBOL)
        if symbol is None:
            print(f"{SYMBOL} not available on this broker.")
            return
        if symbol != SYMBOL:
            print(f"Using broker symbol name: {symbol}")

        result, error = place_market_order(symbol, LOT, SIDE, SL_POINTS, TP_POINTS)
        if error:
            print("FAILED:", error)
            return

        print(f"FILLED {SIDE} {result.volume} {symbol} @ {result.price}")
        print(f"Order #{result.order} | Deal #{result.deal}")

    finally:
        mt5.shutdown()


if __name__ == "__main__":
    main()

反馈

1
开发者 1
等级
(263)
项目
309
76%
仲裁
15
67% / 0%
逾期
6
2%
已载入
2
开发者 2
等级
(2)
项目
2
50%
仲裁
0
逾期
0
空闲
3
开发者 3
等级
(559)
项目
853
61%
仲裁
33
27% / 45%
逾期
24
3%
空闲
发布者: 1 代码
4
开发者 4
等级
项目
0
0%
仲裁
0
逾期
0
空闲
发布者: 7 代码
5
开发者 5
等级
项目
0
0%
仲裁
0
逾期
0
空闲
6
开发者 6
等级
(6)
项目
8
38%
仲裁
1
0% / 100%
逾期
0
空闲
7
开发者 7
等级
(2)
项目
2
0%
仲裁
1
0% / 100%
逾期
0
空闲
8
开发者 8
等级
项目
0
0%
仲裁
0
逾期
0
空闲
发布者: 4 代码
9
开发者 9
等级
(2)
项目
7
0%
仲裁
3
0% / 33%
逾期
1
14%
工作中
10
开发者 10
等级
项目
0
0%
仲裁
0
逾期
0
空闲
11
开发者 11
等级
(2)
项目
2
0%
仲裁
0
逾期
0
工作中
发布者: 2 代码
12
开发者 12
等级
项目
0
0%
仲裁
0
逾期
0
空闲
13
开发者 13
等级
(319)
项目
574
35%
仲裁
83
31% / 45%
逾期
207
36%
空闲
14
开发者 14
等级
项目
0
0%
仲裁
0
逾期
0
空闲
15
开发者 15
等级
(1)
项目
1
0%
仲裁
0
逾期
0
空闲
发布者: 3 代码
16
开发者 16
等级
项目
0
0%
仲裁
0
逾期
0
空闲
发布者: 10 代码
相似订单
Hi All, I am looking for a bot EA which makes good profit. If any having please share it for TEST. After proper TESTING only I will make the payment, no cheating no fraud. Please do not waste the time also
Allow me to set the daily trading bias manually to BUY or SELL. Check my defined 4H and 1H trend-alignment conditions. Execute entries based on my 15-minute pullback and continuation rules. Trade only between 06:00 and 16:00 Nigeria time, Monday to Friday. Calculate lot size based on my chosen risk percentage and stop-loss distance. Automatically place stop-loss and take-profit orders. Enforce my daily trade limits
hi, I need a quantower script I need a trailing stop at the 20 ema, And a more complicated version would be a breakout of the Asian session and a retest of the 9ema for an entry and a training stop at the 20 ema
Hi, I’m looking for a **ready-made MT5 scalping EA specifically for Gold (XAUUSD)**. My main requirement is an **HTF scalping strategy**, so I’m looking for an existing robot that is already developed and can be tested before I make the purchase. I’m not looking to build one from scratch at this stage. I would like to first test the EA on a **demo account** to see how it performs under live market conditions and
Rebate robot 30 - 100 USD
Need rebate robot,for pairs like gbpusd,eurusd,usdjpy,usdchf,Spreads are like around 2.5 pip,MAy be better hedge ea both buy and sell,i will get benifit just from rebate,so try ur best to do what i want,and if u r not expert plz go away plz its not simple job,if u already have the robot so i can test it will be surely selected,also u can get some benifit from this screen shoots that i attached,its from another job in
We are looking for an experienced MQL5 developer or algorithmic trader who already owns a fully developed, functional, and profitable Expert Advisor (EA) specifically designed or successfully tested for Prop Firm trading. We are not looking for someone to develop a new trading robot from scratch. Our priority is to collaborate with someone who already has an operational trading system with a proven track record
I am looking for an experienced MQL5 developer or development team to build a scalable Telegram-to-MT5 copy trading system. The main purpose of the system is to monitor trading signals from my Telegram channel and automatically execute those signals on connected client MT5 accounts. Core Requirements Receive and parse trading signals from Telegram Automatically execute trades on connected MT5 accounts Support more
Hi, I’m looking to develop a custom XAUUSD (Gold) trading EA for MT5. I initially wanted to get an EA, but I don’t currently have a specific trading strategy. I would like help developing a suitable strategy from scratch and then converting it into a fully automated MT5 EA. My account size will be around $1,000. I’m interested in a scalping strategy that can trade during both the London and New York sessions. My main
Sami 30+ USD
I've built the bot as a single-page app that runs the three-step workflow you described. Since the page can't pull live broker data, it runs on simulated 5-minute candles or on a CSV you paste in.I've published the trading bot page. I haven't opened or run it, so I can't confirm the logic behaves as intended. It runs on simulated 5-minute candles (or a CSV you paste in) and builds the 4H and 30M charts from them. How
Thana ram 30 - 200 USD
Hello, I want to develop a custom MT5 Expert Advisor (EA) for XAUUSD Gold. IMPORTANT: I want a proper rule-based automated trading EA, NOT a martingale, grid or guaranteed-profit bot. 1. MARKET & TIMEFRAME - Platform: MT5 - Symbol: XAUUSD only - Main trend timeframe: M15 - Entry timeframe: M5 - Must support broker suffixes such as XAUUSDm, XAUUSD., etc. 2. TREND RULE BUY trend: - M15 price above EMA 50 - EMA 50 above

项目信息

预算
30+ USD
截止日期
到 10 天

客户

所下订单1
仲裁计数0