[MT5 auto place an Buy order when i do nothing

 

Hi everyone,

I'm trying to use Python for automatic trading (Demo account), but I found that MT5 Auto places a Buy order when I do nothing.

And only one time when start

Here is my code, only initialize, nothing else

import MetaTrader5 as mt
mt.initialize()
symbol = 'XAUUSD'
while True:
    current_second = time.localtime().tm_sec
    if current_second == 1:
       
        #Setting
        timeframe = mt.TIMEFRAME_M1
        start_bar = 0
        num_bars = 50

Then, when the second is 1, MT5 auto places a Buy order with 0.01 lot.

I don't know why it happened.

Please help me.

MQL5 Programming for Traders – MetaTrader 5 algorithmic/automatic trading language manual
MQL5 Programming for Traders – MetaTrader 5 algorithmic/automatic trading language manual
  • www.mql5.com
MQL5 Programming for Traders – MetaTrader 5 algorithmic/automatic trading language manual
 
You might want to add some logging to your script to see if your code is reaching the point where an order would be placed:
import MetaTrader5 as mt
import time

print("Initializing MT5 connection...")
mt.initialize()
symbol = 'XAUUSD'

while True:
    current_second = time.localtime().tm_sec
    if current_second == 1:
        print("The second is 1, but no order should be placed.")

        # Setting
        timeframe = mt.TIMEFRAME_M1
        start_bar = 0
        num_bars = 50
        # Add your logging or print statements here

Running this script should help you verify whether the script itself is responsible for the order or if something else is triggering it. If your script is indeed the culprit, you may need to share the complete script for a more thorough examination. If it's not your script, you'll need to investigate the MT5 terminal settings and any other running EAs or scripts.


Reason: