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/17/2016 at 2:02 PM #721505/18/2016 at 4:18 PM #7286
Ok guys, finally have some time to finish the system.
So orders basket will now exit with the floating profit curve cross below 2 standard deviation from its 20 period average. From my own test, things go well, of course this system needs a good first entry points. Also please consider that the risk reward ratio has to be set at about 3 or so to give “space” to the profit exit system to be correctly managed.. I found that adding orders in a good trend run is very powerful and can just make gigantic profit very fast, so if the “rr” variable is set to 1 then the profit exit system will be set to ON very soon and exit of orders will happen very fast.
The original system without exit is still good in this version, just set “rr” variable to 0 and nothing will happen for exiting positions.
Please find attached the whole code and pictures of the system with and without “BB exit system“.
This is an original money management code, but as you can see, we can build anything from just little imagination and knowledge, so this thing can evolve or can be totally changed to a whole new system. Your turn to find good use of this 🙂
3 users thanked author for this post.
05/18/2016 at 4:31 PM #729205/19/2016 at 12:10 AM #7308Fantastic work ! Many thanks to all for their work and esp to Nicolas, you’re doing a great job and helping a lot of people here. This looks like being the start of a robust money and position management system that can benefit all. I am testing out different ideas with this and will post any interesting results here, would encourage everyone to do the same.
05/19/2016 at 5:27 AM #7313To all participants, I applaud the excellent result of a great team effort – thanks for the postings and the opportunity to learn from the masters.
I have tested it with the BB exit, on GBPJPY 5m chart from 18/5/16 at 20:30 AEST with a fabulous result: 578% for 8 hours exposure. I have the rr = 2.
I am finding that there are not many opportunities in the last few months where this could have been achieved in FX, as the trends haven’t lasted long enough. The retraces are firing the stop losses. But one profit like this will take care of 578 losses – so it is a Turtle Traders test of persistence.
My thoughts are that if the risk is increased to 2%, this may provide enough space for the minor retraces to pass without firing the stop losses, and so reach the target profit.
Or alternatively, if a trailing stop loss (equating to the risk) was used on the latest trade, any retracement will sacrifice the last trade, but the profit on the early trades would more than compensate. May I suggest that the grid step be set to say, 6 x ATR and the trailing stop at 2 x ATR.
I figure Nicolas is doing something like this with the money management and floating profit, but I don’t understand how the coding works.
I look forward to the experiences of others when testing this amazing system.
1 user thanked author for this post.
05/19/2016 at 7:11 AM #7314Hi,
I am very impressed with what has been going on here. However, I have tried the latest script ‘grid-orders-ctfa-with-BB-exit’ by importing the itf file, so I haven’t changed anything: it only does 1 trade at the start and then nothing more. It does this on EURO/USD, GBP/USD, CACA40 and it also doesn’t matter if I use a 1 min, 5 min or 15 min timeframe in the backtest. What could be wrong here?
Thank you very much for your advice and congratulations!
Glen
05/19/2016 at 7:28 AM #7318Thanks again Nicolas for your great work 🙂 Real time market testing begins today!
To all others, I’m very happy you appreciate my idea and suggest further improvements.
@ MikeGC, very good suggestions Mike that can definintely improve profitability and avoid being stopped out of trades before the trend starts, there is plenty of optimization which can be done for this system.
05/19/2016 at 9:48 AM #7329Hi everyone!
Congratulations for this fantastic job !!
@gforton I was trying the code shared and found that the first condition to join the market is set up with “strategyprofit=0” and this only occurs first time:12345678//first trade whatever conditionif NOT ONMARKET AND close>close[1] AND STRATEGYPROFIT=0 thenBUY amount LOT AT MARKETendifif NOT ONMARKET AND close<close[1] AND STRATEGYPROFIT=0 thenSELLSHORT amount LOT AT MARKETendifChange this to your conditions to enter and it will work fine, or just delete this part like this:
12345678//first trade whatever conditionif NOT ONMARKET AND close>close[1] thenBUY amount LOT AT MARKETendifif NOT ONMARKET AND close<close[1] thenSELLSHORT amount LOT AT MARKETendifHave a nice day and better trading!!
Cheers!
1 user thanked author for this post.
05/19/2016 at 9:51 AM #733005/19/2016 at 10:19 AM #7333Thanks Nicolas!
Here is the code printed out:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667defparam preloadbars = 100once RRreached = 0//parametersaccountbalance = 10000 //account balance in money at strategy startriskpercent = 1 //whole account risk in percent%gridstep = 50 //grid step in pointamount = 1 //lot amount to open each traderr = 5 //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 MARKETendifif NOT ONMARKET AND close<close[1] AND STRATEGYPROFIT=0 thenSELLSHORT amount LOT AT MARKETendif// case BUY - add orders on the same trendif longonmarket and close-tradeprice(1)>=gridstep*pipsize thenBUY 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))onepointvaluebasket = pointvalue*countofpositionmindistancetoclose =(moneyrisk/onepointvaluebasket)*ticksize//floating profitfloatingprofit = ((close-positionprice)*pointvalue)*countofpositionMAfloatingprofit = average[20](floatingprofit)BBfloatingprofit = MAfloatingprofit - std[20](MAfloatingprofit)*2//floating profit risk reward checkif rr>0 and floatingprofit>moneyrisk*rr thenRRreached=1endif//GRAPH floatingprofit as "float"//GRAPH RRreached as "rr"GRAPH floatingprofit as "floating profit"GRAPH BBfloatingprofit as "deviation of floating profit"//stoploss trigger when risk reward ratio is not met alreadyif onmarket and RRreached=0 thenSELL AT positionprice-mindistancetoclose STOPEXITSHORT AT positionprice-mindistancetoclose STOPendif//stoploss trigger when risj reward ratio has been reachedif onmarket and RRreached=1 thenif floatingprofit crosses under BBfloatingprofit thenSELL AT MARKETEXITSHORT AT MARKETendifendif//resetting the risk reward reached variableif not onmarket thenRRreached = 0endif05/19/2016 at 6:44 PM #7415All right, so once again the code beats my knowledge, I don’t manage to run the system in real time because I get the error message;
“This trading system was stopped due to a division by zero during the evaluation of the last candlestick. Please add protections to your code to prevent divisions by zero.”
I managed to sort it in the previous version with some advice, in this version I tried to solve it the same way by cutting and pasting some of the lines to different sections of the code but I’m not able to fix it so please help me out you guys with better coding knowledge…
At least I remembered to delete the graph lines before running it real time 🙂
BTW has anyone managed to run it properly on JPY pairs yet? I have only had one entry order and then stopped out asap…
05/19/2016 at 7:18 PM #7420Sorry for this stupid bug.
Here is a quick fix just replace the lines 33 & 34 with these ones:
1234if onmarket thenonepointvaluebasket = pointvalue*countofpositionmindistancetoclose =(moneyrisk/onepointvaluebasket)*ticksizeendif05/19/2016 at 7:29 PM #7421About 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.
So a dynamic scale of the grid step could be coded, but it would be inverse of the ATR value. High ATR should mean minimal grid step and low ATR a larger one. Also, a minimal value of the grid step can be implemented.
Do you agree? everyone?
1 user thanked author for this post.
05/20/2016 at 10:21 AM #7457Hi Simon, I have just discovered your post re an ATR trailing stop – I couldn’t agree more. A long trend needs scope so the max profit can be achieved. The best way to do this is with a wide trailing stop but with the accompanying increased risk. This is the beauty of @cfta grid system – the profit does not rely on one trade.
1 user thanked author for this post.
05/20/2016 at 10:37 AM #7461I agree re the order size but I am not so sure about the BB exit.
I have attached the results of a test trade on CADJPY that is mouth-watering. Goodbye 2:1, hello 10:1!
I’m afraid I butchered your code Nicolas and your money management and r:r control, cfta- many apologies.
The trailing stop in the test is the SuperTrend. As you may well know, it is based on the ATR. The formula for both………….
Super trend values are calculated as follows
Up = (HIGH + LOW) / 2 + Multiplier * ATR
Down = (HIGH + LOW) / 2 – Multiplier * ATR
When the change of trend occurs, the indicator flipsAverage True Range is calculated as follows
Current ATR = [(Prior ATR x 13) + Current TR] / 14
– Multiply the previous 14-day ATR by 13.
– Add the most recent day’s TR value.
– Divide the total by 14I have attached the butchered code – ugh, not very tidy but I don’t have the expertise to complete the money management nor the grid step – sorry.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374defparam preloadbars = 100//once RRreached = 0//parameters//accountbalance = 10000 //account balance in money at strategy start//riskpercent = 1 //whole account risk in percent%gridstep = 50 //grid step in pointamount = 1 //lot amount to open each trade//rr = 0 //risk reward ratio (set to 0 disable this function)ST = SuperTrend[3.2,22]//first trade whatever conditionif NOT ONMARKET AND close>close[1] AND STRATEGYPROFIT=0 thenBUY amount LOT AT MARKETendifif NOT ONMARKET AND close<close[1] AND STRATEGYPROFIT=0 thenSELLSHORT amount LOT AT MARKETendif// case BUY - add orders on the same trendif longonmarket and close-tradeprice(1)>=gridstep*pipsize thenBUY amount LOT AT MARKETendif// case SELL - add orders on the same trendif shortonmarket and tradeprice(1)-close>=gridstep*pipsize thenSELLSHORT amount LOT AT MARKETendif//SuperTrend stop lossif close > ST THENEXITSHORT AT MARKETENDIF//money management//liveaccountbalance = accountbalance+strategyprofit//moneyrisk = (liveaccountbalance*(riskpercent/100))//onepointvaluebasket = pointvalue*countofposition//mindistancetoclose =(moneyrisk/onepointvaluebasket)*ticksize//floating profit//floatingprofit = ((close-positionprice)*pointvalue)*countofposition//MAfloatingprofit = average[20](floatingprofit)//BBfloatingprofit = MAfloatingprofit - std[20](MAfloatingprofit)*2//floating profit risk reward check//if rr>0 and floatingprofit>moneyrisk*rr then//RRreached=1//endif//GRAPH floatingprofit as "float"//GRAPH RRreached as "rr"//GRAPH floatingprofit as "floating profit"//GRAPH BBfloatingprofit as "deviation of floating profit"//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//endif//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//endif//resetting the risk reward reached variable//if not onmarket then//RRreached = 0//endif -
AuthorPosts
Find exclusive trading pro-tools on