Checking for Awesome Oscillator Buy Sell Signals - Python Code

·

2 min read

Find out what is Awesome Oscillator

The below code checks for Awesome Oscillator signals constantly and gives But and Sell Signals as and when they occur.

df should contain the live data feed close, low, high and open prices with the timeframe for which you wanted to check the Awesome Oscillator Signals.

The code is for a Python script that checks for buy and sell signals in real-time financial market data using a technical indicator called the Awesome Oscillator (AO) from the TA-Lib library.

The code starts by importing the necessary libraries: TA-Lib for the AO calculation, Pandas for data storage and manipulation, and time for waiting between updates.

Next, an empty Pandas dataframe is created to store the live price ticks.

Then, there are two functions defined. The first function, update_ticks, updates the dataframe with the latest tick data. The second function, check_signals, calculates the AO using the high and low values of the latest price ticks and checks for buy and sell signals by comparing the AO values with the previous tick.

Finally, there is a main loop that continuously updates the dataframe with the latest tick data, checks for signals using the check_signals function, and waits for some time (in this case, 60 seconds) before updating the dataframe again.

The buy and sell signals are determined by whether the AO value crosses above or below a threshold value of 0. You can adjust these threshold values according to your strategy.

import talib
import pandas as pd
import time

# create an empty dataframe to store the live price ticks
df = pd.DataFrame()

# function to update the dataframe with the latest tick data
def update_ticks(df, tick_data):
    df = df.append(tick_data, ignore_index=True)
    return df

# function to check for buy and sell signals
def check_signals(df):
    # calculate the AO
    df['ao'] = talib.AWESOME(df['high'], df['low'], fastperiod=5, slowperiod=34)
    # check for buy signals
    if df['ao'].iloc[-1] > 0 and df['ao'].iloc[-2] < 0:
        print("Buy Signal: AO crosses above 0")
    # check for sell signals
    if df['ao'].iloc[-1] < 0 and df['ao'].iloc[-2] > 0:
        print("Sell Signal: AO crosses below 0")

# main loop to continuously update the dataframe and check for signals
while True:
    # get the latest tick data
    tick_data = get_live_ticks()
    # update the dataframe with the latest tick data
    df = update_ticks(df, tick_data)
    # check for signals
    check_signals(df)
    # wait for some time before updating the dataframe again
    time.sleep(60)
#the threshold values for buy and sell signals are set to 0. You can adjust these values according to your strategy.

Did you find this article valuable?

Support Nikhil by becoming a sponsor. Any amount is appreciated!