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.
-
-
12/30/2016 at 6:50 PM #19457
HA indicator incoming
1234567891011121314151617181920212223242526//Heikin-AshixClose = (Open+High+Low+Close)/4if(barindex>2) thenxOpen = (xOpen[1] + xClose[1])/2endifchangeToGreencandle = xClose>xOpen AND xClose[1]<xOpen[1]ChangeToRedcandle = xClose<xOpen AND xClose[1]>xOpen[1]Greencandle=xclose>xopenredcandle=xclose<xopenIf changeToGreencandle thenIndicator1=1elsif greencandle thenindicator1=0.5ElseIndicator1=0EndifIf ChangeToRedcandle thenIndicator22=-1elsif redcandle thenindicator22=-0.5ElseIndicator22=0EndifReturn indicator1 COLOURED(0,255,0) as "Buy", indicator22 COLOURED(255,0,0) as "Sell"🙂
1 user thanked author for this post.
01/06/2017 at 5:29 PM #20080Good afternoon, I’m a beginner.
Could someone put the final system? It seems interesting. Thank you01/09/2017 at 8:22 PM #20335Hi Iramirez and welcome to the thread 🙂
There is no final version yet since the system is still under developement but the current verions is on the previous page;
I don’t recommend this system for beginners but everyone is free to use it but make sure you do your homework on it and pay attention to if cumulative orders are allowed or not.
For all other followers I’m currently working on an alternate entry method and possibly another CTFTA indicator to facilitate setting alerts for setups.
01/30/2017 at 8:42 PM #23151Hey fellows,
It’s been quite a while since the last update here. I have been working on an alternate entry and exit version of the strategy which is better suited for the low volatility and slow markets we have been seeing for the most part of the last few months. This version is aiming at getting 25-100 pips per trade so we still need to catch a decent move but often we will get out quickly with a very small loss, since the entry signal is Heiken Ashi changing color we need to run it on a higher TF than the other verions of the system, I have focused on M15 mainly but it can be run on M5 or H1 as well. The entry filter is directional movement (25) and ADX (25), these values are discretionary depending on the TF.
However I only run it when I can keep an eye on the markets the market can travel many pips the wrong way in 15 mins, hence I also recommend turning off cumulative orders or set a low amount of maximum entries to 3 or 5.
In order for it to work you will need the below HA Change indicator (a modified version of the one Kasper provided);
12345678910111213141516171819202122//Heikin-AshixClose = (Open+High+Low+Close)/4if(barindex>2) thenxOpen = (xOpen[1] + xClose[1])/2endifchangeToGreencandle = xClose>xOpen AND xClose[1]<xOpen[1]ChangeToRedcandle = xClose<xOpen AND xClose[1]>xOpen[1]Greencandle=xclose>xopenredcandle=xclose<xopenIf changeToGreencandle thenIndicator1=1elsif greencandle thenindicator1=0.5elsif Changetoredcandle thenindicator1=-1elsif redcandle thenindicator1=-0.5ElseIndicator1=0EndifReturn indicator1Long;
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485/// Definition of code parametersdefparam preloadbars =10000DEFPARAM CumulateOrders = true // Cumulating positions deactivatedAAA= ADX [25]DIM= DI[25]HAC= call "HA Change"once RRreached = 0accountbalance = 10000 //account balance in money at strategy startriskpercent = 1 //whole account risk in percent%amount = 1 //lot amount to open each traderr = 1 //risk reward ratio (set to 0 disable this function)sd = 0.25 //standard deviation of MA floating profit//dynamic step gridminSTEP = 5 //minimal step of the gridmaxSTEP = 30 //maximal step of the gridATRcurrentPeriod = 150 //recent volatility 'instant' periodATRhistoPeriod = 3000 //historical volatility periodATR = averagetruerange[ATRcurrentPeriod]histoATR= highest[ATRhistoPeriod](ATR)resultMAX = MAX(minSTEP*pipsize,histoATR - ATR)resultMIN = MIN(resultMAX,maxSTEP*pipsize)gridstep = (resultMIN)// Conditions to enter long positionsc1 = (AAA > 10)c2 = (DIM > 0)c3 = (HAC = 1)//first trade whatever condition, for one cycle only add "AND STRATEGYPROFIT=0" on line 39.if NOT ONMARKET AND (c1)=1 AND (c2)=1 AND (c3)=1 AND close>close[1] thenBUY amount LOT AT MARKETendif// case BUY - add orders on the same trendif longonmarket and close-tradeprice(1)>=gridstep thenBUY 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)*sd//floating profit risk reward checkif rr>0 and floatingprofit>moneyrisk*rr thenRRreached=1endif//stoploss trigger when risk reward ratio is not met alreadyc4 = (HAC = -1)if onmarket and (c4)=1 thenSELL AT MARKETendifif onmarket and RRreached=0 thenSELL AT positionprice-mindistancetoclose STOPendif//stoploss trigger when risk 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 = 0endifShort
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485/// Definition of code parametersdefparam preloadbars =10000DEFPARAM CumulateOrders = true // Cumulating positions deactivatedAAA= ADX [25]DIM= DI[25]HAC= call "HA Change"once RRreached = 0accountbalance = 100000 //account balance in money at strategy startriskpercent = 1 //whole account risk in percent%amount = 1 //lot amount to open each traderr = 1 //risk reward ratio (set to 0 disable this function)//sd = 0.25 //standard deviation of MA floating profit//dynamic step gridminSTEP = 5 //minimal step of the gridmaxSTEP = 30 //maximal step of the gridATRcurrentPeriod = 150 //recent volatility 'instant' periodATRhistoPeriod = 3000 //historical volatility periodATR = averagetruerange[ATRcurrentPeriod]histoATR= highest[ATRhistoPeriod](ATR)resultMAX = MAX(minSTEP*pipsize,histoATR - ATR)resultMIN = MIN(resultMAX,maxSTEP*pipsize)gridstep = (resultMIN)// Conditions to enter short positionsc11 = (AAA > 10)c12 = (DIM < 0)c13 = (HAC = -1)//first trade whatever condition, for only one cycle add "AND STRATEGYPROFIT=0" on line 39.if NOT ONMARKET AND (c11)=1 AND (c12)=1 AND (c13)=1 AND close<close[1] thenSELLSHORT amount LOT AT MARKETendif// case SELL - add orders on the same trendif shortonmarket and tradeprice(1)-close>=gridstep 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[200](floatingprofit)BBfloatingprofit = MAfloatingprofit - std[200](MAfloatingprofit)//*sd//floating profit risk reward checkif rr>0 and floatingprofit>moneyrisk*rr thenRRreached=1endifc14 = (HAC > 0)if c14 thenEXITSHORT AT MARKETendif//stoploss trigger when risk reward ratio is not met alreadyif onmarket and RRreached=0 thenEXITSHORT AT positionprice-mindistancetoclose STOPendif//stoploss trigger when risk reward ratio has been reachedif onmarket and RRreached=1 thenif floatingprofit crosses under BBfloatingprofit thenEXITSHORT AT MARKETendifendif//resetting the risk reward reached variableif not onmarket thenRRreached = 0endifI hope you will enjoy it and find room for improvements 🙂
02/04/2017 at 7:38 AM #23882Hello Brains
could help me with the following request:
https://www.prorealcode.com/topic/request-of-money-management-for-a-grid-strategy/
Thanks in advance
Ale
02/04/2017 at 12:35 PM #23906Kasper, have you tried the latest code with HA entry and exit? It seems very promising when limiting the number of entries and running it on M15 or H1 but I’m looking for a way to filter out the sideways movement but it’s tricky to find a good one, I have been experimenting with Keltner and Donchian but no major progress yet. I’m hoping you may have some suggestions 🙂
02/04/2017 at 2:00 PM #23914Hi. I just tried the long version on DAX 15m TF .I have made the indicator and named it “HA Change”
So it runs as an automated strategy and I can see that it continues, but it’s not profitable- properly as mentioned because of sideways marked.
I have been trying to figure out what to do the code, and I got stuck. I have no idea of what to do, other that wait until multiframe support.
I have also tried to incorporate the grid code into Reiners Pathfinder, but it can not be done. it either ruins the pathfinder profit or change it so much that it’s not pathfinder anylonger. Mainly because that grid order are keeping a thight MM strategy of only trading for 1% of the account, which Pathfinder does not.
We could try and give the ALE code a shoot.
02/04/2017 at 3:56 PM #23921Well it is coded as an automated strategy but just as with the other versions of my strategies we need to pick and choose the period to start it when we have the right setup and stop it when we are happy with our profits or the setup has disappeared. If we expect an up move on DAX on Monday we start the strategy on Monday morning and keep an eye on it and the price action during the day.
Indeed MTF support would make a huge difference with more precise entries and a stoploss ready to kick in right away when a retrace occurs rather than at the close of each 15m candle, do think there is a chance that we can change the code in the HA Change to reflect a higher TF, for instance running it on 5m with the changes of 15m? I know I have asked the question before but perhaps we have found new answers since last time it was asked.
I will look inte Ale’s code more and give it a shot too, it has a lot of potential for the ranging markets we have been seeing lately.
Thanks for your feedback Kasper 🙂
12/13/2017 at 2:43 PM #55578Hey traders,
Long time no speak, I have been waiting for MTF to become available but it seem to take longer and longer.
However here is an early christmas gift. The below update is fairly useful on low-medium timframes such as M15 but when using aggregating orders (of course we can stick with single orders too) we need to run it on low TF such as M1 or lower to be able to rely on our SL or BB exit since it kicks in at close of candle and too much can happen during a M15 candle and cause much larger losses during the 15 minutes it takes for the candle too close hence I recommend setting a low maximum number of orders and monitor the system manually while it is up and running.
The update is based on Squeeze (from BB Squeeze but only the squeeze function and not the momentum) and Heiken Ashi. Squeeze need to be off (blue bar) and Heiken Ashi decide the direction of the trade either by change of color or by the current color when Squeeze changes to off (for change of color “HAC crosses over 0” and for current direction “HAC >0” for long) on line 31.
First the required indicators, HA Change;
HA Change12345678910111213141516171819202122//Heikin-AshixClose = (Open+High+Low+Close)/4if(barindex>2) thenxOpen = (xOpen[1] + xClose[1])/2endifchangeToGreencandle = xClose>xOpen AND xClose[1]<xOpen[1]ChangeToRedcandle = xClose<xOpen AND xClose[1]>xOpen[1]Greencandle=xclose>xopenredcandle=xclose<xopenIf changeToGreencandle thenIndicator1=1elsif greencandle thenindicator1=0.5elsif Changetoredcandle thenindicator1=-1elsif redcandle thenindicator1=-0.5ElseIndicator1=0EndifReturn indicator1And Squeeze;
Squeeze123456789101112131415161718192021222324// Bollinger bandssource = closebbMa = Average[bbLength](source)dev = bbMult * STD[bbLength](source)bbUpper = bbMa + devbbLower = bbMa - dev// Keltner channelskcMa = Average[kcLength](source)kcRange = TR(source)kcMaRange = Average[kcLength](kcRange)kcUpper = kcMa + kcMaRange * kcMultkcLower = kcMa - kcMaRange * kcMult// Squeeze indicatorif bbLower > kcLower and bbUpper < kcUpper then// Squeeze onindicator1=-1else// Squeeze offindicator1=1endifreturn indicator1The strategy for longs;
CFTA - LONG HA Sq123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778/// Definition of code parametersdefparam preloadbars =10000DEFPARAM CumulateOrders = true // Cumulating positions deactivatedSQ= call "Squeeze"[12, 1.5, 12, 1]HAC= call "HA Change"once RRreached = 0accountbalance = 10000 //account balance in money at strategy startriskpercent = 1 //whole account risk in percent%amount = 1 //lot amount to open each traderr = 1 //risk reward ratio (set to 0 disable this function)sd = 0.25 //standard deviation of MA floating profit//dynamic step gridminSTEP = 20 //minimal step of the gridmaxSTEP = 50 //maximal step of the gridATRcurrentPeriod = 150 //recent volatility 'instant' periodATRhistoPeriod = 3000 //historical volatility periodATR = averagetruerange[ATRcurrentPeriod]histoATR= highest[ATRhistoPeriod](ATR)resultMAX = MAX(minSTEP*pipsize,histoATR - ATR)resultMIN = MIN(resultMAX,maxSTEP*pipsize)gridstep = (resultMIN)// Conditions to enter long positionsc1 = (SQ > 0)c2 = (HAC CROSSES OVER 0)//first trade whatever condition, for one cycle only add "AND STRATEGYPROFIT=0" on lne 34if NOT ONMARKET AND (c1)=1 AND (c2)=1 thenBUY amount LOT AT MARKETendif// case BUY - add orders on the same trendif longonmarket and close-tradeprice(1)>=gridstep thenBUY 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)*sd//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 risk 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 = 0endifAnd shorts;
CFTA - Short HA Sq123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778/// Definition of code parametersdefparam preloadbars =10000DEFPARAM CumulateOrders = true // Cumulating positions deactivatedSQ= call "Squeeze"[12, 1.5, 12, 1]HAC= call "HA Change"once RRreached = 0accountbalance = 10000 //account balance in money at strategy startriskpercent = 1 //whole account risk in percent%amount = 1 //lot amount to open each traderr = 2 //risk reward ratio (set to 0 disable this function)sd = 0.25 //standard deviation of MA floating profit//dynamic step gridminSTEP = 20 //minimal step of the gridmaxSTEP = 50 //maximal step of the gridATRcurrentPeriod = 150 //recent volatility 'instant' periodATRhistoPeriod = 3000 //historical volatility periodATR = averagetruerange[ATRcurrentPeriod]histoATR= highest[ATRhistoPeriod](ATR)resultMAX = MAX(minSTEP*pipsize,histoATR - ATR)resultMIN = MIN(resultMAX,maxSTEP*pipsize)gridstep = (resultMIN)// Conditions to enter short positionsc11 = (SQ > 0)c12 = (HAC CROSSES UNDER 0)//first trade whatever condition, for only one cycle add "AND STRATEGYPROFIT=0" on line 34if NOT ONMARKET AND (c11)=1 AND (c12)=1 thenSELLSHORT amount LOT AT MARKETendif// case SELL - add orders on the same trendif shortonmarket and tradeprice(1)-close>=gridstep 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)*sd//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 risk reward ratio has been reachedif onmarket and RRreached=1 thenif floatingprofit crosses under BBfloatingprofit thenEXITSHORT AT MARKETendifendif//resetting the risk reward reached variableif not onmarket thenRRreached = 0endifRemember to be mindful of line 34 to set or avoid recurring cycles, recurring is great for testing but risky for live trading, also note to increase most parameters if using on very low TF.
I hope you will find it useful 🙂
12/17/2017 at 7:32 PM #5589812/18/2017 at 7:28 PM #5601012/18/2017 at 7:44 PM #5601212/18/2017 at 8:40 PM #56015@ Rejo the code is exactly the same as I run without any problems, the only issue I can think of is that it might be caused by running PRT in French instead of English.
@ Henrik, sorry but I’m not sure what you mean, do you refer to having a stop order for taking profit? I guess we can implement that but since it is a discretionary system I prefer exiting manually to maximize profit or let the bollinger exit kick in, which in one way let us maximize profit to the extent that we stay in our position until we have retracement and ride the price movement all the way rather than exiting when it’s halfway since we rarely know when a move is done.
12/18/2017 at 9:00 PM #56021Hi Cfta!
Looked at your codes from the beginning when i was trying to make a “bombmatta” dont know what its called in english. I made some changes for the grid to buy on fixed prices and used your profit exit but changed it to be a stop order instead of sell at market.
Now when i try to explain i cant find the final codes but atleast two that explains fixed grid entry and exit calculation with stop order. so i copypasted the snippets i talked about so youll understand what i mean.
I just wanted to show you as your ideas made me come up with this. 🙂
Regards
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108//BREAKOUT////////////////////////////////////////////////////////////////////////K=highest[X](close) //IC*0.25//FÖRVÄNTAD DAGLIG RÖRELSE (PROCENT) = INKÖP/STOP////////////////////////DP=0.007//AVSTÅND INKÖP MATTA / STOP////////////////////////////////////////////////IC=((CLOSE*DP)/4)BOMHAST=IC//-------------------------------------------------------------------------//graph close as "close"//GRAPH K AS "BREAKOUT"//GRAPH START AS "START"//GRAPH IC AS "NORMALSPANN"//GRAPH floatingprofit as "floating profit"//GRAPH BBfloatingprofit as "BB Floating Profit"//-------------------------------------------------------------------------////////////////////////////////////////////////////////////////////////////////////////// Conditions to enter long positions//////////////////////////////////////////////////////////////////////////////////////////TREND INDI////////////////////////////////////////////////////////////////////////TFC=1indicator1 = dema[18*TFC](ROC[13*TFC](ExponentialAverage[1*TFC]))indicator2 = dema[18*TFC](ROC[13*TFC](ExponentialAverage[1*TFC]))c1 = (indicator1 > indicator2[1])//SET STOP ORDER INDI////////////////////////////////////////////////////////////////////////TFC2=15indicator10 = dema[20*TFC2](ROC[25*TFC2](ExponentialAverage[1*TFC2]))indicator20 = dema[20*TFC2](ROC[25*TFC2](ExponentialAverage[1*TFC2]))c10 = (indicator10 > indicator20[1])//c20 = (indicator10[1] < indicator20[2]) AND C20IF c1 AND C10 AND NOT ONMARKET THENSTART=KBUY 1 CONTRACT AT K STOPBUY 1 CONTRACT AT CLOSE+K+BOMHAST STOPBUY 2 CONTRACT AT CLOSE+K+(BOMHAST*2) STOP//BUY 4 CONTRACT AT START+(BOMHAST*3) STOPENDIFIF c1 AND COUNTOFPOSITION=1 THENBUY 1 CONTRACT AT START+BOMHAST STOPBUY 2 CONTRACT AT START+(BOMHAST*2) STOP//BUY 4 CONTRACT AT START+(BOMHAST*3) STOPENDIFIF c1 AND COUNTOFPOSITION=2 THENBUY 2 CONTRACT AT START+(BOMHAST*2) STOP//BUY 4 CONTRACT AT START+(BOMHAST*3) STOPENDIF//IF c1 AND COUNTOFPOSITION=4 THEN//BUY 4 CONTRACT AT START+(BOMHAST*3) STOP//ENDIF////////////////////////////////////////////////////////////////////////////////////////// SAFETY STOPS MATTA////////////////////////////////////////////////////////////////////////////////////////// Stops and targetsif countofposition=1 thenSELL AT START-BOMHAST STOPENDIFif countofposition=2 thenSELL AT START STOPENDIFif countofposition=4 thenSELL AT START+BOMHAST STOPENDIF//if countofposition=8 then//SELL AT START+(BOMHAST*2) STOP//ENDIFfloatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize//actual trade gainsMAfloatingprofit = average[20](floatingprofit) //[ONMARKET]BBfloatingprofit = MAfloatingprofit - std[20](MAfloatingprofit)*1.8//0.25FPP= (BBfloatingprofit)/((pointvalue*countofposition/pipsize))+positionpriceif onmarket thenif FPP<CLOSE thenSELL AT FPP STOPendifENDIFGRAPH FPP AS "floatingprofit stop FPP"//GRAPH floatingprofit AS "floatingprofit"GRAPH CLOSE AS "Close"12/19/2017 at 11:16 AM #56054 -
AuthorPosts
Find exclusive trading pro-tools on