Help with a condition
Forums › ProRealTime English forum › ProOrder support › Help with a condition
- This topic has 28 replies, 6 voices, and was last updated 6 years ago by
GraHal.
-
-
08/26/2018 at 7:14 AM #79071
Hi friends,
I’m working in an automated strategy but I’m having problems with an issue.
I would like to make entries only under a condition. I would like to open shorts when last RSI min. value was between two values, and open longs when last RSI max was between another two values.
I’ve got it defining a N bars number, but I don’t want to use the bars number. I think it may be solved using ONCE or WHILE instructions but I can’t find the way.
My code now is as following:
Open longs:
1c7 = ((lowest[20](RSI)) < 20) and ((highest[RSINUMBARS](RSI)) < 80)Open shorts:
1c17 = ((highest[20](RSI)) > 80) and ((lowest[RSINUMBARS](RSI)) > 20)But I would like to obviate the [20] bars value using something similar to
1while ((highest[20](RSI)) > 80) and ((lowest[RSINUMBARS](RSI)) > 20) do ...I tried wih ONCE too but didn’t work.
Could you guide me to find a solution?
Thanks to all the community.
08/26/2018 at 8:27 AM #79074If you post your full code then I / we could easily run it on our Platforms and it then easier to offer help rather than us having to make above into a working System to check it out.
If you not want to share your full code then I guess some expert coder may spot an anomaly and / or offer suggestions?
08/26/2018 at 8:33 AM #79075I’m not sure I fully understand your problem.
First of all you need to give your RSI’s a period. For example:
1RSI[14]Why not use a simple IF THEN ENDIF?
123if ((highest[20](RSI[14])) > 80) and ((lowest[RSINUMBARS](RSI[14])) > 20) then(whatever you want to do)endifThe code is read through once at the close of a candle and if your condition of looking back for the lowest RSI and highest RSI over your look back periods is met then whatever you want to do is carried out.
The ONCE instruction means that whatever is written after it is only read at the close of the very first candle and ignored every candle after that.
08/26/2018 at 8:46 AM #79076Hi GraHal of course. Also I’ve been all night working on it and I changed a few things to enhance it.
Basically I change RSI by RSX and results are much better now. However code is a bit frankenstein…don’t laugh please 🙂
It’s for DAX M1 and my main question is how to avoid RSXBARS for no limiting trades at that certain vars number. I spent much hours testing with WHILE and ONCE but I can’t solve it.
Also, any other idea to enchance strategy is welcome 🙂
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222//-------------------------------------------------------------------------// Código principal : CH - 1M - TR - STO//-------------------------------------------------------------------------/// Definition of code parametersdefparam preloadbars = 500DEFPARAM FlatBefore = 101000DEFPARAM FlatAfter = 172500daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0// INICIO RSXLen=RSXLENif (f90 = 0.0) thenf90 = 1.0f0 = 0.0if (Len-1 >= 5) thenf88 = Len-1.0elsef88 = 5.0endiff8 = 100.0*(Close)f18 = 3.0 / (Len + 2.0)f20 = 1.0 - f18elseif (f88 <= f90) thenf90 = f88 + 1elsef90 = f90 + 1endiff10 = f8f8 = 100*Closev8 = f8 - f10f28 = f20 * f28 + f18 * v8f30 = f18 * f28 + f20 * f30vC = f28 * 1.5 - f30 * 0.5f38 = f20 * f38 + f18 * vCf40 = f18 * f38 + f20 * f40v10 = f38 * 1.5 - f40 * 0.5f48 = f20 * f48 + f18 * v10f50 = f18 * f48 + f20 * f50v14 = f48 * 1.5 - f50 * 0.5f58 = f20 * f58 + f18 * Abs(v8)f60 = f18 * f58 + f20 * f60v18 = f58 * 1.5 - f60 * 0.5f68 = f20 * f68 + f18 * v18f70 = f18 * f68 + f20 * f70v1C = f68 * 1.5 - f70 * 0.5f78 = f20 * f78 + f18 * v1Cf80 = f18 * f78 + f20 * f80v20 = f78 * 1.5 - f80 * 0.5if ((f88 >= f90) and (f8 <> f10)) thenf0 = 1.0endifif ((f88 = f90) and (f0 = 0.0)) thenf90 = 0.0endifendifif ((f88 < f90) and (v20 > 0.0000000001)) thenv4 = (v14 / v20 + 1.0) * 50.0if (v4 > 100.0) thenv4 = 100.0endifif (v4 < 0.0) thenv4 = 0.0endifelsev4 = 50.0endif// FIN RSX// General conditionsRSX=v4RSXLEN = 14 // 34 //12RSXVARMIN = 28 // 31 //26RSXVARMAX = 64 //62 //66RSXBARS = 24 //33 //24// Conditions longSTOL = Stochastic[204,4]STOOVERL = 25STOUNDERL = 60STOMANTAINL = 89ATRPROFITL = AverageTrueRange[5] //50 //AverageTrueRange[5]ATRPROFITMULTL = 5 //1 //4.7ATRRISKL = AverageTrueRange[10]ATRRISKMULTL = 3.8 //3.5MAPROFITAVGL = 14BBPROFITSTDAVGL = 15//RSXL = RSX// Conditions shortSTOS = Stochastic[199,2]STOOVERS = 70STOUNDERS = 83STOMANTAINS = 6ATRPROFITS = AverageTrueRange[10]ATRPROFITMULTS = 4.6ATRRISKS = AverageTrueRange[4]ATRRISKMULTS = 4.4MAPROFITAVGS = 15BBPROFITSTDAVGS = 18//RSXS = RSXonce RRreached = 0profitpipsl = ATRPROFITL*ATRPROFITMULTL // 0.1 * var:30-60 4.9riskpipsl = ATRRISKL*ATRRISKMULTL //risk in pipsamountl = 1 //lot amount to open each tradesdl = 0.17 //standard deviation of MA floating profit - orig: 0.25profitpipss = ATRPROFITS*ATRPROFITMULTS // 0.1 * var:30-60 4.6riskpipss = ATRRISKS*ATRRISKMULTS //whole account risk in percent%amounts = 1 //lot amount to open each tradesds = 0.17 //standard deviation of MA floating profit - orig: 0.25// Conditions to enter long positionsc3 = (STOL > STOOVERL) // 20c4 = (STOL < STOUNDERL) // 40c5 = (STOL > STOL[1]) // and (STOL[1] < STOL[2])c6 = (RSX > RSX[1]) and (RSX > RSXVARMIN)c7 = ((lowest[RSXBARS](RSX)) < RSXVARMIN) and ((highest[RSXBARS](RSX)) < RSXVARMAX)// Conditions to enter short positionsc13 = (STOS < STOUNDERS) // 80c14 = (STOS > STOOVERS) // 60c15 = (STOS < STOS[1])c16 = (RSX < RSX[1]) and (RSX < RSXVARMAX)c17 = ((highest[RSXBARS](RSX)) > RSXVARMAX) and ((lowest[RSXBARS](RSX)) > RSXVARMIN)//first trade whatever conditionif NOT ONMARKET AND c3 and c4 and c5 and c6 and c7 AND NOT daysForbiddenEntry then //close>close[1]BUY amountl LOT AT MARKETendifif NOT ONMARKET AND c13 and c14 and c15 and c16 and c17 AND NOT daysForbiddenEntry then //close<close[1]SELLSHORT amounts LOT AT MARKETendif//money management//liveaccountbalance = accountbalance+strategyprofitmoneyriskl = riskpipslif longonmarket thenonepointvaluebasketl = pointvalue*countofpositionmindistancetoclosel =(moneyriskl/onepointvaluebasketl)*pipsizeendifmoneyrisks = riskpipssif shortonmarket thenonepointvaluebaskets = pointvalue*countofpositionmindistancetocloses =(moneyrisks/onepointvaluebaskets)*pipsizeendif//floating profitfloatingprofitl = (((close-positionprice)*pointvalue)*countofposition)/pipsizefloatingprofits = (((close-positionprice)*pointvalue)*countofposition)/pipsize//actual trade gainsMAfloatingprofitl = average[MAPROFITAVGL](floatingprofitl)BBfloatingprofitl = MAfloatingprofitl - std[BBPROFITSTDAVGL](MAfloatingprofitl)*sdlMAfloatingprofits = average[MAPROFITAVGS](floatingprofits)BBfloatingprofits = MAfloatingprofits - std[BBPROFITSTDAVGS](MAfloatingprofits)*sds//floating profit risk reward checkif profitpipsl>0 and floatingprofitl>profitpipsl thenRRreached=1endifif profitpipss>0 and floatingprofits>profitpipss thenRRreached=1endif//stoploss trigger when risk reward ratio is not met already//if onmarket and RRreached=0 then//SELL AT positionprice-mindistancetoclose STOP//EXITSHORT AT positionprice-mindistancetoclose STOP//endifif longonmarket and RRreached=0 thenSELL AT positionprice-mindistancetoclosel STOP//EXITSHORT AT positionprice-mindistancetoclose STOPendifif shortonmarket and RRreached=0 then//SELL AT positionprice-mindistancetoclose STOPEXITSHORT AT positionprice-mindistancetocloses STOPendif//stoploss trigger when risk reward ratio has been reached//if onmarket and RRreached=1 then//if floatingprofit crosses under BBfloatingprofit then//SELL AT MARKET//EXITSHORT AT MARKET//endif//endifif longonmarket and RRreached=1 and (stol < STOMANTAINL) thenif floatingprofitl crosses under BBfloatingprofitl thenSELL AT MARKETendifendifif shortonmarket and RRreached=1 and (stos > STOMANTAINS) thenif floatingprofits crosses under BBfloatingprofits thenEXITSHORT AT MARKETendifendif//resetting the risk reward reached variableif not onmarket thenRRreached = 0endifThanks a lot!
1 user thanked author for this post.
08/26/2018 at 8:59 AM #79077Hi Vonasi, thanks a lot for your response.
The main problem is defining last condition in a certain number of bars may limit amount of trades done.
What about if RSI or RSX condition is made on last 30 bars and not 14 or 20? I don’t want to lose those trades. So I would like to save in a floating var the last point where that condition were done and open trades in base at that condition.
I’m not sure if I explain it right at all, sorry.
08/26/2018 at 9:01 AM #79078However code is a bit frankenstein…don’t laugh please
I’m not laughing at the code, but I am at the joke! Very good!! I’ll have to remember that one! 🙂
But I have to say I am a bit scared by the monster!
Also you must look and feel like a monster if you have been up all night coding!?
I tried it on my Platform over 100k bars on DAX 1 min and it executes nil / zero trades … so that is the first problem – no trades – Yes??
08/26/2018 at 9:11 AM #79079Hi GraHal,
I don’t feel like Frankie…instead I want more coding…I’m getting addict 😀
I don’t have problems with code, but I upload it to test it. In 100000 bars doesn’t have great results but yes at 10.000 and 30.000 and my idea is updating vars to adapt it at market conditions.
I attach also some performance results.
Thanks again.
08/26/2018 at 9:12 AM #79083I test it at IG DAX 1€ cash.
08/26/2018 at 9:27 AM #79084I got 1 trade on a 5 min TF over 100k bars on DAX so my conclusions would be that your code has far too many AND conditions and they are not being met all at the same time.
I tried deleting Buy conditions one by one and I got trades (on 1 min TF) but they lost loads and loads of £££s.
I think you need to put chains / ropes on Frankenstein v1.0 and start on Frank v2.0 with far less conditions?? See if you can get signs of life in a finger before putting the whole monster body together?? Sorry couldn’t resist that! 🙂 🙂
On a less jokey note … did you run the System and get trades after adding each condition or did you write lots of conditions and then run the code (apply the lightning bolt to Frank!)??
Edit / PS
I wrote above before I saw your post with results … weird that I get zero trades? I’ll try running again again and report back.
08/26/2018 at 9:34 AM #79086Hi GraHal,
I don’t know which may be the real problem with your tests. I’m testing in € and capital is configured in PRT strategy window.
- Initial capital: 600€
- Spread: 2
Also, my country is Spain…not sure if it may affect to tests and results, because it works from 10:10 to 17:25 to avoid high commissions and market openings.
If you see performance data attached, are very promising. Of course I would like to reduce vars and conditions but I think it works nice for me.
About my doubts, have you got any idea? It’s adding some more code but I don’t fear of it 😀
Thanks again for your comments.
08/26/2018 at 9:40 AM #79089Aha I try it now on my Spread Bet Platform and I get 1 trade on DJI at 1 min TF (still no trades on DAX 1 min on CFD or SB PLatform).
Bit of a mystery, maybe it is the Time settings difference between our Platforms … Ill convert the times and report back.
EDIT / PS
To get same the lightning bolt at same time as Spain, I knocked 1 hour off Flat Before / After and still the same results … no trades on DAX at 1 min. Also I used the .itf file … so I have all Franks body parts in my Test Lab also! 🙂
08/26/2018 at 9:54 AM #79092but yes at 10.000 and 30.000
What do you mean re above?? 10 AM and 3 PM or what?
08/26/2018 at 9:55 AM #79094Sorry… 10000 and 30000 BARS
In Spain we use dots [.] instead commas [,] for thousand separations.
Regards.
1 user thanked author for this post.
08/26/2018 at 10:44 AM #79099@komiya Are you 100% sure that the results you show in post above are results for the code in the .itf file??
I can’t understand how you get trades and I don’t with the same code on same data on same TF etc etc??
Anybody else offer any thoughts on why nil trades for me and 95 trades for komiya??
08/26/2018 at 10:54 AM #79101Hi, I reupload again but it’s working nice for me…
Anybody else may test it and think about my question?
Thanks a lot people!
-
AuthorPosts