Grid orders with one combined stop loss and limit, can it be done?
Forums › ProRealTime English forum › ProOrder support › Grid orders with one combined stop loss and limit, can it be done?
- This topic has 307 replies, 1 voice, and was last updated 7 months ago by OtherAttorney.
-
-
06/28/2016 at 6:44 PM #9976
Hi siaoman,
The code I posted in the last version is a dummy strategy for further development, it is not suitable to be traded “as is” because of needs to find good entries, as already discussed. The commented codes are a part of this “testing” strategy.
Also, as you noticed, there is only one cycle of trades because of the test on STRATEGYPROFIT=0, that you have commented in lines 28 and 32 of your code.
06/28/2016 at 7:18 PM #9977Nicolas, the forward testing of the dynamic grid step looks very promising and the system appear to adjust the entries to the current volatility so both the idea and the coding works great 🙂
However one issue we need to take into account is that the system should preferably be run on the 1 second timeframe for the most accurate entries but on that timeframe it is difficult to measure the volatility properly and the default ATRcurrentPeriod of 5 does not have much of a meaning measuring the volatility over the last 5 seconds. Of course we can adjust these parameters, for instance if I would like to measure ATR on the 5 min timeframe I can multiply the value by 300 (60 seconds * 5 min = 300) and change the parameter accordingly, do you this is a good way of dealing with the issue or would it be better to adjust the ATR function of the system to measure the ATR on a higher timeframe than the system is running on?
@ siaoman, the system is only intended to run for one cycle until it is started manually again otherwise it would be too much of a gamble to leave it running, if markets are ranging or choppy with high volatility one could easily blow a quarter of one’s account in an hour.
BTW now there are only 7 matches left in the Euro Cup so I will become more active here again than I’ve been the last couple of weeks 🙂
06/29/2016 at 5:48 AM #9983Cheers for the response Nicolas. I had a feeling that was the case. I’m going to continue testing the system to enter based on some entry rules I have, but so far the dynamic grid works really well. If I get something to work well, I’ll post it here in spirit of sharing!
Thanks again.
06/29/2016 at 7:48 AM #9984Yes you can adjust the ATR period the way you do by multiplying the ATR period, that’s why I left ATR period in parameters, for everyone set to their needs. I’m used to say that I make the weapons but I rarely use them on the battlefield 🙂
07/02/2016 at 1:14 PM #10113@cfta Sorry, its from a friend. I have not tested it.
07/05/2016 at 7:41 PM #10250Nicolas, the testing goes on and for the most part it looks great but there are a couple of issues that might turn out to be a problem.
The dynamic step grid min and max grid step seem to work perfectly for indices such as the DAX but not at all for FX pairs. I have noticed this in both backtesting and in real time, for a sample I ran a test on GBP/USD with min grid step 10 and max 50 but some trades ended up being taken with just 2 pips in between, I thought this might be a decimal issue and increased the step tenfold to 100 and 500 but it didn’t seem to solve the problem and trades were still entered at the same small grid steps. Please look into how we can solve it 🙂
The other issue is the one in my last post about multiplying the number of ATR periods which turned out to be a problem for me when reaching high numbers with an error message saying historic bars were insufficient even though I increased the defparam bars to an even higher number, this might be due to my inexperience with PRT though…
Here’s the code I used for testing shorts in case I erased or changed something by accident;
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768defparam preloadbars = 3000once RRreached = 0//parametersaccountbalance = 10000 //account balance in money at strategy startriskpercent = 2 //whole account risk in percent%amount = 1 //lot amount to open each traderr = 3 //risk reward ratio (set to 0 disable this function)//dynamic step gridminSTEP = 10 //minimal step of the gridmaxSTEP = 50 //maximal step of the gridATRcurrentPeriod = 25 //recent volatility 'instant' periodATRhistoPeriod = 500 //historical volatility periodATR = averagetruerange[ATRcurrentPeriod]histoATR= highest[ATRhistoPeriod](ATR)resultMAX = MAX(minSTEP*pipsize,histoATR - ATR)resultMIN = MIN(resultMAX,maxSTEP*pipsize)gridstep = ROUND(resultMIN)//first trade whatever conditionif NOT ONMARKET AND close<close[1] AND STRATEGYPROFIT=0 thenSELLSHORT amount LOT AT MARKETendif// case SELL - add orders on the same trendif shortonmarket and tradeprice(1)-close>=gridstep*pipsize thenSELLSHORT amount LOT AT MARKETendif//money managementliveaccountbalance = accountbalance+strategyprofitmoneyrisk = (liveaccountbalance*(riskpercent/100))if onmarket thenonepointvaluebasket = pointvalue*countofpositionmindistancetoclose =(moneyrisk/onepointvaluebasket)*pipsizeendif//floating profitfloatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize //actual trade gainsMAfloatingprofit = average[20](floatingprofit)BBfloatingprofit = MAfloatingprofit - std[20](MAfloatingprofit)*2//floating profit risk reward checkif rr>0 and floatingprofit>moneyrisk*rr thenRRreached=1endif//stoploss trigger when risk reward ratio is not met alreadyif onmarket and RRreached=0 thenEXITSHORT AT positionprice-mindistancetoclose STOPendif//stoploss trigger when risj reward ratio has been reachedif onmarket and RRreached=1 thenif floatingprofit crosses under BBfloatingprofit thenEXITSHORT AT MARKETendifEXITSHORT AT positionprice-mindistancetoclose STOPendif//resetting the risk reward reached variableif not onmarket thenRRreached = 0endifFor everyone following the developement of the system I’m happy to share that I have been practicing using it for intraday trades with small grid step, it takes more time and patience but when the right move comes we can easily harvest 5-10 % in an hour or two 🙂
07/06/2016 at 7:52 AM #10260Thank you for your feedback. Just spotted the problems for the dynamic step grid, my fault! 🙂
The line 22 should be replace with:
1gridstep = (resultMIN)Because ROUND can’t round decimal number.
Also the instructions “pipsize” must be deleted from the add orders conditions because the dynamic step is already calculated this way (with pips decimal numbers).
Please find attached the fixed version.
1 user thanked author for this post.
07/11/2016 at 8:35 AM #10384Hi cfta
Interesting that you have tested it on intraday trends with promising results. I’ve tested to run it on the swedish omx30 with signals on 5-min chart and then grid orders on 1 minute and 1 second. My experience so far is that although being right on the direction, when being filled and building the position and therefore adjusting the stop and getting it closer to the actual price, the position gets very sensitive for a minor countermove and therefore often get stopped out before reaching my target. I asume that I need to adjust my values (grid step, s/l, target, atr-period and so on) and need some input on how to think. Have you tested on the omx30 and if so what values do you use? If not what timeframes and settings have you tested with good results on other indices? Any other ideas on how to set and test values to get better results?
Thanks to you and Nicolas for your continued work on this promising idea:)
07/11/2016 at 8:39 AM #1038607/11/2016 at 9:40 AM #10391Thanks Nicolas
I understand. Then one need to find out the best relationship between the s/l, target and the other values so that you can take a small countermove in the trend you ride just before your target is hit. Would a wider stoploss be better in this case? Feels like it is necessary to combine grid-orders with an entry strategy into a complete trading system to be able to get a real backtest. For the moment I do it manually with some ideas but it is not effective enough.
@cfta Do you set fixed targets when you run your tests or do you only use the built in exits?07/12/2016 at 11:52 AM #10428Thanks for the fixed code Nicolas 🙂
@ Brage, remember that the initial idea behind this strategy is to look for swing trades on the H4 charts with 20 pip grid steps wich provides a decent margin for the trade to trend in one direction and turn profitable before being stopped out, preferably by the BB exit securing some profit rather than losing 1 %. Either way this system requires a fairly high degree of accuracy in picking entries in which the market will go one way with only minor retracements to work, the last couple of months the market conditions have been quite bad for this mostly related to the rash moves related to the brexit concerns.
Bottom line is that the larger the grid step the smaller the risk of being stopped out, of course increasing the SL also reduce the risk of being stopped out but once you have built up a large position with 6-10 entries you will get stopped out fast by a moderate retracement anyway unless having a huge SL of 10-20 % which I wouldn’t recommend. My advice is to have a fairly low RR for the BB exit to kick in at 2 or 3 which will save you from a fair amount of stop outs and to start experimenting with the ATR settings of the dynamic grid step so entries will not be taken or only taken with large steps when the markets are choppy and stack up the orders once the price starts moving. Usually I trust the BB exit and SL to do their job but sometimes I stop the system manually if I reckon the price is about to turn and saving the extra profit before the BB exit.
Here is a table I posted earlier in the thread for reference on how the SL mover closer to the average entry price;
1 user thanked author for this post.
07/12/2016 at 10:17 PM #10436Thanks for answers
Will try larger timeframes and a lower rr and experiment more with the ATR settings. Had a couple of questions in a previous post. Have you tested on the omx30 and if so what values do you use? If not what timeframes and settings have you tested with good results on other indices? Do you prefer FX pairs for this code?
07/14/2016 at 4:13 PM #10468Welcome Brage!
No I have never traded OMX 30 at all but it might be worth a try, in particular since it is almost 24 hours a day with IG and hence avoiding the worst gapping. I mostly focus on the DAX, Dow Jones and Nikkei for indices and spend about as much time on FX pairs with a bit more attention to the EUR and GBP crosses with AUD and CAD. I like the yen pairs most but have not yet gotten around to tweak the code to suit yen-pairs which I beleive are very suited for the system since they often have nice and smooth swings with moderate tracements and spikes. For TF I either view H4 or H1 for the lareger grid steps and then switch to 5m to pinpoint where to start the system and for smaller grid steps I look at m15 or m15 and then switch to m1 or 10 sec chart to start it up.
Please share your progress on the different ATR settings!
08/08/2016 at 8:15 PM #1137708/09/2016 at 7:55 PM #11457Hey fellows,
The EURO is over and so is my holiday though volatility has been irratic and choppy or virtually non existant so testing has been limited but slowly progressing. As mentioned previously focus has been on determining the most profitable settings for the dynamic step grid, I like to to run the system on 10 second to avoid delayed entries when the market is moving quickly and hence we need high number on the ATR period to get entries adjusted to the volatility. The most recent settings I have been testing is 10 and 50 for min and max grid step along with 500 and 10 000 for ATRcurrentperiod and ATRhistoperiod.
Nicolas, the ATR measures the volatility of the market but not the direction do you think it would be useful to replace the ATR with ADX instead? In a dream scenario I would like to implement an ADX matrix measuring the ADX for multiple timeframes on multiple number of periods at once, on Metatrade I used to use such an indicator for manual entries which proved very useful, perhaps I should start a seperate thread for indicator development if we have a go at it?
-
AuthorPosts
Find exclusive trading pro-tools on