Create Stop Loss and Take profit for your Backtest in Tradingview Pinescript

แชร์
ฝัง
  • เผยแพร่เมื่อ 10 มิ.ย. 2021
  • The full code is in the link below if you wish to copy paste.
    www.quantprogram.com/StopLoss...
    In this video I show you how to create the stoploss and takeprofit in percentage terms in pine script Trading view.
    Let us know if you have any questions. HAPPY TO HELP.
    Check out our channel for more backtesting and strategy videos.
    Backtesting Pullback Strategy Pinecript: • Pullback Strategy Back...
    Stan Weinstein Strategy Pinecript code: • Stan Weinstein's Tradi...
    Create Stop Loss Take Profit Code: • Create Stop Loss and T...
    Creating Trailing stop Loss in Tradingview Pinescript: • Trailing Stop Loss Cod...
    RSI divergence Pinescript code: • RSI Divergence Pinescr...
    Donchian Breakout Pinescript Code: • Donchian Channel Break...
    Inside day Strategy Pinescript Code: • Backtesting Inside da...
    Bullish Engulfing Strategy Pinescript Code: • BACKTESTING Candlestic...
    Disclaimer: The contents provided in the channel are purely educational. We do not provide any financial or investment advice. There is a very high degree of risk involved in trading. Past results are not indicative of future returns. quantprogram.com and all individuals affiliated with this site assume no responsibilities for your trading and investment results. The contents, videos, columns, articles and all other features are for educational purposes only and should not be construed as investment advice.

ความคิดเห็น • 67

  • @InspireWave518
    @InspireWave518 ปีที่แล้ว

    Extremely helpful, Thank you so much

  • @artursspiridonovs4771
    @artursspiridonovs4771 2 ปีที่แล้ว +6

    Very good videos, surprisingly straight to the point and informative!

  • @malkashmiri
    @malkashmiri 2 ปีที่แล้ว

    great Vid very helpful, thank you

  • @tele2662
    @tele2662 2 ปีที่แล้ว

    Thank you, nice video.

  • @teleskop9687
    @teleskop9687 ปีที่แล้ว

    Thanks a lot

  • @PradeepKumar-dz8yz
    @PradeepKumar-dz8yz 2 ปีที่แล้ว

    great video please make a video for macd strategy

  • @tradeking08
    @tradeking08 ปีที่แล้ว

    brother can you please automate this strategy in paper trading of tradingview ? so we can check in live market. is it possible to do automate?

  • @yekmang
    @yekmang 5 หลายเดือนก่อน

    hi, do you know how to make sure the order size of the TV tally with exchange order size? i cant manage to tally the order size. its very confusing to me. thanks in advance

  • @fudailayham1281
    @fudailayham1281 2 ปีที่แล้ว +3

    This is the video I was looking for and it was informative. Thank you for your efforts:)

    • @quantprogram
      @quantprogram  2 ปีที่แล้ว

      Thanks much for the comment mate. Appreciate it

    • @fudailayham1281
      @fudailayham1281 2 ปีที่แล้ว

      @@quantprogram hey is it possible to store a candles data(high, low, open, close) to a variable and make it constant? For eg. I want the entry candle's data set unchanged for my stoploss logic depends on that candle prices

    • @quantprogram
      @quantprogram  2 ปีที่แล้ว

      Hi mate, i think there is a way but i haven't tried it from my end. The logic will be to store that high/low./open or close to a variable and then create an if else or for loop and state that if the variable is different then the old variable is new variable. You can store the old variable as an array.
      There might be an easier way to do it. Worth the search

  • @apogounte8239
    @apogounte8239 2 หลายเดือนก่อน

    nice video! can u provide the equivalent for trading view version 5?

  • @MrBombayDude
    @MrBombayDude ปีที่แล้ว

    Great video thank you. Is there anyway to incorporate in this strategy where you move the SL to breakeven once the profit increases by 5 %. In other words, any way to back test where you making the SL dynamic and changing it to break even once a certain profit is achieved?

    • @quantprogram
      @quantprogram  ปีที่แล้ว

      Yes you can!, But will involve some complex coding. You'll need to add an if else statement stating if the close is >5%, SL is adjusted, and then you have to make this sl constant which is the tricky part. Youll have to put the entire thing on a loop

  • @songchiu6439
    @songchiu6439 2 ปีที่แล้ว

    Your video helps me a lot, thank you❤️
    By the way, how if I don't want the system help me close automatically, I just want when it hit TP or SL then only close trade, is it possible to do this? If yes, what's is the code😂

  • @wadders1988
    @wadders1988 11 หลายเดือนก่อน

    Great video, thank you!! ... I was wondering if the SL & TP could be configured to pips?

    • @wadders1988
      @wadders1988 11 หลายเดือนก่อน

      Nevermind, figured it out, strategy.exit(id = "Close", loss = 100, profit = 200)
      Thank you for the video it has helped me a lot!!

    • @balrajpillai
      @balrajpillai 3 หลายเดือนก่อน

      hey bro, is this in pips or pip points?@@wadders1988

  • @mattc4153
    @mattc4153 ปีที่แล้ว

    Thanks great video. Is there a way to run a strategy against say the entire S&P or a group of symbols?

    • @quantprogram
      @quantprogram  ปีที่แล้ว +1

      No mate. Not on tradingview platform. Tradingview at the end of the day is a charting platform, its not meant for quants.If you want to do portfolio backtesting and position sizing based tests the recommended platforms are Amibroker or python

  • @JustinJaeger
    @JustinJaeger หลายเดือนก่อน

    Great video! But my problem is that the alert only triggers after candle close, which makes my strategy not porfitable anmore... Is there a way to trigger alerts real time?

    • @quantprogram
      @quantprogram  หลายเดือนก่อน

      Thanks for the comment. It’s not theoretically possible. There’s no real time per se. When I say do something now and I do it. Time has already passed. There will be a delay of certain seconds. The now has passed and is now in the past . There will be a delay in action. Same applies to coding. When you code something there has to be a measure on where it can be checked. Is it checked every second, every 30 seconds etc. without this specific check nothing can be coded to action. So when the code is done for daily chart, to check if certain conditions are met, the order will only be filled when the market opens next day as now you have got the data from the previous day. This is same if it’s a daily chart or even a high frequency trading environment. There will always be a delay because code is involved and conditions have to be checked.

  • @silenttrader1606
    @silenttrader1606 ปีที่แล้ว

    Thanks, how should I write to close long position when short position is open. I'm testing a strategy, while long position is open if the price hit to my stoploss or target it close the long position , but when a new short position is open (or triggered) the long position is still open , so I have both long position and short position. Is it posible to close my long position such three situation stoploss, target and when short position is open. Thanks

    • @quantprogram
      @quantprogram  ปีที่แล้ว +1

      There is a conflict here mate. You cant have a long position and short position simultaneously. Then your'e net position is 0. Even if you have 2 contract long and 1 short position. Then you're net position is 1 long.

  • @shaddyghazal8255
    @shaddyghazal8255 ปีที่แล้ว

    hey bro, can you add a section about coding the user inputs so that you don't have to go to the code every time to change the tp and sl?

    • @quantprogram
      @quantprogram  ปีที่แล้ว

      thats pretty simple mate, you can use the input function and assignt he variapble and then make adjustments to SL and TP in the settings rather than changing code all the time

  • @pasht60
    @pasht60 ปีที่แล้ว +1

    Is possible to set the stop loss at the low of the previous candle (before we enter the trade) ?

  • @restrella520
    @restrella520 11 หลายเดือนก่อน +1

    How can you place a stop below the last swing low of the last seven candles before entry?. I have last_swing_low = ta.lowest(close,7). But the problem is that after it executes the trade, the stop loss is moving to the low of the most recent 7 candles, when it is supposed to be at the low of the 7 most recent candles before the entry, and then reset after the trade closes. Can you please help me with that?

    • @restrella520
      @restrella520 11 หลายเดือนก่อน +1

      I also tried last_swing_low = ta.lowest(close, (7 + ta.barssince(entry condition)))

  • @cemosir111
    @cemosir111 ปีที่แล้ว

    hey, can you show it on an indicator not strategy ? and also is it possible to make it not by percentage but the difference with the last swing low/high and 1:2 ratio take profit level ? would be perfect! nobody has ever shared sth like that. This video is also great job btw, thanks

    • @hamzaserrar4234
      @hamzaserrar4234 ปีที่แล้ว

      I was looking for the thing ... Did you find something ??

    • @cemosir111
      @cemosir111 ปีที่แล้ว

      @@hamzaserrar4234 i coded it myself

    • @hamzaserrar4234
      @hamzaserrar4234 ปีที่แล้ว

      Is it possible to share it if you dont mind ? Thnx

    • @mikeg8343
      @mikeg8343 ปีที่แล้ว +2

      @@cemosir111 imagine replying this and not sharing

  • @jaytav001
    @jaytav001 2 ปีที่แล้ว +1

    Nicely explained. Just 1 query,
    How to set conditional Target and SL?
    I don't want to exit for 1 st 15 minutes of the day. So my exit should get activated after 1st 15 minutes.
    I tried exit with in IF condition, but it's not working.
    Need help!

    • @quantprogram
      @quantprogram  2 ปีที่แล้ว +1

      That might be a bit tricky mate. I know how to exit post n bars, but this one is quite specific and complicated, will let you know if i find it somewhere

  • @p1nkpanther825
    @p1nkpanther825 3 หลายเดือนก่อน

    I have a strategy where both entry and exit should be done on the same candle, but it closes the exit at the candle after entry can u plz help me ?

    • @quantprogram
      @quantprogram  3 หลายเดือนก่อน

      you cant enter and exit at the same candle. You can enter at the open and exit at the open of the next candle

  • @cookiemonster6649
    @cookiemonster6649 2 ปีที่แล้ว

    I coded the TP and SL just like you, but when my strategy opens a short it doesn't close it according to my set SL and TP, but instead just closes when the next Longsignal comes.
    The Longs close perfectly by my SL and TP
    Do you know what could be the error?

    • @quantprogram
      @quantprogram  2 ปีที่แล้ว +1

      I wont be able to know unless i see the entirety of the code, but most likely this will be a small minor error somewhere. My suggestion would be to code just the short entry alone and exclude the entire code for the long entry and see whether it works. In this way you can breakdown the code and see if the short side is working. Once that is sorted, then you can combine both long and short.
      The other reason why it might not work is that long signal is created before the existing short position either hits a SL or TP. In this case the problem is in more of the way you code. You should create another if else statement to state that IF we are already in a short position then DONT create a long position and vice versa. In that way the opposite signal wont be generated and the opposite trade wont be executed unless SL or TP is hit

    • @cookiemonster6649
      @cookiemonster6649 2 ปีที่แล้ว

      @@quantprogram Thank you very much for answering so quick. I will try this

    • @quantprogram
      @quantprogram  2 ปีที่แล้ว

      @@cookiemonster6649 Your'e welcome mate

  • @jack_sparrow1049
    @jack_sparrow1049 3 ปีที่แล้ว

    how to take 1:2 take profit while using supertrend as stoploss. i mean how to code that can you do it

    • @quantprogram
      @quantprogram  3 ปีที่แล้ว

      Can be done. But it's a bit of work. Contact quantprogram@gmail.com if your'e interested

    • @BulentOner
      @BulentOner 2 ปีที่แล้ว

      Supertrend is a simple function which is return direction and supertrend value. You can use supertrend value as a stoploss value at strategy exit. Take profit is the same logic 2 times supertren with other direction as a limit. Thats my opinion.

  • @philjoseph6997
    @philjoseph6997 ปีที่แล้ว

    Hey mate, is it possible for this to be done with two separate strategy.exit() statements, whereby one is for the TP and another for the SL ? i.e.
    strategy.exit("Long TP", from_entry = "OWR Long", limit = longProfit, comment = "TP (Long)")
    strategy.exit("Long SL", from_entry = "OWR Long", stop = longStop, comment = "SL (Long)")

    • @quantprogram
      @quantprogram  ปีที่แล้ว

      Worth a try. See what you get

  • @delmartaylor7122
    @delmartaylor7122 3 ปีที่แล้ว +1

    Can I pay you to code my system?

    • @quantprogram
      @quantprogram  3 ปีที่แล้ว +7

      Hi Delmar,
      You can , but i personally think it's unnecessary. It's like the "learning how to fish" vs "give me this fish" discussion. Your system can have more performance or might not work well, in that case you'll have to hire the coder again to tweak the system or create a new system which adds more cost. You will be in that vicious cycle.
      Learning how to code trading strategies is not that hard mate. You can create 1000's of systems and tweak it whenever & however you want. I would really recommend checking out the course in our website. You will learn how to code systems with no coding experience. Theres 8 different strategies that has beaten the market within the course as well. You will be up and running as a quantitative trader in less than a week.
      I can get you a discount if you fancy. Contact us at info@quantprogram.com

    • @nisharsadick5180
      @nisharsadick5180 3 ปีที่แล้ว

      @@quantprogram your motive is very good. Keep it up.

    • @dianaheijman
      @dianaheijman 2 ปีที่แล้ว +2

      Hi Delmar, I can only agree with QuantProgram here. Learning Pine Script really opens so many doors. It's one of the easiest script languages out there (I'm not a coder myself), and once you slightly get the hang of it, it is very motivating to learn more because you can tweak your strategies exactly how you want them to be. It may seem daunting in the beginning, but after a bit of experimenting, trying out example strategies, perhaps do a course, you'll be on a roll :)

    • @zaildarbains
      @zaildarbains 2 ปีที่แล้ว +1

      @@dianaheijman yea but time is money😄

    • @minhdzung
      @minhdzung 3 หลายเดือนก่อน

      @@zaildarbainsdamn right! 👍

  • @officialgc...goldcoastmusi8608
    @officialgc...goldcoastmusi8608 2 ปีที่แล้ว +1

    Hello, great stuff. i want you to help me with this 1) i want to place a buy or sell order when a condition is met (2) in this buy/sell order i want to indicate the take profit and the stop loss too as i set the buy or sell order. (3) After the order is placed, i want to set a condition which invalidates the buy/sell order and hence cancels the order. i tried something like this with no luck if (thelongmove)
    sl=low[2]
    entry=high[1]
    tp=high[1]
    strategy.entry("long1", true,qty=1,stop=sl,limit=tp,when=high==entry,comment="thelong1")
    if (theshortmove)
    sl1=high[2]
    entry1=low[1]
    tp1=low[1]
    strategy.entry("short1", false,qty=1,stop=sl1,limit=tp1,when = low==entry1,comment="theshort1")

    • @quantprogram
      @quantprogram  2 ปีที่แล้ว +2

      Hi, I believe there is a multiple areas in the code which is contradictory to what you want. I can advice you to our tech team which could create the code for you at a specific fee. Please email quantprogram@gmail.com for more details.

  • @quantprogram
    @quantprogram  2 ปีที่แล้ว +1

    The full code is in the link below if you wish to copy paste.
    www.quantprogram.com/StopLossPinescript
    Contact us at quantprogram@gmail.com if you need additional help