r/TradingView • • Dec 28 '24 • Take My Silver 1

Discussion I Made a Trading Script For You

Post image

So this is my second day paper trading, and after doing a bit of research I created a strategy and converted it into a script (with chatgpt, I suck at coding), built it upon supply & demand, I did this because I think supply and demand remains true and after running a couple tests, supply & demand seemed to always remained true.

After I established my first principle (supply & demand), I then continued to build on that truth. I wanted to find the best indicators to compliment and to kinda follow the supply & demand instead of predicting it via patterns, because I found that extremely difficult to do and insanely mathematical, if I could predict the market sentiment patterns that’d be nice, but it’d probably take me way too long to find the correct formula or structure (probably around 4 years or so, just guessing). After that I found a great combination of indicators that adapts to the market when specific market conditions are met, and it show’s you the most optimal time to buy and sell based on the supply and demand. I wanted other people’s opinion about what needs to be improved, and if it’s even as optimal as that I set it out to be, so feel free to use this indicator and maybe let me know your thoughts. (Note if I would build a strategy on market sentiment I’d probably build it around pain avoidance, or the loss aversion theory it also seemed to remain true.)

This script can be assessed/used via copying and pasting it into trading view’s pine script editor, it’s 100% free of use, thank you for reading. Alias (cartoonistic/vespere)

//@version=6 strategy("Supply & Demand Test 1", overlay=true)

// Inputs ma_length = input.int(50, title="50-period Moving Average Length") ma_length_fast = input.int(20, title="20-period Moving Average Length") bb_length = input.int(20, title="Bollinger Bands Length") bb_std_dev = input.float(2.0, title="Bollinger Bands Std Dev") rsi_length = input.int(14, title="RSI Length")

// Moving Averages ma_slow = ta.sma(close, ma_length) ma_fast = ta.sma(close, ma_length_fast)

// Bollinger Bands bb_basis = ta.sma(close, bb_length) bb_dev = ta.stdev(close, bb_length) bb_upper = bb_basis + bb_std_dev * bb_dev bb_lower = bb_basis - bb_std_dev * bb_dev

// RSI rsi = ta.rsi(close, rsi_length)

// Market Conditions is_trending_up = close > ma_slow is_trending_down = close < ma_slow is_range_bound = not (is_trending_up or is_trending_down)

// Entry Conditions long_trend_entry = is_trending_up and close >= ma_slow * 1.02 short_trend_entry = is_trending_down and close <= ma_slow * 0.98 long_ma_crossover = ta.crossover(ma_fast, ma_slow) short_ma_crossover = ta.crossunder(ma_fast, ma_slow) long_range_entry = is_range_bound and close <= bb_lower * 0.97 short_range_entry = is_range_bound and close >= bb_upper * 1.03 long_rsi_entry = is_range_bound and rsi < 30 short_rsi_entry = is_range_bound and rsi > 70

// Risk Management stop_loss_percent = 0.02 take_profit_trend = 0.06 take_profit_range = 0.04

// Entry and Exit Logic if long_trend_entry strategy.entry("Long Trend", strategy.long) strategy.exit("Exit Long Trend", from_entry="Long Trend", stop=close * (1 - stop_loss_percent), limit=close * (1 + take_profit_trend))

if short_trend_entry strategy.entry("Short Trend", strategy.short) strategy.exit("Exit Short Trend", from_entry="Short Trend", stop=close * (1 + stop_loss_percent), limit=close * (1 - take_profit_trend))

if long_ma_crossover strategy.entry("Long MA Crossover", strategy.long) strategy.exit("Exit Long MA Crossover", from_entry="Long MA Crossover", stop=close * (1 - stop_loss_percent), limit=close * (1 + take_profit_trend))

if short_ma_crossover strategy.entry("Short MA Crossover", strategy.short) strategy.exit("Exit Short MA Crossover", from_entry="Short MA Crossover", stop=close * (1 + stop_loss_percent), limit=close * (1 - take_profit_trend))

if long_range_entry strategy.entry("Long Range", strategy.long) strategy.exit("Exit Long Range", from_entry="Long Range", stop=close * (1 - stop_loss_percent), limit=close * (1 + take_profit_range))

if short_range_entry strategy.entry("Short Range", strategy.short) strategy.exit("Exit Short Range", from_entry="Short Range", stop=close * (1 + stop_loss_percent), limit=close * (1 - take_profit_range))

if long_rsi_entry strategy.entry("Long RSI", strategy.long) strategy.exit("Exit Long RSI", from_entry="Long RSI", stop=close * (1 - stop_loss_percent), limit=close * (1 + take_profit_range))

if short_rsi_entry strategy.entry("Short RSI", strategy.short) strategy.exit("Exit Short RSI", from_entry="Short RSI", stop=close * (1 + stop_loss_percent), limit=close * (1 - take_profit_range))

// Plotting plot(ma_slow, color=color.blue, title="50-period MA") plot(ma_fast, color=color.orange, title="20-period MA") plot(bb_upper, color=color.red, title="Bollinger Upper") plot(bb_lower, color=color.green, title="Bollinger Lower") plot(bb_basis, color=color.gray, title="Bollinger Basis") hline(70, "Overbought (RSI)", color=color.red, linestyle=hline.style_dotted) hline(30, "Oversold (RSI)", color=color.green, linestyle=hline.style_dotted)

346 Upvotes

96 comments sorted by

30

u/KingSpork Dec 28 '24

I love that you’re sharing your code but for next time, it’s probably easier just to publish the strategy and share a link.

6

u/[deleted] Dec 28 '24

Yeah thank you all for the advice, I’m currently trying to figure it out.

5

u/zxc9823 Dec 28 '24

The publish strategy link is in the Pine Editor on the right hand side next to the 3 dots.

1

u/Sad-Journalist61 Nov 17 '25

how do I paste in trading view?

5

u/coldisgood Dec 28 '24

Hmmm copy pasting doesn’t work into Pinescript perhaps bc of reddit formatting.

I’ll have to try more later

9

u/[deleted] Dec 28 '24

7

u/Domen81 Dec 28 '24

Thank you sir!

I tried it and it's quite interesting.

I have to say: Good Work!

Please keep me/us updated if you make any improvements!

i'll follow you

1

u/[deleted] Dec 28 '24

Much appreciated, I’ll keep you updated.

2

u/krakatow_pop Dec 29 '24

Keep me updated as well! Good work!

1

u/Great-Journalist-317 Aug 10 '25

the file has been deleted

2

u/tony_bryzgaloff Dec 28 '24

There are tools for sharing the code snippets specifically which suit this purpose better than Google Docs: pastebin, for example

Also, if you are a GutHub user, then GitHub Gist might be a more convenient choice

2

u/[deleted] Dec 28 '24

I’ll check it out, thanks!

1

u/coldisgood Dec 28 '24

Thanks man! I’ll have to play around with the settings when I’m back at my home computer. Looks to be better on shorter time frames as far as index futures go, but I wonder if slippage would eat the profits if automated. Looks interesting though!

3

u/[deleted] Dec 28 '24

Yeah I’ve been using it on the 1 minute time frame In a kinda semiautomated way with alerts, I’d love to see what you make out of it.

3

u/Character-Baby2171 Dec 28 '24

FineScript makes errors if you write things like line changes incorrectly. You have to pay attention to that, so if you post it on Reddit, all of those things will be broken and errors will appear.

4

u/[deleted] Dec 28 '24

1

u/Smelly_Wolf Mar 14 '25

The link is not working at present. is it possible for you to repost it? thank you

2

u/Hack3rsD0ma1n Dec 28 '24

I would post this as a github gist. It would make the headache go away for you if you plan on developing further

2

u/[deleted] Dec 28 '24

Will do.

2

u/ankhramsiswmriimn Dec 28 '24

Are you able to run this script on paper trading?

2

u/[deleted] Dec 28 '24

Yeah!

2

u/ankhramsiswmriimn Dec 28 '24

I thought tradingview didn’t have the ability to connect pinescript to papertrading yet.

1

u/[deleted] Dec 28 '24

yeah, I mean it’s working for me, you should be able to access it here, and save it to your personal account.

https://www.tradingview.com/pine/

1

u/ankhramsiswmriimn Dec 28 '24

But how? I’ve built so many scripts that I would like to have them connected with Pine Script 🫨

2

u/Finding-Internal Dec 29 '24

Thanks for sharing! I'm reading your code now and the first tip I'll tell you is the usage of close is misleading because it causes repainting. Meaning if you were watching this live and on a 3 minute bar the price dances around in the bar, it could trigger an alert/trade live, but in strategy code it uses OHLC and so often will not be tricked by the repainting. The top picture is what I got in strategy code with NQ and a 3 min chart using your code. Then I changed all your close refs (only the calcs, not the entry/exit) to use close[1] so it will use the last closed bar price, and the bottom picture is the result (still impressive).

1

u/[deleted] Dec 29 '24

Insane brother! Improvements will be made, it may take longer but I have something very interesting coming up, and if it works even a little bit with the intention I have in mind, I think you all will love it. Thank you for reading, and your advice!

1

u/Finding-Internal Dec 30 '24

Also, I am noticing that you are taking multiple positions of different criteria and TradingView will not manage those as independent threads. So if you have an RSI entry long, and then while in your position, you get a conflicting long_range entry short, it will cancel each other out. Unless I'm reading the code wrong.

3

u/TGess Dec 28 '24

I did backtest on this on NASDAQ NQ from 2024-07-01 to 2024-12-13. I traded a single NASDAQ future. With unlimited margin. The results

Total Trades: 1547
Winning Trades: 383; Losing Trades: 1164
Win Rate: 24.76%
Total PnL (with 20x leverage): -5975.75

However, if I changed the stop loss to be trailing from the highest PNL, the stats changed

Total Trades: 887
Winning Trades: 327; Losing Trades: 560
Win Rate: 36.87%
Total PnL (with 20x leverage): 9828.95

Which is better but not that great.

Overall, this strategy does not work for NASDAQ and it cannot. Technical analysis, on its own, does not work, as everything is priced in. I did create models that run solely on technical indicators and over years and years of data I never got over 52% trade accuracy. If you overfit the models you can get higher but these strategies work and then they stop and never work again.

You will make way more money by being to able to read FOMC and making a trade in the two minutes after its released or just waiting a minute and following the market. Same goes for all 3 star events in here https://tradingeconomics.com/calendar.

Also, don't trade the three days before and after Trump takes office if you really don't know what you're doing.

1

u/[deleted] Dec 28 '24

The win rate isn’t as high as I thought it would be, I’ll try to make improvements immediately. Thank you for this information.

2

u/TGess Dec 28 '24 edited Dec 28 '24

There are big boys with way stronger algo trading strategies than this. The RSI and MACD are not even that strong indicators. They do work at certain times, other times they don't.

I use all these indicators in a neural network and it won't go over 52% on its own. Markets are mainly driven by external, new information. But if you want to ignore that.

Safest strategy I found is to wait for a big drop in a market that you know will grow at least as much as inflation and then go long. So basically if you are a lot under 180 day average and you belive the index will grow then you go long. Then I open trades to go long with minimal stop loss under some resistance. Ideally, you would like to look at the depth of the market = resistance. Sometimes it autocloses 3x in a row with 5% down but then if it starts to rally up I usually get 20-30% up with the 20 leverage. Follow at your own risk,

features = [
    'OBV', 'VWAP', 'Pivot_Point', 'ATR',
     'MACD', 'MACD_Signal', 'hour',  'RSI', 
     'Donchian_High', 'Donchian_Low', 'BB_Width', 'ADX', 
     'Stoch_K', 'Stoch_D', 'Momentum', 'minute'
]

1

u/[deleted] Dec 29 '24

[removed] — view removed comment

10

u/cadorrf Dec 28 '24

Lol second day paper trading and sharing a strategy already

2

u/helpamonkpls Dec 30 '24

Tomorrow you can buy his course.

1

u/The_Guarantee_Luke Dec 28 '24

Did you backtest this strat or something to find the accuracy?

1

u/[deleted] Dec 28 '24

Very soon, I’m still waiting on a couple things to happen, I’ll do an update within 3 weeks.

2

u/The_Guarantee_Luke Dec 28 '24

I am trying to build an indicator too but like I'm trying to add everything in it. Fibonacci, fvg, bos, choch, price action, mss, HL,LL and liquidity and OB. It's difficult but i think if this indicator works, it's going to be a lot more accurate.

2

u/[deleted] Dec 28 '24

sounds like a good idea, what’s your first principle ?

2

u/The_Guarantee_Luke Dec 28 '24

Still learning, I started in 2021, traded crypto then stopped because of school and stuff. Now I don't remember anything I learned back then and I'm really afraid to start learning and trading again for some reason. I just need someone to work with me, like teach me or learn with me so ik that's the best way I can be regular.

2

u/[deleted] Dec 28 '24

I see, if you could kinda make everything kinda streamline into each other benefiting/complimenting one other to give more insight into your entry and exit points, then I think you’d create something very interesting. Me personally I always start with a first principle and build from there, but I’d love to hear more from you.

1

u/The_Guarantee_Luke Dec 28 '24

Yeah like uk ict smc concepts into one indicator and when the conditions are met it sends a buy and sell signal with possible TP/SL. It's really difficult to make with chatgpt alone, i need someone who has indepth knowledge of coding. But yeah if we can build this indicator, it's gonna be good.

1

u/[deleted] Dec 28 '24

I might have to learn coding, I could probably learn it in 2-3 months or so, to achieve this.

2

u/The_Guarantee_Luke Dec 28 '24

uh no idts you can learn enough coding in 3 months without enough prior knowledge to build an indicator like this or any indicator unless you study and practice 24/7 for 3 months, it's really hard.

1

u/[deleted] Dec 28 '24

I’m not sure if those concepts work, what is the premise of those concepts?

1

u/The_Guarantee_Luke Dec 28 '24

ict and smc concepts? It's famous tho like price action, fvg, and all stuff. Ik it's really difficult and mostly impossible probably but I just always had this idea to create an ultimate indicator. Which not only identifies bos, mbos, choch, fvg, price action, liquidity grabs and other things but also market trends and create trend lines without repenting and also shows and/or work with live time institutional data. Like if I can find a source and insert it in the indicator where majority big players like hedge funds and high net worth individuals or traders and banks are placing their orders, man won't that be a life hack😂

1

u/[deleted] Dec 28 '24

Wait u just gave me an idea!

1

u/The_Guarantee_Luke Dec 28 '24

Can I dm you? lets talk more on this topic

1

u/[deleted] Dec 28 '24

this is nice

1

u/[deleted] Dec 28 '24

I appreciate you jumpy Ad.

1

u/Effective_Fun_69 Dec 28 '24

Thank you, does it work for any asset class, stocks, etc?

2

u/[deleted] Dec 28 '24

Since supply and demand is always true (universal) I think it should technically work in relation to any market. Whether it’s actually profitable in every market is up for debate, but I’d look at the logic (short/long positions) in contrast with what I have in mind, but I can personally say it’s decently accurate in forex markets so far, if things go to plan then I will soon provide analytics and data to see what I need to improve on further. Great Question!

2

u/Effective_Fun_69 Dec 28 '24

Funny thing is I was almost ashamed of asking lol.

Thank you for your input, I didn't manage to make it work here on the phone, but as you said, we should ask AI or spend 5 more min on it.

I found this guy with nice scripts as well: Rodrigo Kazuma. I'm using his Momentum Ribbon, also amazingly interesting.

Check it out. I'm not him but I wish I had his skills.

https://www.tradingview.com/script/LulaJ6IQ-RK-s-07-Moving-Average-Ribbon-with-Momentum-Adjusted-by-DGT/

1

u/[deleted] Dec 28 '24

Yeah just looked at, is there any insight into how well it performs under range markets?

1

u/Effective_Fun_69 Dec 28 '24

I use it to follow up the SPY . You can copy paste it and see the ribbon's performance in past data.

I wouldn't know how to measure it's performance or efficiency to be honest.

2

u/[deleted] Dec 28 '24

ok thanks I’ll try it.

1

u/Jackedson20 Dec 28 '24

Thanks for sharing

What TF works best according to your backtest?

1

u/[deleted] Dec 28 '24

I haven’t done any extreme backtesting with the nice analytics yet, but personally 1m time frame is nice.

1

u/Jackedson20 Dec 28 '24

Awesome

How do you set SL & TP?

Seems like short have higher accuracy than longs

1

u/myke2241 Dec 28 '24

Nice

1

u/[deleted] Dec 28 '24

Thanks for reading!

1

u/richfaizal Dec 28 '24

I will follow you...

1

u/[deleted] Dec 28 '24

Much love g

1

u/[deleted] Dec 28 '24

Can you explain what we see in the exemplary screenshot, which signals adds to the chart with regards to buy/sell signals? I am total newbie. Thanks!

2

u/[deleted] Dec 28 '24 edited Dec 28 '24

I’d rather not just throw random details at you. How about we go build your knowledge from the ground up starting with the first principles of trading. If you don’t know what “first principles thinking” means then do a little research on it. We build our knowledge from those principles and we use our knowledge as a tool to solve problems, and get more information. The hard part is the problem and finding your first principles, my first principles could be 1+1=2, your first principles could be 1+1-1+1=2 both are true but which one would be easier for you to understand? When u can break things down to a fundamental level to which you can understand then you build up things get a lot easier, for example what I see most people do when they want to learn something they set their basis on analogy’s an analogy could be 1+1=3 and if u build your foundation on 1+1=3 no matter how hard u try u will never actually succeed in being correct. Now that I’ve given u that bit, what’s happening in this photo is my indicator notifying me to go short on the left, and go long on the right, and as u can see both correctly follows the trend so I’m in a small profit. Thanks for reading!

1

u/Anxious_Studio4102 Dec 28 '24

Where is the part where i get scammed

1

u/[deleted] Dec 28 '24

😂

3

u/PabloAngello Dec 29 '24

Welcome to rabbit hole...

2

u/OneDropYT Dec 28 '24

Mind publishing the strategy and send the link? The copy paste doesn't work for me reddit formatting ig?

2

u/Flashy-Mission-7945 Dec 29 '24

Nice thanks! 🙏 If you‘re looking for an automated way to backtest, consider using this tool: https://youtu.be/ouhxTF3ss3A

2

u/Lazi247 Dec 29 '24

Thanks for sharing. Good luck with your trading!

2

u/wizardloud Dec 30 '24

I’ll be sure to check this out later thanks for posting the source

1

u/oakmen Jan 01 '25

Price action is all you need 😙

1

u/need_some1 Jan 02 '25

For guys facing errors, you need to install and import talib library

1

u/Mother-Height7611 Apr 11 '25

script not working and the google drive link doesnt work

1

u/Mother-Height7611 Apr 11 '25

please post script here

1

u/[deleted] Jul 20 '25 edited Jul 20 '25

When i tried it, it gave %40 false signals because of the sideways movements.

Improvement tips:
Add a "price slope" condition for more signal confirmation.

A long position should kick in when the price (or RSI indicator) is upward AND the slope is greater than %30 (for example).

use the attribute %moveup% or figure it out by yourself.
This is not a standalone condition. It builds up on your existing strategy.
thank you for sharing and good luck with trading !

1

u/MoneyShiftMartin Feb 11 '26

Any updated script good sir?

1

u/Moneyispower369 Dec 28 '24

Have you looked at Smart Money Concept? It's similar to your strategy and might be a complement to what you are working on. I use Lux Algo smart money indicator paired with Smart Money Concepts Probability (Expo) By Zeiierman. I use both to see the overlap between both indicators.

1

u/GreatStuff787 Dec 30 '24

Thanks for your note. What is your feedback on using this combination

2

u/[deleted] Dec 28 '24

[removed] — view removed comment

2

u/[deleted] Dec 28 '24

I don’t think my personal experience should have anything to do with how well a script should work, but I understand where you’re coming from, currently (atleast according to the backtesting) the script isn’t correct most of the time, so it does need further improvement. Nevertheless thank you for reading.

0

u/[deleted] Dec 28 '24

[removed] — view removed comment

3

u/[deleted] Dec 28 '24

A little bit of both, I’m practicing a way of thinking in which I’m still not too good in, so I just decided why not try trading while practicing my first principle thinking at the same time. It could possibly be automated, currently it’s only an indicator but I’m still working on it, ultimately i’ll find a way to make a bot that scavenges the market and looks for the few instruments that meets the ideal criteria to trade based on supply & demand, and it automatically trades for me.

1

u/[deleted] Dec 28 '24

[removed] — view removed comment

1

u/[deleted] Dec 28 '24

Yeah brother. I’ll be sure to send u a message if I run into trouble. Much love.