Selling after X days
Forums › ProRealTime English forum › ProOrder support › Selling after X days
- This topic has 6 replies, 2 voices, and was last updated 5 years ago by
Frank.
-
-
05/06/2020 at 9:43 AM #130181
Hello,
My objective is to set a stop loss which equals the buying price – 1,5*Average Daily Range and a profit target which equals the buying price + 3*Average Daily Range.
I’m considering an Average Daily Range of 7 trading days.
1 candle = 1 trading day
I also want to sell at stop if the opening price equals the closing price, or if nothing happened after 20 days.
This is my code
Buy and sell strategy12345678910111213141516171819202122ADR = Average[7](Dhigh(1)-Dlow(1))// Target and Stop Lossc6 = 1.5*ADRc7 = 3*ADRIF Dclose(0)-c6 THENSELL AT close STOPENDIFIF Dclose(0)+c7 THENSELL AT close LIMITENDIFIF close = open THENSELL AT close STOPENDIFI don’t know if the above code will do exactly what I expect. Also, I don’t know how to code “If nothing happens, sell at limit after 20 days”.
Can anybody help with this one? Thanks!
Frank
05/06/2020 at 10:14 AM #130192Have you read through all the instruction documentation that can be found here?
https://www.prorealcode.com/prorealtime-documentation/
STOP and LIMIT orders are pending orders that you place on the market at each bar to do something at an inferior price or at a better price so you are using them all wrong.
If you calculate your take profit and stop loss levels then you can simply do this:
1234567ADR = Average[7](Dhigh(1)-Dlow(1))sl = 1.5*ADRtp = 3*ADRset stop ploss slset target pprofit tpObviously the sl and tp values will be updated at every new bar so if you want them fixed then set them at the time of entering the market and include them with in a IF NOT ONMARKET condition.
Selling after 20 days is easy. Selling if close equals open is also easy but I can’t imagine this happens very often on a daily chart.
1234if onmarket and ((barindex - tradeindex = 20) or (close = open)) thensell at marketexitshort at marketendif1 user thanked author for this post.
05/06/2020 at 10:48 AM #130201Hi Vonasi,
Thank you very much for the link to the online documentation, I only had the PDF version, this is very handy.
I’m still in doubt with one part of the code. I confirm that I do want to keep the stop loss and the take profit fixed, but it’s still not clear to me how to do it, when you say “set them at the time of entering the market and include them with in a IF NOT ONMARKET condition”, How am I supposed to change the code to make that happen?
1234567ADR = Average[7](Dhigh(1)-Dlow(1))sl = 1.5*ADRtp = 3*ADRset stop ploss slset target pprofit tpMany thanks in advance.
Frank
05/06/2020 at 12:13 PM #1302141234567891011if (your entry conditions) thenbuy 1 contract at marketif not onmarket thenADR = Average[7](Dhigh(1)-Dlow(1))sl = 1.5*ADRtp = 3*ADRendifendifset stop ploss slset target pprofit tp1 user thanked author for this post.
05/06/2020 at 2:36 PM #130241Thank you very much! I stll have one more question (I’m learning…). I’ve tried to incorporate the “not onmarket” condition in the buy conditions rather than in a separate one, and I’m getting different results. I don’t understand why, and which of the 2 cases would be more appropriate for my objective:
1234567891011121314IF (c1 AND c2 AND c3 AND c4 AND c5) AND not daysForbiddenEntry THENBUY 100 SHARES AT MARKETIF NOT ONMARKET THENADR = Average[7](Dhigh(1)-Dlow(1))sl = 1.5*ADRtp = 3*ADRENDIFENDIFset stop ploss slset target pprofit tp123456789101112IF (c1 AND c2 AND c3 AND c4 AND c5) AND not daysForbiddenEntry AND NOT ONMARKET THENBUY 100 SHARES AT MARKETENDIFADR = Average[7](Dhigh(1)-Dlow(1))sl = 1.5*ADRtp = 3*ADRset stop ploss slset target pprofit tpCould you please shed a light on this one? I’m surely missing something here.
Frank
05/06/2020 at 4:01 PM #130268All conditions are checked at the close of a bar. So if you are on market at the close of that bar then that condition is true even if you place an order to close a trade. That stops an entry on the next bar or stops the orders cancelling each other out.
Use DEFPARAM CUMULATEORDERS = FALSE at the top of your first code shown in your last post and that will only ever have one position open at a time but not miss alternate bars due to the ONMARKET condition.
1 user thanked author for this post.
05/06/2020 at 4:08 PM #130271 -
AuthorPosts
Find exclusive trading pro-tools on