exit490

TRAILING STOP LOSS TO LONG AND SHORT

##THIS SCRIPT IS ON GITHUB

This TradingView strategy it is designed to integrate with other strategies with indicators.
It performs a trailing stop loss from entry and exit conditions.
In this strategy you can add conditions for long and short positions.
The strategy will ride up your stop loss when price moviment 1%.
The strategy will close your operation when the market price crossed the stop loss.
Also is possible to select the period that strategy will execute the backtest.
The strategy has the following parameters:

+ **INITIAL STOP LOSS** - Where can isert the value to first stop.
+ **POSITION TYPE** - Where can to select trade position.
+ **BACKTEST PERIOD** - To select range.

## DISCLAIMER

1. I am not licensed financial advisors or broker dealers. I do not tell you when or what to buy or sell. I developed this software which enables you execute manual or automated trades multiple trades using TradingView. The software allows you to set the criteria you want for entering and exiting trades.
2. Do not trade with money you cannot afford to lose.
3. I do not guarantee consistent profits or that anyone can make money with no effort. And I am not selling the holy grail.
4. Every system can have winning and losing streaks.
5. Money management plays a large role in the results of your trading. For example: lot size, account size, broker leverage, and broker margin call rules all have an effect on results. Also, your Take Profit and Stop Loss settings for individual pair trades and for overall account equity have a major impact on results. If you are new to trading and do not understand these items, then I recommend you seek education materials to further your knowledge.

**YOU NEED TO FIND AND USE THE TRADING SYSTEM THAT WORKS BEST FOR YOU AND YOUR TRADING TOLERANCE.**

**I HAVE PROVIDED NOTHING MORE THAN A TOOL WITH OPTIONS FOR YOU TO TRADE WITH THIS PROGRAM ON TRADINGVIEW.**

## NOTE

I accept suggestions to improve the script.

If you encounter any problems I will be happy to share with me.

+ Authors: @exit490
+ Revision: v1.0.0
+ Date: 03-Aug-2019
+ Pinescript version: 4

## LICENSE

Copyright 2019 Mauricio Pimenta / exit490

Trailing Stop Loss script may be freely distributed under the MIT license.
Von Favorisierten Skripten entfernen Zu Favorisierten Skripten hinzufügen

Kommentare

Really sorry being a little dumb... can you give an example of how to add a long and short condition to your script...
+4 Antworten
revertingtower DannyBaker
@DannyBaker, not sure if you've solved this?

You'll need to convert this into a Study.

I've added additional conditions to the existing SHORT / LONG logic ; I've done this to match another indicator that I've developed. I have a plot from my indicator that I use to detect crossover / crossunder with the plots provided in this script. I changed the last two lines here to plot() as that worked better for my use.

For me my alerts are driven by:

alertcondition((crossedStopLoss or hasCloseLongConditional), title='Trend Down', message='XXX')
alertcondition(hasEntryLongConditional(), title='Trend Up', message='XXX)

I've been using this for the past couple of days and it's been working well.
Antworten
ZuzarLakdawala revertingtower
@revertingtower, Either it only triggers Long or Short based on the setting. What if we want to go both way.
+2 Antworten
I created a script which is working flawlessly on Tradingview so I wanted to create alert notifications. Buy order is coming after certain conditions get satisfied and I'm creating an alert through alertcondition() function, as follows

//Buy Condition
Buy = condition1 and condition2 and testrange
alertcondition(Buy, title = "Buy Signal", message = "Buy Signal Alert")

I'm stuck in the sell order alert notification as I'm using strategy.exit() which has stop, trail_points and trail_offset. So the strategy either hits stop-loss or it starts trailing from a certain percentage with an offset.

//Exit Strategy
strategy.exit("TP/SL", "Enter Long", stop=StopLoss * (1 - sl_inp),
trail_points = close * TrailPer / syminfo.mintick,
trail_offset = close * TrailOffset / syminfo.mintick)

I can't use alertfunction() here as the trailing stoploss and offset are both defined in strategy.exit function. Your above strategy trails at 1% stoploss but doesn't have an offset, how can I modify it so that after a certain percentage (trail_points) it starts to trail with an offset (trail_offset).

Any help will be greatly appreciated! Thanks!
+3 Antworten
This really works great, exactly what I was looking for. It trails the stop and never adjusts it downward until it is hit.
Thanks!
+1 Antworten
what about lines 169 and 202? shouldn't them be like that? "updatedEntryPrice = close"
Antworten
asterisco asterisco
Since positions are taken the next day after conditions are met, it doesn't work at all.
Antworten
SuiteSociety asterisco
@asterisco,
Hi, I agree with you.
I edited the script using "updatedentryprice: = close"

If you don't use this formula, the strategy doesn't make any sense hahahaha
Antworten
Can any one help me to get the stop loss for short entry and close short , long is working fine, but i'm stuck on shot entry and exit .
Antworten
This works either on Long side or Short side ... not both ...
Antworten
Startseite Aktien-Screener Forex-Screener Krypto-Screener Wirtschaftskalender So funktioniert es! Chartmerkmale Preise Einen Freund empfehlen Hausregeln Hilfe Center Webseite & Brokerlösungen Widgets Charting Lösungen Lightweight Charting Library Blog & News Twitter
Profil Profileinstellungen Konto und Abrechnung Angeworbene Freunde Coins Meine Support Tickets Hilfe Center Veröffentlichte Ideen Followers Ich folge Private Nachrichten Chat Abmelden