Fixed Percent Stop Loss & Take Profit %

Fixed Percent Stop Loss & Take Profit %

A neat example of how to set up Fixed Stops and Take Profit as a percent of the entry price.
Yup, that's about it!

You can ignore the actual entry/exit orders - they're based on a simple MA cross and are therefore NOT relevant, NOT really profitable and NOT recommended!

You should be using this code as a way of adding Stops and Takes to your own scripts - hope it helps!


Good Luck and Happy Trading!
Favori Komutlardan Çıkart Favori Komutlara Ekle
> Full Access on our website. 7-Day Free Trial. Crypto Tipster & Crypto Scalper Strategies. Stunning Past Performance


Hi There,
Thanks @theCrypster for the great work!
Short Q to whomever can answer - check of example the list of trades in this example page.
You will see a loss lager then the SL.. what am i missing here?

Cevap Gönder
@eladlevi, Hey, Thanks for the response. I'm sorry I don't understand your question!

This may provide useful - If the bar is still active when the SL gets hit, the SL signal won't display the "correct" SL price until that bar has closed. It will display the SL at the current price, and every time you update the chart it will update with the new "current" price. So, only once the bar has closed the SL will update to the correct position and your strategy back-test will provide accurate SL info.

Hope that helps you. Let us know!
Cevap Gönder
eladlevi theCrypster
Thanks for replying back. I’ll try to be specific.
I can see trades that had loss more than the SL.
(In the back test trades list).
The question is - Why is that?
And can we get it to stop at this price and not loss more than what was defined?

Thanks again
Cevap Gönder
@eladlevi, Oh I see - Now we've dug a little deeper I can see two things going on here. One doesn't matter and can be explained easily, the other would require a fix. (I think we've got one, too!)

So, the first "issue" (it's not an issue, really) is that when you are Long, but a signal (like the MA Cross in the example), shows a Short, it would obviously close the Long trade and enter the Short. So, you might only have 5% of your 10% TP target. This is why some trades are exited at BELOW value.

The actual problem/bug that we need to resolve is when you enter a trade and the price moves in the wrong direction immediately (on the same bar). This code will currently only fix your SL/TP in position after the trade entry bar has closed. So we'd need to enter at the bar close of the previous bar, not the open price of the current bar.

Does that make any sense! (?)

Try this:
Right at the top of your script within the "Strategy" tag, add this:

>>>>>>> process_orders_on_close=true <<<<<<<

That should now open any trades at the close of whichever bar signals the trade, rather than plotting it at the open price of the next bar. This in turn then means the SL/TP values should be confirmed and awaiting a "hit" as soon as the next bar opens! I think...

Try it out and Please Please Please let us know how it goes! :D

Thanks for spotting that one, I love this community!
+1 Cevap Gönder
eladlevi theCrypster
@theCrypster, yep 👍🏻 now I got your points!
Will give it a try!
(Suggest to fix it in this strategy as well).
Love this community as well!

Cevap Gönder
@eladlevi, Awesome, we're updating and testing the new version now!
Cevap Gönder
eladlevi theCrypster
@theCrypster, tried it now, had cases where there is a miss.
check out the following use case:
Using Days candles - entry price 100 --> SL of 5% will target 95.
Now... during the off market, the price now drops bellow 95(!), e.g the new day starts with prince of 80.
The strategy will close at 80.
As I'm new to trading I wonder if such case can happen in *real life* trades
(not only in testing and back testing.. means that although I gave a stop loss order, there are cases that
I will get a bigger hit.. )

Appreciated your help and answering!
Cevap Gönder
@eladlevi, Hmm that's a good question! This article is brief but covers most of what you're asking:

I can't easily see a fix for the "next bar SL/TP not hit" issue at the moment - give us some time and we'll get back to you on that one!

Thanks again, this has been fun! :)
Cevap Gönder
Hi mate, is there any chance I can get this set up for a Study script? I want to be able to draw my SL/TP lines, while only on a study script. (so i can use alerts and send to my trading bots etc)

Cevap Gönder
Ana Sayfa Hisse Senedi Takipçisi Forex Takipçisi Kripto Takipçisi Ekonomik Takvim Nasıl Çalışır Grafik Özellikleri Ücretlendirme Tanıdık yönlendirme Kurallarımız Destek Merkezi Web Sitesi & Aracı Kurum Çözümleri Görsel Bileşenler(Widget) Grafik Çözümleri Hafif Grafik Kitaplığı Blog ve Haberler Twitter
Profil Profil Ayarları Hesap ve Ödemeler Tanıdık yönlendirme Destek Kayıtlarım Destek Merkezi Yayınlanmış Fikirler Takip Edenler Takip ediliyor Özel Mesajlar Sohbet Çıkış