0% found this document useful (0 votes)
63 views2 pages

IQ Option Trading Bot

The document outlines a trading bot using the IQ Option API that connects to a practice account and trades based on moving average signals for the EURUSD asset. It calculates fast and slow moving averages to generate buy or sell signals and executes trades accordingly. The bot continuously checks for signals, executes trades, and reports results, while waiting one minute between checks.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views2 pages

IQ Option Trading Bot

The document outlines a trading bot using the IQ Option API that connects to a practice account and trades based on moving average signals for the EURUSD asset. It calculates fast and slow moving averages to generate buy or sell signals and executes trades accordingly. The bot continuously checks for signals, executes trades, and reports results, while waiting one minute between checks.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

from iqoptionapi.

stable_api import IQ_Option


import time
import numpy as np

# ----- Account Setup -----


email = "[email protected]"
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

You might also like