You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi Anyone can help me to correct this script, I have made this script with the help of ChatGPT,
Logic are when Parabolic SAR appear on Bottom of Second candle it should buy CALL trade for Binary for 1 min
same goes for sell when Parabolic SAR appear on Top of Second candle it should buy PUT trade for Binary 1 min
every thing is working fine in this script connection balance print login and all. after connection I am facing "Required keys not found in candle data." this message.
Here is the Script.
from iqoptionapi.stable_api import IQ_Option
import time
Create an instance of IQ Option API
api = IQ_Option("mail", "password")
Select account type (PRACTICE or REAL)
account_type = "PRACTICE" # Change to "REAL" for real account
Connect to the IQ Option account
api.connect()
Check if the API connection is successful
if api.check_connect():
print("Connected to IQ Option")
# Set balance type based on selected account type
if account_type == "PRACTICE":
api.change_balance("PRACTICE")
print("Trading in PRACTICE account")
elif account_type == "REAL":
api.change_balance("REAL")
print("Trading in REAL account")
else:
print("Invalid account type selected. Please choose either PRACTICE or REAL.")
api.close_connect()
exit()
# Print account balance
balance = api.get_balance()
print("Account Balance:", balance)
for i in range(len(candles)):
if i == 0:
sar_values.append(candles[i]["low"])
continue
if uptrend:
if candles[i]["low"] < previous_ep:
uptrend = False
sar_values.append(previous_ep)
af = step
ep = candles[i]["high"]
continue
sar = previous_sar + af * (previous_ep - previous_sar)
sar_values.append(sar)
if candles[i]["high"] > previous_ep:
af += step
if af > maximum:
af = maximum
ep = candles[i]["high"]
else:
ep = previous_ep
else:
if candles[i]["high"] > previous_ep:
uptrend = True
sar_values.append(previous_ep)
af = step
ep = candles[i]["low"]
continue
sar = previous_sar + af * (previous_ep - previous_sar)
sar_values.append(sar)
if candles[i]["low"] < previous_ep:
af += step
if af > maximum:
af = maximum
ep = candles[i]["low"]
else:
ep = previous_ep
previous_sar = sar
previous_ep = ep
return sar_values
Start the trading loop
while True:
# Get the current candles
candles = api.get_realtime_candles(ACTIVES, candle_interval)
# Check if new candles are available
if candles:
# Check if the required number of candles is available for the time frame
if len(candles) >= 5:
current_candle = candles[-1]
previous_candle = candles[-2]
# Check if the required keys are present in the candle data
if "low" in current_candle and "low" in previous_candle:
# Calculate Parabolic SAR values
parabolic_sar_values = calculate_parabolic_sar(candles, parabolic_sar_step, parabolic_sar_maximum)
current_sar = parabolic_sar_values[-1]
previous_sar = parabolic_sar_values[-2]
# Check buy conditions
if current_sar < current_candle["low"] and previous_sar < previous_candle["low"]:
print("Placing BUY order")
api.buy(ACTIVES, trade_amount, "call", expiration_time)
# Check sell conditions
if current_sar > current_candle["high"] and previous_sar > previous_candle["high"]:
print("Placing SELL order")
api.buy(ACTIVES, trade_amount, "put", expiration_time)
else:
print("Required keys not found in candle data.")
else:
print("Insufficient number of candles for the specified time frame.")
# Wait for some time before checking for new candles
time.sleep(1)
The text was updated successfully, but these errors were encountered:
Hi Anyone can help me to correct this script, I have made this script with the help of ChatGPT,
from iqoptionapi.stable_api import IQ_Option
import time
Create an instance of IQ Option API
api = IQ_Option("mail", "password")
Select account type (PRACTICE or REAL)
account_type = "PRACTICE" # Change to "REAL" for real account
Connect to the IQ Option account
api.connect()
Check if the API connection is successful
if api.check_connect():
print("Connected to IQ Option")
Define the candle interval and expiration time
candle_interval = 60 # 1 minute
expiration_time = 1 # 1 minute
Define the Parabolic SAR parameters
parabolic_sar_step = 0.02
parabolic_sar_maximum = 0.2
Define the trade amount
trade_amount = 1 # Change this to the desired trade amount
Define the trading pair
ACTIVES = "EURUSD-OTC" # Replace with your desired trading pair
Start streaming candles
max_candles = 100 # Set the maximum number of candles to receive
api.start_candles_stream(ACTIVES, candle_interval, maxdict=max_candles)
Function to calculate Parabolic SAR values
def calculate_parabolic_sar(candles, step, maximum):
sar_values = []
previous_sar = 0
previous_ep = 0
af = step
uptrend = True
Start the trading loop
while True:
# Get the current candles
candles = api.get_realtime_candles(ACTIVES, candle_interval)
The text was updated successfully, but these errors were encountered: