How to find the OPTIMAL Stop Loss / Target Profit with Python for a Trading Strategy

  Рет қаралды 21,658

Algovibes

Algovibes

Күн бұрын

Пікірлер: 98
@Ejnota
@Ejnota Жыл бұрын
¡Gracias!
@Algovibes
@Algovibes Жыл бұрын
Thanks buddy! :-) Appreciate your support
@Ejnota
@Ejnota 9 ай бұрын
One question, if the open is the one that is shifted and the iteration over the rows gos row by row, then why you compared the row.Low of that particular row if that row already passed, shouldn't we compared with row.Low of the next row? @@Algovibes
@Ejnota
@Ejnota 9 ай бұрын
Could happen that the stop lost of take profit is triggered over a row that has past already
@Ejnota
@Ejnota 9 ай бұрын
I just realized that it could be fixed adding an elif in the first if
@Kr3m3rsVids
@Kr3m3rsVids 2 жыл бұрын
Fantastic! Forward looking bias, overfitting, slicing data, stop loss optimising and so on, all in 1 video and 100% Python! Great content, thanks again!
@Algovibes
@Algovibes 2 жыл бұрын
Thanks a lot for your comment buddy. Appreciate it!
@timwaldau1649
@timwaldau1649 2 жыл бұрын
Hi, cool stuff! Thank you! ... but in my point of view there is a little issue. In some cases it could be that both conditions apply (if row.Low < buyprice * 0.99:... elif row.High > buyprice * 1.01:). In a 4h timeframe and higher volatility the candle low and the candle high could touch both - the sl- and also the tp-price within one candle. But which of both first? ... In this case it is theoretically necessary to zoom in a smaller timeframe to find out which high or low was first. I'm wrong? Here an example with a assumed buyprice (next time stamp open) of 41k buyprice=41000 # 41000 * 0.99 = 40590 # 41000 * 1.01 = 41410 Low=40500 High=41600 if Low < buyprice * 0.99: sellprice = buyprice * 0.99 print("sellprice SL: {}".format(sellprice)) print() elif High > buyprice * 1.01: sellprice = buyprice * 1.01 print("sellprice TP: {}".format(sellprice)) print() ''' sellprice SL: 40590.0 ''' # 'elif' is only applied if the first condition is false...
@vidabask
@vidabask 2 жыл бұрын
Thanks mate! Keep doing what you're doing. Everytime I watch one of your videos I feel inspired to keep working on my algo trading! Question: don't you use CCXT?
@Algovibes
@Algovibes 2 жыл бұрын
I am not using CCXT for trading (yet). Planning something on it and actually will release an intro video on ccxt today.
@jerrywang3225
@jerrywang3225 2 жыл бұрын
I believe there's a bug here. df.Low < buyprice *0.99, what if the low happens to be on the same candle of the buy signal, so i think we should add index> buydate to our selling condition. Correct me if i am wrong.
@drizham
@drizham Жыл бұрын
Very elegant programming and logic. Very nice
@Algovibes
@Algovibes Жыл бұрын
Thanks buddy. Appreciate your comment! Be invited to check out my other stuff :-)
@一般男性-i5q
@一般男性-i5q 2 жыл бұрын
I think it's simpler to generate "Buy" columns use: df['Buy'] = (df.SMA_50 > df.SMA_100) & (df.SMA_50.shift() < df.SMA_100.shift()) Just for reference. By the way, nice tutorial again, Thanks.
@Algovibes
@Algovibes 2 жыл бұрын
Sure! Also a legit and even better way to do it. Thanks for your contribution.
@cmrncrick
@cmrncrick 2 жыл бұрын
Love all your videos! Thank you for such quality education!
@Algovibes
@Algovibes 2 жыл бұрын
Thanks a ton mate! My pleasure.
@kev0dev
@kev0dev 2 жыл бұрын
This is an awesome video! Thanks so much for you work!
@Algovibes
@Algovibes 2 жыл бұрын
Thank you very much buddy :-)
@Larussiecestlavie
@Larussiecestlavie Жыл бұрын
very good video, but what if the stoploss and take profit get hit both at the same time step?
@Algovibes
@Algovibes Жыл бұрын
Thanks mate. To avoid that you need more granular data. I think I am also mentioning that some when in the video.
@alexanderher7692
@alexanderher7692 Жыл бұрын
how do you pull tradingview data including previous signals from dynamic strat?
@AshishKumar-oe2sx
@AshishKumar-oe2sx Жыл бұрын
Is theres a method where we can get the number of stop loss hit in the intraday and if once the desired profit is achieved then to leave the marker ... In short we want to backrest how many times does the indicator fails in the intraday.
@Algovibes
@Algovibes Жыл бұрын
Sure, that's definitely possible!
@arunavadatta7734
@arunavadatta7734 2 жыл бұрын
This tutorial video is awesome......now make a video with same logic with trailing stoploss instead of static stoploss.
@Algovibes
@Algovibes 2 жыл бұрын
Cool suggestion. Thanks a lot!
@alexanderher7692
@alexanderher7692 Жыл бұрын
do you have the code somewhere in open repo?
@Algovibes
@Algovibes Жыл бұрын
Even better! You have the opportunity to support my channel and get access to the code: kzbin.info/door/87aeHqMrlR6ED0w2SVi5nwjoin Looking forward to see you there!
2 жыл бұрын
Welche Börse benutzt du ? FTX ist schon mal nicht. Binance kann keine Futures in der EU. Bleibt noch Phemex und so ähnliche. Schiele auch auf einen institutionellen Accout.
@Algovibes
@Algovibes 2 жыл бұрын
Ne FTX habe ich glücklicherweise nie benutzt. Ich hab nur mal ein bisschen mit deren API rumgespielt. Ich handle aktiv momentan spot auf Binance, Optionen/Futures hatte ich mal bei Delta gecheckt, allerdings crasht deren API permanent bei mir und ist daher produktiv nicht nutzbar für mich. Ich will die short Seite wieder traden, daher bin ich auch immer auf der Suche nach guten Alternativen zu Binance.
2 жыл бұрын
@@Algovibes ich schau mir gerade phemex an und recherchiere erstmal nach Standort, Support, Sicherheit und api quality.
@kitbodeephongkasem909
@kitbodeephongkasem909 Жыл бұрын
please show video how to optimize tp and sl in multitime frame ?
@Algovibes
@Algovibes Жыл бұрын
Cool idea, thanks a lot. Maybe interesting for you: Multi Timeframe strategy: kzbin.info/www/bejne/j4nNdoFvq65gl7c
@anilmm2005
@anilmm2005 2 жыл бұрын
Thanks for wonderful set up and explanation
@Algovibes
@Algovibes 2 жыл бұрын
Thanks for watching buddy
@ionutoceanu
@ionutoceanu Жыл бұрын
Valuable content sir. The only issue that I found is the calculation of relative profits reported to buyprice. I think it should be: profits = pd.Series([((sell-buy)/buy)*100 for sell,buy in zip(sellprices, buyprices)]) print(profits.sum())
@Algovibes
@Algovibes Жыл бұрын
Thanks mate. No You cannot do that. I explained why you can't do that here: kzbin.info/www/bejne/nIirgqqniZifhLs Let me know if you need any more input!
@denniscarver9147
@denniscarver9147 2 жыл бұрын
Hey Algo, how can I do this by testing a portfolio? Instead of a single stock or crypto, a portfolio of positions that meet our buy criteria?
@Algovibes
@Algovibes 2 жыл бұрын
Yea sure! Also possible. I have videos on backtesting large amount of cryptos and stocks both in my Python for Finance and cryptobot playlist. Be invited to check that out!
@hosseinvahidi5387
@hosseinvahidi5387 Жыл бұрын
Very intuitive and simple. Thank you.👍
@Algovibes
@Algovibes Жыл бұрын
Welcome buddy, thanks a lot for watching! :-)
@saisac7357
@saisac7357 2 жыл бұрын
Great work sir...
@Algovibes
@Algovibes 2 жыл бұрын
Thanks a ton :-)
@tradingbotspro
@tradingbotspro 2 жыл бұрын
Hey! Nice video! Thanks a lot for showing your approach of handling stops. Looking forward to take a look to the next stage - figuring out how to implement and optimise trailing sl he-he. Also, regarding math of this video: what is about DD? Because we calculated tp and sl every time like we have the same position size, but that is not correct since we definitely had got DD from negative trades. Thus, we should either took the bigger leverage or deposit additional money or decrease lot size which would definitely distort the final PnL. I understand, that purpose of the video was to explore stops calculation and operation logics, but I would like to pay attention for everyone that there are a tons of moments before some real and working strategy will be done, backtested and optimised :)
@Algovibes
@Algovibes 2 жыл бұрын
Thanks mate! You made good and correct points and they are all covered in my videos 😁 I just cannot cover everything in every single video.
@tradingbotspro
@tradingbotspro 2 жыл бұрын
@@Algovibes understood, otherwise it would be a very long videos hehe
@Niko-ie6dh
@Niko-ie6dh 2 жыл бұрын
good video, just one remark: you added trading fees but you didnt incorporate slippage. as you do not buy an Open by limitorder, your marketorder would cost you a certain amount of %. The trade exit is done by limit so there you can 1:1 use the price. This is actually very important to keep in mind because it will ruin alot of good-looking paper strategies. 👍🏻
@tradingbotspro
@tradingbotspro 2 жыл бұрын
I think, if we are talking about some highly liquid crypto like btc, eth, etc. and usual individual trader amount of trade - it will be almost without slippage because of relatively small amount of position and high liquidity OR yes you're right we could simply use LO and get exact price. And btw on btc pair there is no fees for a while)))
@Algovibes
@Algovibes 2 жыл бұрын
Good point on the market order in general. Anyhow I assume the slippage effect on high liquidity cryptos will be too small to make any substantial difference.
@Larussiecestlavie
@Larussiecestlavie Жыл бұрын
​@@Algovibes the fees for crypto are so high that you don't have to care about slippage
@titucartoon
@titucartoon 2 жыл бұрын
Hi Sir This Is Biplov From India I am really help full from you but one thing sir when i code it it showing import pandas as pd import numpy as np from binance.client import client client = client() ModuleNotFoundError Traceback (most recent call last) Cell In[1], line 3 1 import pandas as pd 2 import numpy as np ----> 3 from binance.client import client 4 client = client() ModuleNotFoundError: No module named 'binance.client'; 'binance' is not a package plz help me
@Algovibes
@Algovibes 2 жыл бұрын
Just install the binance library. Should the solve the issue. Greetings to India :-)
@titucartoon
@titucartoon 2 жыл бұрын
@@Algovibes 🙏🙏🙏👍🏻
@titucartoon
@titucartoon 2 жыл бұрын
Sir have you any mail???
@ionutoceanu
@ionutoceanu 2 жыл бұрын
Very good explanation and very usefull piece of code. Thanks !
@Algovibes
@Algovibes 2 жыл бұрын
Thanks a lot buddy. Appreciate your comment :-)
@mistycsoul
@mistycsoul 2 жыл бұрын
Good video👍Can you make a video for a optimal sl tp ,for renko strategy?
@Algovibes
@Algovibes 2 жыл бұрын
Thanks mate. Noted your suggestion!
@mahmoodhajipour3680
@mahmoodhajipour3680 2 жыл бұрын
thank you, it was enjoyable to watch this video, would you please use optimization algorithms for this topic?
@Algovibes
@Algovibes 2 жыл бұрын
Welcome mate. Which one do you have in mind would be interesting for you?
@InspiringVibesVideos
@InspiringVibesVideos 2 жыл бұрын
Thanks for the Tutorial, Can you share the code so it is easier to code in colab? Thank!
@Algovibes
@Algovibes 2 жыл бұрын
Welcome mate. Sure! Code is available here: kzbin.info/door/87aeHqMrlR6ED0w2SVi5nwjoin Looking forward to your mail! :-)
@PavelSumik
@PavelSumik 2 жыл бұрын
Another super video, thank you very much for your great work
@Algovibes
@Algovibes 2 жыл бұрын
Thanks a ton Pavel!
@mrrolandlawrence
@mrrolandlawrence 2 жыл бұрын
great content as ever :)
@Algovibes
@Algovibes 2 жыл бұрын
Thanks a ton Roland!
@rajeshnair8872
@rajeshnair8872 2 жыл бұрын
Rightly said about np. arrange is really helpful Thank you Algo Vibes.
@Algovibes
@Algovibes 2 жыл бұрын
Thanks buddy. Yea it is quite convenient even tho you can also do that with raw python but with a bit more calculation steps.
@yanchobeats
@yanchobeats 2 жыл бұрын
Amazing! Can you feature in your next video how to enter only once per candle even if we get taken out because of stoploss or takeprofit?
@tradingbotspro
@tradingbotspro 2 жыл бұрын
You need just to add additional condition when you are trying to open new position in if statement that there was no sl or tp record in date sell array.
@yanchobeats
@yanchobeats 2 жыл бұрын
@@tradingbotspro Hey, can you drop a few lines on how that might look like, im new to coding :D
@tradingbotspro
@tradingbotspro 2 жыл бұрын
@@yanchobeats i posted msg with explanation but it was not published. Will try again.
@Algovibes
@Algovibes 2 жыл бұрын
Thanks mate. Sorry, maybe I am a bit tired but can you elaborate on your suggestion? Thanks!
@yanchobeats
@yanchobeats 2 жыл бұрын
@@Algovibes Hey mate, I think it would be awesome to show how to enter a trade only once per candle, if you get taken out of that trade because of stoploss or takeprofit, the algo does not re-enter that candle, it has to wait for a new one to form. My algo right now is entering non stop on a candle when it gets taken out, and a entry once per bar no matter what seems great. I have this strategy on tradingview, there i use the "close" function and it works there perfectly, it enters once per bar no matter what. I think that would be greatly beneficial and cool as a strategy for your channel. If you want I can show you some screenshots for more context? Thank you for the great work bro!
@jitkadyan
@jitkadyan 2 жыл бұрын
Another Greate Video , very detailed explain , very thankful for your quick response for considering our suggestion. Sir requesting you to also create a video on martingale system trading application with any trading strategy as most of the strategy not produced continue loosing trade more than 4 so can we apply martingale system on that strategy . pls consider if possible. Thanks for your time and sharing these valuable knowledge with us. Thanks a lot
@Algovibes
@Algovibes 2 жыл бұрын
Thanks a ton and I am extremely grateful for your suggestions man. Always something interesting. I cannot promise anything but I have noted it and will see what I can do.
@rraul
@rraul 2 жыл бұрын
5 stars content 👏👏👏
@Algovibes
@Algovibes 2 жыл бұрын
5 star audience! Thanks a lot rraul
@eliotharreau7627
@eliotharreau7627 2 жыл бұрын
Very nice Bro. Lets try it. Thnx.👌
@Algovibes
@Algovibes 2 жыл бұрын
Thanks mate :-)
@SanjayRaut-l4v
@SanjayRaut-l4v 9 ай бұрын
superb imagetek
@Algovibes
@Algovibes 9 ай бұрын
thx mate :-)
@Satyam1010-N
@Satyam1010-N 2 жыл бұрын
Nice
@Algovibes
@Algovibes 2 жыл бұрын
Thanks buddy
@lorenzobaggi161
@lorenzobaggi161 2 жыл бұрын
top player
@Algovibes
@Algovibes 2 жыл бұрын
😁
@welcometomathy
@welcometomathy 2 жыл бұрын
Last time I did that king of code I got 150/150 Tp/SL long and 1000/350 Tp/SL short xD
@Algovibes
@Algovibes 2 жыл бұрын
What? 😁
@borism4849
@borism4849 2 жыл бұрын
It's called a fragile strategy according to Taleb.
@GeeNee25
@GeeNee25 2 жыл бұрын
Why is it so? Can you explain or give a reference, please?
@borism4849
@borism4849 2 жыл бұрын
@@GeeNee25 With this strategy you make a lot of small gains (1%) but when you lose, you lose big (4%). With this strategy, you have a high probability of making smaller gains and a lower probability of making big losses. If you try this strategy on the SPY during a bear market, you will see that this strategy underperforms massively.
@Algovibes
@Algovibes 2 жыл бұрын
Yep. I would be very cautious with this as well.
@denniscarver9147
@denniscarver9147 2 жыл бұрын
@@borism4849 I think a filter would be helpful in that situation. Something to identify the regime change ( bull to bear). I don't know for sure.
@mrnobody2492
@mrnobody2492 Жыл бұрын
Hast du schon selber einen Trading bot am laufen ? Das muss doch laufen wie sau
@ko-prometheus
@ko-prometheus 2 жыл бұрын
☢☢☢☢☢
@Algovibes
@Algovibes 2 жыл бұрын
😁thx for watching buddy
@vannikuhs674
@vannikuhs674 2 жыл бұрын
Prⓞм𝕠𝕤𝐌
IL'HAN - Qalqam | Official Music Video
03:17
Ilhan Ihsanov
Рет қаралды 700 М.
黑天使只对C罗有感觉#short #angel #clown
00:39
Super Beauty team
Рет қаралды 36 МЛН
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.
How to treat Acne💉
00:31
ISSEI / いっせい
Рет қаралды 108 МЛН
How Financial Firms Actually Make Money
22:40
QuantPy
Рет қаралды 370 М.
Stop Losses in Backtesting.py
27:08
Chad Thackray
Рет қаралды 17 М.
QuantConnect LEAN Algorithmic Trading Engine - Getting Started
46:08
Part Time Larry
Рет қаралды 66 М.
PORTFOLIO THEORY with MATRIX ALGEBRA using Python PART I
19:23
IL'HAN - Qalqam | Official Music Video
03:17
Ilhan Ihsanov
Рет қаралды 700 М.