Comparing Different AI For Stock Trading Strategies

Comparing Different AI For Stock Trading Strategies

7 mins readComment
Jaya
Jaya Sharma
Assistant Manager - Content
Updated on Feb 6, 2025 07:16 IST

Artificial intelligence has reached its peak in the current times. It has millions of use cases amongst which we will be discussing the use of AI for stock trading strategies. Unlike earlier times when AI was being used only by large funds for investing, even retail investors. In case you want to trade and earn using the power of AI then you will have to do two things. First understand which AI model is capable of creating profitable strategies and secondly, you need to learn using these AI models to leverage their capabilities.

ai for stock trading

Please remember, at this stage, do not blindly follow what AI is telling you to do, use your own discretion followed by expert advice.

Table of Contents

Comparing AI For Stock Trading Strategies

The following AI models have been tested and based on that, some have performed well while some have not performed so well. All the AI models that we are discussing below, have been tested using the same prompts. Let us discuss each one in detail.

Test 1: Can AI Models Create a Strategy Through An Indicator?

During this test, each AI was given an indicator’s strategy and was asked to convert it in a code that could be used in Trading View. Here is the prompt given to all AI models:

You are a professional PineScript v6 developer.

You know how to code indicators and strategies. You also know their differences in code.

Please turn a TradingView indicator into a strategy.

When to buy and when to sell:

- Go long when price closes above upper Bollinger Band.

- Close long when price closed below lower Bollinger Band.

Follow these instructions:

- Convert the Indicator specific code to a Strategy specific code. Do not use a code that TradingView Strategy will not support. Especially timeframes and gaps. Define those in code so they are semantically the same as before.

- Preserve timeframe logic if there is one and fill gaps.

- If the indicator is plotting something, the strategy code should plot the same thing as well so the visuals are preserved.

- Do not trigger a short. Simply go Long and Flat.

- Always use 100% of the capital.

- Set the commission to 0.1%.

- Set the slippage to 0.

- strategy.commission.percent and strategy.slippage do not exist in the PineScript. Please avoid this mistake. Set those variables in strategy() function whenever initiating the strategy.

- While initiating strategy() function, do not use line breaks since this will cause compiler error.

- Leave all other strategy settings to the default values (do not set them at all).

- Never use the lookahead_on. 

- Add the Start Date and the End Date inputs/filters so that users can choose from when to execute trades. Start with 1st January 2018 and go to 31st December 2069.

- While setting strategy title, add "Demo GPT - " at start of name and then continue with the strategy name.

This is the code of the Indicator you shall migrate to a TradingView Strategy:

//@version=5

indicator(shorttitle="BB", title="Bollinger Bands", overlay=true, timeframe="", timeframe_gaps=true)

length = input.int(20, minval=1)

maType = input.string("SMA", "Basis MA Type", options = ["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"])

src = input(close, title="Source")

mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")

ma(source, length, _type) =>

    switch _type

        "SMA" => ta.sma(source, length)

        "EMA" => ta.ema(source, length)

        "SMMA (RMA)" => ta.rma(source, length)

        "WMA" => ta.wma(source, length)

        "VWMA" => ta.vwma(source, length)

basis = ma(src, length, maType)

dev = mult * ta.stdev(src, length)

upper = basis + dev

lower = basis - dev

offset = input.int(0, "Offset", minval = -500, maxval = 500, display = display.data_window)

plot(basis, "Basis", color=#2962FF, offset = offset)

p1 = plot(upper, "Upper", color=#F23645, offset = offset)

p2 = plot(lower, "Lower", color=#089981, offset = offset)

fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))

1. OpenAI o1: OpenAI o1 created a profitable and easy trading strategy. Its strategy was tested on the BTC/ USD INDEX chart in 1-day timeframe. As per a Reddit user, a real use case of OpenAI o1 shows that it is one of the best AI for trading strategies. It is more accurate while it takes fewer reasoning tokens.

openai

2. Claude 3.5 Sonnet: Similar to OpenAI, Claude has created an easy and profitable strategy and its result is also the same.

claude
3. Gemini 1.5 Pro: This AI model has also created a profitable strategy and was able to give the same result.
claude

Once all these AI models were tested on prompt 1, they were tested for a different prompt which was harder than the first one.

Explore artificial intelligence courses

Test 2: Can AI Models Improve a Strategy By Adding An Indicator?

 Here the AI models were to check whether they could improve an existing strategy by adding an indicator to it. In this case the following prompt was given:

You are a professional PineScript v6 developer.

You already know how to code the indicators as well as strategies and you also know the differences in code.

Please improve this TradingView strategy.

Add the below given indicator to this strategy and remove the plots and fills it has:

//@version=5

indicator(title="Stochastic RSI", shorttitle="Stoch RSI", format=format.price, precision=2, timeframe="", timeframe_gaps=true)

smoothK = input.int(3, "K", minval=1)

smoothD = input.int(3, "D", minval=1)

lengthRSI = input.int(14, "RSI Length", minval=1)

lengthStoch = input.int(14, "Stochastic Length", minval=1)

src = input(close, title="RSI Source")

rsi1 = ta.rsi(src, lengthRSI)

k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)

d = ta.sma(k, smoothD)

plot(k, "K", color=#2962FF)

plot(d, "D", color=#FF6D00)

h0 = hline(80, "Upper Band", color=#787B86)

hline(50, "Middle Band", color=color.new(#787B86, 50))

h1 = hline(20, "Lower Band", color=#787B86)

fill(h0, h1, color=color.rgb(33, 150, 243, 90), title="Background")

Now improve the strategy like:

- Open long position as soon as gaussian channel is green, the close price is above high gaussian channel band and when Stochastic RSI is above 80 or below 20.

- Close long positions when close price crosses high gaussian channel band to downside.

1. OpenAI: Again, OpenAI could easily improve an existing strategy and gave profitable results.

open ai

2. Claude 3.5 Sonnet: Even Claude was able to deliver profitable result using this level of prompt.

claude 3.5 sonnet

 

3. Gemini 1.5 Pro: Gemini 1.5 Pro was not able to yield profitable result and kept on throwing code error.

Test 3: Can AI Models Create a Strategy from Scratch?

This time the AI models were tested through the hardest level of prompt where they had to create an entire TradingView strategy using a single prompt.

Here is the prompt:

Create a PineScript v6 trading strategy based on Gaussian Channel and add Stochastic RSI in order to avoid bad trades. It can be copy pasted it into TradingView, can be saved and it should run.

Long only and no shorting. Never use lookahead_on. Always trade with 100% of the equity. 0.1% commission. 0 ticks slippage. Start trading from 2018-01-01 until 2069-01-01. Avoid any compiler errors. Use only those functions that exist and are supported by PineScript v5.

1. OpenAI: The AI model could yield profitable results only after many tries.

open ai strategy

2. Claude 3.5 Sonnet: In this case, Claude failed as it could not produce a profitable strategy.

claude 3.5 sonnet

3. Gemini 1.5 Pro :The AI model was able to come up with a strategy that yielded profit but the profit was way low and it took many tries to build the strategy.

gemini 1.5 pro

Comparison: Which AI Model Created a Profitable Strategy?

After comparing the strategies created by all these AI models in TradingView, it can be concluded that OpenAI was the most successful in creating a profitable strategy:

Prompt Level

Open AI

Claude 3.5 Sonnet

Gemini 1.5 Pro

Easy

Yes

Yes

Yes

Medium

Yes

Yes

No

Hard

Yes

No

No

How Can You Use AI Models For Creating a Profitable Trading Strategy?

In order to use AI Models for creating profitable trading strategies, you need to learn using these AI models. Alongwith understanding the proper use of these models, you also need to master prompt engineering so that you can properly guide the AI model to give the required output. A number of course providers are offering courses that will teach you how to leverage Artificial Intelligence. Some of the useful courses have been listed below:

Conclusion

It is important to consider the fact that AI is continuously learning and it cannot be completely relied upon to execute trades without human discretion. Leveraging the capabilities of AI for stock trading is useful since it can perform analysis within minutes which is not possible manually. It is therefore important to consider both Artificial Intelligence and human intelligence for better trading practices.

About the Author
author-image
Jaya Sharma
Assistant Manager - Content

Jaya is a writer with an experience of over 5 years in content creation and marketing. Her writing style is versatile since she likes to write as per the requirement of the domain. She has worked on Technology, Fina... Read Full Bio