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.
-
-
05/20/2016 at 11:01 AM #746705/20/2016 at 11:24 AM #7474
Thanks for your post, but in this code you totally deleted the money management system of cfta. This code only add orders on the same trend and then exit them when the supertrend change direction. I’m sorry, but what is the best of the system here is the 1% loss despite of how many trades are on the run, so while deleting this part, it’s like get back to the beginning 🙂
I’ll plan to work on dynamic step asap. But I’d like to find a good way to enter market first, so do anyone have worked already on that? I know a lot of people are reading this thread, don’t be shy! 🙂
05/20/2016 at 11:49 AM #7507@Nicolas and everybody
I might have found a system which might work as an entry. It is called State Space and I have started a new thread here to discuss it:
http://www.prorealcode.com/topic/state-space/I have there also posted some combinations together with the grind system, starting in post 4 I think. But I think its good to start reading from post 1.
@Nicolas could you please help with the first goal in the thread?Please use all systems there carefully. I have not used them live yet.
05/20/2016 at 2:26 PM #7521I am sorry if I offended you or cfta. It is not that the idea and the coding aren’t brilliant. I was merely trying to demonstrate an alternative as I was finding the BB exit system showing mostly losses on back tests. I did not intend it as complete code but I don’t know how to code the money management system to integrate with a SuperTrend stop.
Has anyone else back tested the grid system extensively with the BB exit switched on? Are you finding the same issues?
05/20/2016 at 3:54 PM #7534I will share my actual start point in my trading.
I wait till the markets moves at least 45 pips in any direction above or under Exponentialaverage[8](close). When this occurs a limit order starts at this Exponentialaverage[8](close) buy or sell. I got a fixed profit and stop for 25-30 pips. I tryed BB exit with worst results than taking a fixed profit (maybe beacuse backtest limits).
See attached images.
05/20/2016 at 4:49 PM #7544This is normal since you don’t use add orders in your strategy. Adding the bollinger bands deviation over the floating profit curve give us some space for the whole basket orders to close while it can continue to make profit along the way. It’s just a way of let the profit run than to exit properly with a fixed % trailing stop.
I haven’t code anything else with BB exit for the moment. But I think its powerfulness resides in a trending market condition with a simple entry based on things not too complicated, I do believe that a couple of moving average could make the trick.
I’m not offended at all! Let’s share your ideas! Sorry if it looked different in my previous replies.
05/20/2016 at 5:04 PM #7546Thanks for give back your feedback. I tested my strategy adding orders (see attached image). It gives very good trades sometimes and the most important thing is it didn’t crash the whole account over the time, so it’s not so bad! ( with BB EXIT ). but sometimes i don’t like it, hehehe, like image2.
Keep following for news, thanks all!
05/20/2016 at 5:19 PM #7551Ok but please keep in mind that the BB exit calculated on the floating profit is exactly the same thing as a standard bollinger bands on price. It is more convenient to recalculate it on floating profit because it is the same deviation for the buy and sell orders, that’s all.
Floating profit is nothing more than the difference of the actual price and the average price of orders, multiplied by the number of them. So its curve, is the same as the price itself.
The BB exist operand only if the Risk Reward ratio is reached so it would never exit positions in loss (if everything is in the code though! 🙂 )
05/21/2016 at 2:52 PM #7632Hi all, very very intesresting… but… something is missing!!! I really like that you have developped a Trading system from the end. Usually we develop TS from the enrty conditions 🙂 not from the exit.
So… Now What is missing is the entry condition. I am working on it and will come back soon.
What I have changed to the TS?
- the system does not only one entry
- gridstep is decided depending on the choosen index and it is 1/4 of the riskpercent. In future this should be decided using ATR!! very important. (Will work on this also)
- the RRreached = 0 is setup in a different position then nicholas TS. Sorry Nicholas but it wasn’t working where you have done it and I do not undestand why. Do you know why?
- I have added some comments to explain better all the lines.
I am working now to find the entry condition… what we have to look for is a paramenter that tell us when a direction is choosen… one question… on which TF you would like to run it?
It is importan that this system will run on index with fixed spread if we want to use it on bigger TF than 15 minutes. During night we have too big spreads on normal index. Maybe we should use this on commodites?
Nicholas, one question… when we run a backtest all the loosing trades should have the same loss. (1% of the account). Why does not work in this way? pleas elook the image attached.
In the picture one example on dax 1 hour with spread 1.
Last thing that it seems that we forget always 🙁
The code must be roboust. This mean that if I run it on different index it should have similar performance in all. (I think that this is the reason why most of the code I found on this forum are not good for real money trading)
Here my code modifed:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889//after the enrty (long or short) this TS is meant to do more entry until the Stoploss or the Takeprofit will be reached. The stop loss is not static but it is decided at the beginning with variable riskpercent. When the system makes the second, third ,fourth, etc entries the SL is moved to guarantee that the risk is always the same (it means that at every new buy signal it is moved more near to the avarage price.//The Take profit is done when the atual gain is under the avarage of the last trades and when the risk reward ratio is reacheddefparam preloadbars = 100once RRreached = 0//parametersindexvalue = 10000 //dax=10000 MIB=18000 WTI=4800 etc...Entrysteps = 0.25 // decide with which interval the new entries are doneaccountbalance = 10000 //account balance in money at strategy startriskpercent = 1 //whole account risk in percent%gridstep = indexvalue*(riskpercent/100*Entrysteps) //grid step in point, this should change depending on the volatilityamount = 1 //lot amount to open each traderr = 3//risk reward ratio (set to 0 disable this function)//first trade whatever condition. Here you should put the entry of long trades. this one below is only an example.if NOT ONMARKET AND close>close[1] thenBUY amount LOT AT MARKETendif//first trade whatever condition. Here you should put the entry of short trades. this one below is only an example.if NOT ONMARKET AND close<close[1] thenSELLSHORT amount LOT AT MARKETendif// case BUY - add orders on the same trend. Here is when next buy are madeif longonmarket and close-tradeprice(1)>=gridstep*pipsize thenBUY amount LOT AT MARKETendif// case SELL - add orders on the same trend. Here is when next sell are madeif shortonmarket and tradeprice(1)-close>=gridstep*pipsize thenSELLSHORT amount LOT AT MARKETendif//money managementliveaccountbalance = accountbalance+strategyprofit //balance account considering the past tradesmoneyrisk = (liveaccountbalance*(riskpercent/100)) //value in euro that we risk on each trade.if onmarket thenonepointvaluebasket = pointvalue*countofposition //value of each point of the index. It increase when we have multiples contractsmindistancetoclose =(moneyrisk/onepointvaluebasket)*ticksize //index points calculated to keep the stoploss fixedendif//floating profitfloatingprofit = ((close-positionprice)*pointvalue)*countofposition //actual trade gainsMAfloatingprofit = average[20](floatingprofit)//avarage of the last 20 tradesBBfloatingprofit = MAfloatingprofit - std[20](MAfloatingprofit)*2 //standard deviation of the avarage of last 20 trades//floating profit risk reward check. If the actual gain is bigger than the riskreward the variable RRreached is set to 1. It means that the system is ready to exit at the take profit signal.if rr>0 and floatingprofit>moneyrisk*rr thenRRreached=1endif//Here is where we set the stoploss. it means that the reward ratio is not reached yet.if onmarket and RRreached=0 thenSELL AT positionprice-mindistancetoclose STOPEXITSHORT AT positionprice-mindistancetoclose STOPendif//stoploss trigger when risk reward ratio has been reached.//If the risk reward is reached the take profit can be done. The Take profit is done when the atual gain is under the avarage of the last tradesif onmarket and RRreached=1 thenif floatingprofit crosses under BBfloatingprofit thenSELL AT MARKETEXITSHORT AT MARKETRRreached = 0 //resetting the risk reward reached variableendifendif//resetting the risk reward reached variable//if not onmarket then//RRreached = 0//endif//GRAPH average[10](strategyprofit) coloured(0,0,255) as "profit curve"//HOW TO MAKE IT BETTER: About ATR step instead of fixed one is clever. But, since we want to quickly make huge profit, I suggest to add more orders when the ATR is high and less when it is low. So when the ATR rise a lot in short period, it means that actual volatility can guarantee that a lot of grid orders can be launched to grow the floating profit. Then BB exit would take care of the rest. Of course, we are talking of backtest, live environment should not the exact same thing as market slippage can take its part into making trouble.05/21/2016 at 9:39 PM #7655Hi, while working on that code I realize there were a mistake in the floating profit formula.
The good one is:
12//floating profitfloatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize //actual trade gainsWhile the old one were sufficient for indices for example, it were not good for forex pairs.
Maybe that is where is the trouble with your tests David.
05/22/2016 at 2:27 AM #7660@David-1984 thank you for the comments.
I would like to discuss “Robustness” some more as a general concept because I believe the notion of Robustness across different instruments/pairs is unrealistic. You probably have much more experience with writing algorithms than I do, so I would really like to openly chat about it some more. I think it’s best if we discuss this as a New Post?
I look forward to learning from your experiences.
05/22/2016 at 11:55 AM #7668This is a really good point @dwgfx. One that has concerned me for some time. Thanks for bringing it up. I am very interested to hear what others think.
It harks back to Nicholas’s post re curve fitting. In my limited experience with PRT, I don’t think there is a way to find the optimal settings for a portfolio of instruments. However, Amibroker does have this ability. Has anyone had any experience coding Amibroker? It could be used to optimise a system so the settings could then be used in PRT.
05/22/2016 at 12:08 PM #7672Robustness is the one of the major thing an algorithm trader/coder should focus on. There are many aspects about what we call Robustness in quantitative and algorithmic trading and this is by far a very large subject that of course deserve a new topic.
FYI, Walk-Forward and Monte Carlo analysis are on the to-do list to the things that could be added to the optimization module of prorealtime.
05/22/2016 at 7:41 PM #7700Hi all, I said a stupid thing in my previus post… I said that the Loss should be always the same value. This is not true because our account is not static and it is updated with older trades. This mean that if we have 10000 euro and 1% risk we will lose 100 euro only in the first trade. After that we make (or lose) money we will lose 1% of a bigger value. Sorry again for the mistake.
While checking this I found another small problem…
In this formula the below ticksize could be wrong. It return to us the value divided by 100. This happen in all index except the commodities. For them it works.
I make an example in the picture. Nicholas, could it be a problem witgh IG market PRT version? Can somone check if also in theyr system this problem appear?
1mindistancetoclose =(moneyrisk/onepointvaluebasket)*ticksizeOT: let’s discuss here about robustness
http://www.prorealcode.com/topic/robustness-in-automated-algorithmic-trading-systems/
05/24/2016 at 7:11 AM #7836Nicolas, I’m afraid I have not managed to make the system with BB exit work as intended yet in real time markets, whenever I start the system it takes one trade and then gets stopped out after a 10 pip / 0.1 % loss. I tried the fix you mentioned above and the other fix posted on page 6;
It would be great if we can make the BB exit work. Here is the code I used for longs;
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556//-------------------------------------------------------------------------// Main code : LONG GRID BB Exit//-------------------------------------------------------------------------defparam preloadbars = 100once RRreached = 0//parametersaccountbalance = 10000 //account balance in money at strategy startriskpercent = 1 //whole account risk in percent%gridstep = 20 //grid step in pointamount = 1 //lot amount to open each traderr = 3 //risk reward ratio (set to 0 disable this function)//first trade whatever conditionif NOT ONMARKET AND close>close[1] AND STRATEGYPROFIT=0 thenBUY amount LOT AT MARKETendif// case BUY - add orders on the same trendif longonmarket and close-tradeprice(1)>=gridstep*pipsize thenBUY amount LOT AT MARKETendif//money managementliveaccountbalance = accountbalance+strategyprofitmoneyrisk = (liveaccountbalance*(riskpercent/100))if onmarket thenonepointvaluebasket = pointvalue*countofpositionmindistancetoclose =(moneyrisk/onepointvaluebasket)*ticksizeendif//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 thenSELL AT positionprice-mindistancetoclose STOPendif//stoploss trigger when risj reward ratio has been reachedif onmarket and RRreached=1 thenif floatingprofit crosses under BBfloatingprofit thenSELL AT MARKETendifendif//resetting the risk reward reached variableif not onmarket thenRRreached = 0endifPlease have a look!
-
AuthorPosts
Find exclusive trading pro-tools on