Set stoploss with percentage
Forums › ProRealTime English forum › ProOrder support › Set stoploss with percentage
- This topic has 4 replies, 2 voices, and was last updated 5 years ago by
Vonasi.
-
-
01/09/2020 at 8:34 PM #116338
Hi,
I have this code before,
https://www.prorealcode.com/topic/rsi-automated-buy-and-sell-request/But would like to develop a stop loss function with this. I want it to buy when it buys, but I want that if I lose more than 0.3% then I want to sell, just as security, otherwise I want to sell at the highest similar to what the code shows, in this case: if onmarket and myrsi > 70 then sell at market
rsi-automated-buy-and-sell-request1234567891011defparamcumulate orders = falsemyrsi = rsi[14]if myrsi < 30 thenbuy 1 contract at marketendifif onmarket and myrsi > 70 thensell at marketendif1 user thanked author for this post.
01/09/2020 at 10:05 PM #116342k3rex – Your topic has been moved to the ProOrder forums which are for automated strategy topics. You posted in the ProBuilder forum which is for indicator topics. Please try to ensure that you post in the correct forum with future topics.
01/09/2020 at 10:10 PM #116343Just add:
1set stop %loss 0.3to the bottom of the strategy and it will sell when price hits 0.3% below your buy price.
Alternatively you can add:
123if onmarket and close <= positionprice * 0.997 thensell at marketendifand it will sell at the close of any candle that closes 0.3% or more lower than your buy price.
You should check that 0.3% is not too close to price as your broker will have a minimum stop distance and reject any order that is too close and possibly stop your strategy. You can use use MAX to try to ensure that no order is sent that is too close although sometimes brokers can add a big spread and a big minimum stop distance during high volatility so this is not totally foolproof.
For example if the minimum stop distance is 5 then the following will ensure that the 0.3% order is never closer than 5.
123456minstopdistance = 5minstopperc = (minstopdistance/close)*100mystop = max(minstopperc, 0.3)set stop %loss mystop1 user thanked author for this post.
01/12/2020 at 8:08 PM #116539Thank you, it is possible to do the opposite too? When
if onmarket and myrsi > 70 thensell at marketand then make an short position? So when the short position hit :if myrsi < 30 thenbuy 1 contract at marketendifI mean the RSI 30-level and then sell it? Like it goes around like a circle.So what I mean is, when you reach the 70 level, then it becomes a short position and it sold when you reach the 30 level, and at the 30 level you buy and sell at the 70 level, and of course 0.3% stop loss function is inserted so you do not lose any capital.01/12/2020 at 10:29 PM #11656312345678910111213defparamcumulate orders = falsemyrsi = rsi[14]if myrsi < 30 thenbuy 1 contract at marketendifif onmarket and myrsi > 70 thensellshort 1 contract at marketendifset stop %loss 0.31 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on