ChatGPT-4 and AI-Agents: An Exponential Approach to Building Trading Strategies.

SmartLever
5 min readApr 22, 2023

Artificial Intelligence is the new electricity. Just as electricity transformed many industries about 100 years ago, AI will do it now. — Andrew Ng

It’s already been five months into 2023, but it seems like it was only yesterday that ChatGPT-3 was made available. Welcome to the glorious exponential universe. This is not about following someone’s Twitter prompt and having our lives mapped out, whether we like it or not. The long path offers potential, while the short one takes us to mediocrity, just like everything else in life.

On the job market, AI is not poised to replace you; instead, those who adeptly employ AI for their own gain are likely to prosper and may even outpace you. Using customized AI with a thorough understanding of a given application area is where the real promise of AI is found. This specific AI has the potential to totally transform all industries. Everything will develop into an exponential circle with faster turns.

There must be numerous instances in which an exponential circle can be used. As a simple example, we appointed ChatGPT4 as the CEO of SmartLever in this post with the aim of suggesting a weekly action to help us expand the community. ChatGPT has requested that we start by identifying our most successful post and renewing it with fresh content. This post is the outcome.

In this article, we used ChatGPT-3 to build an automated trading system that we could use with SmartBots. So, instead of using Bing, we will utilize AIAgents, the newest idea that is revolutionizing AI, which is an AI that is 10 times as powerful as the last one we used, ChatGPT-4.

The query, Agents:

In the AI Cambridge Explosion, AI agents are a hot issue. A couple of the libraries that are expanding rapidly are BabyAGI and AutoGPT.

Artificial intelligence (AI) agents are computer programs or systems that independently carry out operations, reach conclusions, or resolve issues in accordance with their programming and the data they have access to. They are capable of carrying out tasks in a wide range of areas, including natural language processing, image recognition, decision-making, and more. They are frequently built to somewhat resemble human intellect or behavior.

There are many different kinds of agents that could exist; in this case, goal-based agents are our focus. These agents have clear goals they want to accomplish, and they choose the best course of action to get there.

I requested AI agents to research a financial market counter-trend trading strategy.

Here is the solution after sending an army of agents to fulfill the task:

The coder: ChatGPT-4

We were given three options by the AI agent. Let’s try the final option and include it in the prompt.

Pivot Point Strategy: This strategy involves using pivot points to identify potential reversal points in the market. A position is taken against the current trend when the market reaches these levels.

The Prompt:

Note: In the example, please copy and paste the code from the provided link. The code was not included here for simplicity.

You are a specialized Python coding assistant for quantitative trading with trading systems and strategies.
create a new class that inherits from the Abstract_Strategy class, follow this three points:
1) Use the example as a guide.
2) Create all the respond within one code block.
3) Make comments to explain the code.

example: """https://github.com/SmartLever/SmartBots/blob/main/src/domain/services/strategies/rsi_chatgpt.py"""

Query: """I want a counter-trend strategy, the strategy involves using pivot points to identify a potencial reversal points in the market.
A position is taken against the current trend when the market reaches these levels."""
Respond: """ """

It works! Wow! 🤩

It worked perfectly on the first try, without any tweaking. The advancement from ChatGPT-3.5 to ChatGPT-4 is remarkable.

class Pivot_Points_Strategy(Abstract_Strategy):
def __init__(self, parameters: dict = None, id_strategy: int = None, callback: callable = None,
set_basic: bool = True):
super().__init__(parameters, id_strategy, callback, set_basic)

# Initialize variables
self.high = None
self.low = None
self.close = None
self.pivot_point = None
self.support_1 = None
self.resistance_1 = None
self.support_2 = None
self.resistance_2 = None

def calculate_pivot_points(self):
# Calculate the pivot point
self.pivot_point = (self.high + self.low + self.close) / 3
# Calculate the support and resistance levels
self.support_1 = 2 * self.pivot_point - self.high
self.resistance_1 = 2 * self.pivot_point - self.low
self.support_2 = self.pivot_point - (self.high - self.low)
self.resistance_2 = self.pivot_point + (self.high - self.low)

def add_event(self, event):
if event.event_type == 'bar':
# Store high, low, and close prices
self.high = event.high
self.low = event.low
self.close = event.close

# Calculate pivot points
self.calculate_pivot_points()

# Counter-trend trading logic
if self.close >= self.resistance_2 and self.position <= 0:
quantity = self.quantity
if self.position == 1:
quantity = self.quantity * 2

# Send a sell order
self.send_order(ticker=self.ticker, price=event.close, quantity=quantity, action='sell',
type='market', datetime=event.datetime)
elif self.close <= self.support_2 and self.position >= 0:
quantity = self.quantity
if self.position == 1:
quantity = self.quantity * 2

# Send a buy order
self.send_order(ticker=self.ticker, price=event.close, quantity=quantity, action='buy',
type='market', datetime=event.datetime)
elif event.event_type == 'tick' and event.tick_type == 'close_day':
# Update equity strategy at the end of the day if necessary
self.update_equity(event)

The tutor: Learning the Logic

That might have been anything, but I asked the chat to elaborate on how this works:

def calculate_pivot_points(self):
# Calculate the pivot point
self.pivot_point = (self.high + self.low + self.close) / 3
# Calculate the support and resistance levels
self.support_1 = 2 * self.pivot_point - self.high
self.resistance_1 = 2 * self.pivot_point - self.low
self.support_2 = self.pivot_point - (self.high - self.low)
self.resistance_2 = self.pivot_point + (self.high - self.low)

Putting it all together:

  • As expected, the equity had an uptrend in 2022 during the counter-trend market regime. However, it started to falter in January 2023, indicating a change to a trend market regime.
  • You can replicate this equity in five minutes with SmartBots. Here’s a tutorial.

Takeaways

  • The exponential trading circle is a potent idea that helps us sharpen our trading skills with each breakthrough.
  • The enhancements in ChatGPT-4 over its predecessor are hardly the beginning.
  • Agents will enable us to construct things we can’t even begin to fathom at this time. Assume we have an exponential circle that, at the push of a button, instantly implements our trading strategy, programs it, fixes any bugs it finds, backtests it, and stops when we get a satisfactory result.

Subscribe to all our news here.

The train is in the station, and you can’t miss it, so join us on this journey. We are an open community and if you want to collaborate with us, please send us an email: andres@smartlever.tech

--

--