Supertrend stop loss
Forums › ProRealTime English forum › ProOrder support › Supertrend stop loss
- This topic has 12 replies, 4 voices, and was last updated 1 year ago by SVK.
-
-
07/15/2023 at 3:01 PM #217693
Hi all,
again I have run out of talent so I’m turning to you knowledgable guys for help.
I’m trying to create stop loss based on supertrend indicator.
Long condition can be executed once bar closes above Supertrend 2 – 11 or Supertrend 3 – 12.
If long is executed at Supertrend 2 – 11 then stop loss needs to be placed at 2 -11.
If long is executed at Supertrend 3 – 12 then stop loss needs to be placed at 3 -12.
I have run the strategy with folowing code:
123456789IF NOT shortOnMarket and Trigger AND CondiLong1 and CondiLong2 AND TradingON THENBUY 1 PERPOINT AT MARKETStopInd = close-SuperTrend[3,12]ENDIF// Stops and targetsSET STOP pLOSS StopIndSET TARGET pPROFIT StopInd *1.6Problem is that Supertrend 3 – 12 is not always below the bar close so I have caught a trade with no stop loss set 🙁
Would anyone know how to code this for Long and Short trading please ?
Thank you very much for the help
07/16/2023 at 11:11 AM #217710What do you want to happen if the supertrend is bigger than the close?
The code below catches such cases and sets the stoploss to 30 points.
123456789101112IF NOT shortOnMarket and Trigger AND CondiLong1 and CondiLong2 AND TradingON THENBUY 1 PERPOINT AT MARKETStopInd = close-SuperTrend[3,12]ENDIFIf Stopind < 0 thenStopind = 30Endif// Stops and targetsSET STOP pLOSS StopIndSET TARGET pPROFIT StopInd *1.61 user thanked author for this post.
07/16/2023 at 4:28 PM #217720Hi ProrealAlgos,
many thanks for your response.
I was thinking of having two options for stop loss.
StopInd 1 = close–SuperTrend[3,12]
StopInd 2 = close–SuperTrend[2,11]
If trade is executed and SuperTrend[3,12] is above Close then Stop loss is placed at SuperTrend[2,11] level.
If trade is executed and SuperTrend[3,12] is below Close then Stop loss is placed at SuperTrend[3,12] level.
07/17/2023 at 10:06 AM #217730If trade is executed and SuperTrend[3,12] is above Close then Stop loss is placed at SuperTrend[2,11] level. If trade is executed and SuperTrend[3,12] is below Close then Stop loss is placed at SuperTrend[3,12] level.
Find below the code to achieve this:
12345if SuperTrend[3,12]>close thenset stop price SuperTrend[2,11]elseset stop price SuperTrend[3,12]endif1 user thanked author for this post.
07/17/2023 at 11:16 PM #2177971Nicolas,
thank you very much for your help.
Unfortunately I must be doing something wrong as it doesn’t work.
I have insrted your code like this:
123456789//IF NOT shortOnMarket and Trigger AND CondiLong1 and CondiLong2 AND TradingON and DayLimit THENBUY 1 PERPOINT AT MARKETif SuperTrend[3,12]>close thenset stop price SuperTrend[2,11]elseset stop price SuperTrend[3,12]endifENDIFThis way code just keeps following Supertrend and doesn’t place stop loss at the trigger bar.
07/18/2023 at 9:40 AM #217809Because you have wrongly coded the conditions, the IF statement is entered and therefore the stoploss is updated with the SET STOP PRICE instruction.
Replace
IF NOT shortOnMarket
with
IF NOT longOnMarket
1 user thanked author for this post.
07/18/2023 at 6:12 PM #21784407/18/2023 at 6:27 PM #21784807/18/2023 at 7:09 PM #217851Thank you very much Grahal.
Now I’m trying to figure out how to place profit target at *1.5 of a set stop price.
So far 1 hour and 7 minutes and I’m nowhere. LOL
123456789//IF NOT longOnMarket and Trigger AND CondiLong1 and CondiLong2 AND TradingON and DayLimit THENBUY 1 PERPOINT AT MARKETif SuperTrend[3,12]>close thenset stop price SuperTrend[2,11]elseset stop price SuperTrend[3,12]endifENDIF07/18/2023 at 8:46 PM #217853Yes coding is very time consuming, especially if at the end of a few hours there isn’t a working result!
Have you tried below …
set stop price (SuperTrend[2,11] + (0.5*SuperTrend[2,11]))
But do you really mean 1.5*Price anyway? Taking DJI at 35,000 this gives 52,500 for 1.5*Price??
1 user thanked author for this post.
07/18/2023 at 9:04 PM #21785407/18/2023 at 9:16 PM #217855Ah right gotcha, sorry watching a film at same time so not concentrating.
How about below …
123456789IF NOT longOnMarket and Trigger AND CondiLong1 and CondiLong2 AND TradingON and DayLimit THENBUY 1 PERPOINT AT MARKETif SuperTrend[3,12]>close thenset stop price SuperTrend[2,11]elseset stop price SuperTrend[3,12]Set Target Price (Close + ((Close - SuperTrend[2,11]) *1.5))endifENDIF1 user thanked author for this post.
07/19/2023 at 2:20 PM #217874 -
AuthorPosts
Find exclusive trading pro-tools on