issue in placing an order using python

 

this is my code and it is not placing an order:-

import MetaTrader5 as mt5
import time

mt5.initialize()

risk_percentage = 1.0

balance = mt5.account_info().balance

risk_amount = balance * (risk_percentage / 100.0)

while True:
    
    candle_data = mt5.copy_rates_from_pos("XAUUSDm", mt5.TIMEFRAME_M1, 0, 3)
    prev_candle = candle_data[1]
    open_price_prev = prev_candle["open"]
    high_price_prev = prev_candle["high"]
    low_price_prev = prev_candle["low"]
    close_price_prev = prev_candle["close"]
    
   
    sec_last_candle = candle_data[0]
    open_price_sec_last = sec_last_candle["open"]
    high_price_sec_last = sec_last_candle["high"]
    low_price_sec_last = sec_last_candle["low"]
    close_price_sec_last = sec_last_candle["close"]
    
   
    current_candle = candle_data[2]
    open_price_curr = current_candle["open"]
    high_price_curr = current_candle["high"]
    low_price_curr = current_candle["low"]
    close_price_curr = current_candle["close"]
   
   
   

  
    if prev_candle["open"] < prev_candle["close"]:
        
        entry_price = prev_candle["high"] + 0.21

       
        stop_loss_price = prev_candle["low"] - 0.21

        # place the buy order
        result = mt5.order_send(symbol="XAUUSDm", volume=risk_amount / entry_price, type=mt5.ORDER_TYPE_BUY_LIMIT,
                                      price=entry_price, sl=stop_loss_price, tp=0)
        print(f"buy order placed at {entry_price}" )
    time.sleep(1)
 

Please edit your post to use the CODE button (Alt-S)!

Use the CODE button

Reason: