from iqoptionapi.
stable_api import IQ_Option
import time
import numpy as np
# ----- Account Setup -----
email = "your_email@example.com"
password = "your_password"
I_want_money = IQ_Option(email, password)
I_want_money.connect()
# Check connection
if not I_want_money.check_connect():
print("Login failed.")
exit()
else:
print("Logged in.")
I_want_money.change_balance("PRACTICE") # use "REAL" for live account
# ----- Bot Settings -----
asset = "EURUSD"
amount = 1
duration = 1 # minute
fast_period = 5
slow_period = 10
candle_count = 20
def get_moving_average(prices, period):
return np.convolve(prices, np.ones(period)/period, mode='valid')
def get_signal(prices):
fast_ma = get_moving_average(prices, fast_period)
slow_ma = get_moving_average(prices, slow_period)
if len(fast_ma) < 1 or len(slow_ma) < 1:
return None
if fast_ma[-1] > slow_ma[-1] and fast_ma[-2] <= slow_ma[-2]:
return "call" # Buy signal
elif fast_ma[-1] < slow_ma[-1] and fast_ma[-2] >= slow_ma[-2]:
return "put" # Sell signal
return None
# ----- Main Loop -----
while True:
candles = I_want_money.get_candles(asset, 60, candle_count, time.time())
prices = [candle['close'] for candle in candles]
signal = get_signal(prices)
if signal:
print(f"Signal detected: {signal.upper()}")
check, trade_id = I_want_money.buy(amount, asset, signal, duration)
if check:
print(f"Trade executed! Direction: {signal.upper()}")
time.sleep(duration * 60 + 5) # wait for result
result = I_want_money.check_win_v4(trade_id)
if result > 0:
print(f"Win! Profit: ${result}")
elif result == 0:
print("Draw.")
else:
print(f"Loss: ${-result}")
else:
print("Trade failed.")
else:
print("No trade signal.")
time.sleep(60) # wait 1 minute before next check