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/24/2016 at 8:00 AM #7840
I cam across that same error of money management % loss this week end. I have worked a lot on different set of codes since then, but I think the one attached here is the good and only one that work across various instruments.
Please have a look at the example of trades on NIKKEI with BB exit, it works good.
Here is the complete code:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869defparam preloadbars = 100once RRreached = 0//parametersaccountbalance = 10000 //account balance in money at strategy startriskpercent = 2 //whole account risk in percent%gridstep = 10 //grid step in pointamount = 1 //lot amount to open each traderr = 2 //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))if onmarket thenonepointvaluebasket = pointvalue*countofpositionmindistancetoclose =(moneyrisk/onepointvaluebasket)*pipsizeendif//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 = 0endifI haven’t set it on real time market already, but I plan to with simple price breakout breach to see how it goes.
1 user thanked author for this post.
05/24/2016 at 8:02 AM #7843@cfta The problem that the system exit ate 0.1% is due to the thing that I explain in my post of 22/05. Please have a look into it.
05/24/2016 at 9:16 AM #7854@Nicholas, have you seen the problem that I mentioned? also cfta has it… If you don’t have it it means that it is due to IG market.
My suggestion it is to (depending on which index we choose) multiply the ticksize in the formula below x100 but this must be checked index by index and case by case.
1mindistancetoclose =(moneyrisk/onepointvaluebasket)*ticksizeSecond thing, you are specking to put it in real market time. what TF and index you suggest? 15 minutes? In my opinion we should choose some index with good volatility and strong movements during the day.
Have you tried to remove the money management and see if all the trades close with the same loss?
05/24/2016 at 9:38 AM #7855I have changed this formula at line 35 to pipsize, which is in accordance to the pip value obviously.
Since this is a “no-brain” system (understand that there is no initial trading decision made by the code), timeframe is not important. Of course, because we need it to add orders quickly and with the minimal step requirement we want, we should put it on a minimal timeframe possible, such as seconds eventually… as long as this strategy don’t have needs of any indicator.
I said that I’ll put it on real live environment for testing purpose. First trade will be placed with breakout of a price level (Close crosses under/over …)
I think that the first idea of making decision of when and how this system should operate is a good one. As I said, ProScreener can help us a lot for that, and what we need here is to fetch trend continuation or breakout on different timeframe horizon.
05/24/2016 at 10:25 AM #7862Problem with pipsize as suggested by Nicolas it works on all indexes. Great (as usual) job Nicolas!!
One other comment… maybe (I’m testing it now) it doesn’t work properly the exit when RRreached=1. In some cases we lose more than the risk decided. A good trade turns into the worste one.
05/24/2016 at 12:19 PM #7873Please change this function to see if it happens again:
123456789//stoploss trigger when risj reward ratio has been reachedif onmarket and RRreached=1 thenif floatingprofit crosses under BBfloatingprofit thenSELL AT MARKETEXITSHORT AT MARKETendifSELL AT positionprice-mindistancetoclose STOPEXITSHORT AT positionprice-mindistancetoclose STOPendifThanks.
05/24/2016 at 2:15 PM #7874Nicolas… you are too fast 🙂
Your code solved the problem…
Here my proposal. Have a look in the picture. If we are making good money and the account is bigger than the beginning we could reach this bad situation.
2 Proposals:
Stop loss should be fixed and not equal to the account? Maybe a stop loss linked to the volatility AND the account balance?
Stoploss if after the first enrty we don’t reach a second entry in a certain time or number of candels.
(Please tell me if I’m going out of topic, I know that you want to run it only once.)
05/24/2016 at 2:47 PM #7881forgot the attachment
05/24/2016 at 7:53 PM #7919Nicolas it works! First day of real time trading everything looks good, I was short on time today and only set it up for the Nikkei with 2 % SL and 10 grid step on a 1 min, most entries were taken with a step of about 15-20 pips but of course this is due to the fast moving price. On a highly volatile index like the Nikkei it probably needs to be run on a 1 second chart.
@David great input, a mi piace! As for your above trade in oil, when we know that it is likely that the market will move and keep moving but we are uncertain of the direction run two sets of systems simultaneously, one long and one short. That’s what I did on the Nikkei today, the longs gave me a profit of 5.45 % and know I have a floating loss of 1.8 % which will either retrace or stop out at -2 %.05/24/2016 at 9:18 PM #7935When trying in realtime do you keep the entry like close<close[1]? Does it mean that you enter pratically in a random moment??
Or how did you decided to enter at 16.00?
David
05/24/2016 at 9:19 PM #7936All this has been one of the best reads I have done in a long time. Thanks all for the input. In the spirit of sharing here is a system I trade, which could maybe help with an entry. It is a system that looks for a signal candle of a certain size and then trades into that same direction. It also has an addition to it where it enters long if an unexpected big red candle appears. This is done on the 1HR TF. Have a look and maybe this can be incorporated. Im adding X’s into the code as these numbers would differ from instrument to instrument like DAX vs SP500. p.s. my coding skills aren’t that great so if anyone can suggestion changes pls feel free.
1234567891011121314151617181920212223242526272829303132333435DEFPARAM CumulateOrders = TrueCONCOUNT = 2// Conditions to enter on BIG RED candlec1 = (OPEN - CLOSE) //c1a = (c1/CLOSE)*100c2 = (CLOSE - OPEN) //= -ve valuec3 = (HIGH - LOW) //TP = (c3 * 0.62) //GoLong = c1a > 0.77 AND c2 < 0 //IF GoLong THENBUY CONCOUNT CONTRACT AT (HIGH - X) STOP//SET STOP pLOSS X// H-L c3SET TARGET pPROFIT TP//ENDIF///////////////////////////////////////////////////////////////////////////// Conditions to enter long on BREAK-OUTc1s = (CLOSE - OPEN) //c1as = (c1s/OPEN)*100c2s = (CLOSE - OPEN) //= +ve valuec3s = (HIGH - LOW) //TPs = (c3s * 0.86) //ADX1 = ADX[X]GoShort = c1as > 0.5 AND c1as < 1.2 AND c2s > 0 AND ADX1 > X//IF GoShort THENBUY CONTCOUNT CONTRACT AT (HIGH - X) STOP//high - 100SET STOP pLOSS X//SET TARGET pPROFIT TPs//ENDIF///////////////////////////////////////////////////////////////////////////1 user thanked author for this post.
05/24/2016 at 10:15 PM #7938Since there´s been a lot of changes and new inputs to the original code, it would be great to know which version you use now and that you mentioned above that you tested real time today?
And again thanks to everyone for all the input in this thread. Really interesting and I’ve learned a lot so far. Looking forward to when this code is combined with a fantastic entry strategy. It will be amazing:)
05/25/2016 at 6:28 AM #794605/25/2016 at 8:18 AM #7948In my opinion there are 2 codes that you should look for:
Code number 1 (the last one posted by Nicholas if you want to do only 1 entry)
Code number 2 (if you want to do more than 1 entry. posted below by me)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596//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.1 // decide with which interval the new entries are doneaccountbalance = 10000 //account balance in money at strategy startriskpercent = 2 //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 = 2//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 trades//liveaccountbalance = accountbalancemoneyrisk = (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)*pipsize //index points calculated to keep the stoploss fixedendif//floating profitfloatingprofit = (((close-positionprice)*pointvalue)*countofposition) // /pipsize??? //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 variableendifSELL AT positionprice-mindistancetoclose STOPEXITSHORT AT positionprice-mindistancetoclose STOPRRreached = 0 //resetting the risk reward reached variableendif//resetting the risk reward reached variable//if not onmarket then//RRreached = 0//endif//GRAPH mindistancetoclose coloured(0,0,255) as "mindistancetoclose"//GRAPH floatingprofit coloured(0,0,0) as "ticksize"//GRAPH RRreached coloured(0,0,255) as "RRreached"05/25/2016 at 5:02 PM #8015World indices made big performances yesterday with almost no retracement. That’s where this money management / add orders strategy is the most powerful. You are right about execution cfta, this implied that it needs to be launch on 1 seconds timeframe, as long that our entry don’t rely on indicator. We are all awaiting the multitimeframe support, which I hope will be soon.
-
AuthorPosts
Find exclusive trading pro-tools on