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/19/2017 at 11:28 AM #56055
Sorry fellows, now I understand the problem rejo had.
Henrik, very interesting stuff, I will take a closer look soon, thanks for sharing 🙂
@Nicolas, here is the .itf-file. I stripped down another indicator from the library and modified it to only return one value.1 user thanked author for this post.
12/21/2017 at 10:34 AM #56218@Henrik, the entry parameters in your code looks interesting indeed, can you explain a bit more about them and perhaps post a pic of a chart showing entries? I tried to create a combined indicator of the entry parameters to get a better visual of valid entries but it is a bit tricky.
Regarding the carpet bombing method of doubling up on entries I am somewhat sceptical mostly because of stacking entries and doubling the position count gives a lower tolerance for retracements after entry and increase the risk of being stopped out.
12/29/2017 at 10:46 AM #56785Hi Cfta!
sorry for late response while im taking some time off. My codes are all inside bar instruction to make entry and exit insidebar with stop and limitorders for buy and profit secure exit. Then you can use bigger timeframe for signals. This is a way to get around prts limitations.
Happy New Year
Henrik
12/29/2017 at 6:24 PM #56832Hi all,
I have been observing the development of your system with great interest CTFA and I congratulate you with your work.
Your latest ‘long’ creation looks quite profitable on a 5 min timeframe in backtest and in walk forward analysis.
I took the liberty of fiddling around a bit with the HA and SQ cut-off value and also with the min max step. It is yet a little bit more profitable now.
The ideal situation would be to combine the long and the short version….
Congrats and Happy New Year,
Glen
12/30/2017 at 2:13 PM #56869Theoretically a better way to accumulate new orders would be to only add on pullbacks.
This would allow for better average entries and solve the problem of being stopped out on minor pullbacks.
Basically you still use the grid system to accumulate orders but only add after a pullback of x pips from the last high or low.
Since markets move in waves this should allow for better average entries.
12/30/2017 at 2:18 PM #5687001/01/2018 at 4:51 PM #57013Hi Henrik,
This sounds amazing to be able to circumvent the PRT limitations like this, at first I did not realize it was inside bar calculations. I have had some time off to and will go on a holiday tomorrow but I will look into it more once I’m back in a couple of weeks.
Juanj, only adding on pullbacks would end missing out on the fattest profit due to not adding on when price takes off fast in one direction and the pullback occurs first when the majority of the move is over. There is already a break even feature in the BB exit but it also let us keep a bit more profit.
01/29/2018 at 5:29 PM #60882@Henrik, finally I’m back with time for trading and developement, I have been looking into your code and also forward testing it and I think it looks very promising.
Do you think it will be possible to include entry based on HA Change and Squeeze? I have been trying to code it myself but can’t seem to figure out how to code it as an inside bar calculaction, I also had some issues with divided by zero errors. I think Squeeze in particular is very important to reduce entries during ranging and sideways movement.
It would be great if you could look into it since inside bar calculations create amazing opportunities for us 🙂
01/30/2018 at 9:47 PM #61025Hi Cfta!
The differens is that you set your buy and exit orders with stop and limit orders. The indicators are still limited to the timeframe you choose. I dont have any time right now but i can se if i can build in this stoporderway into your code.
Regards Henrik
02/01/2018 at 5:00 PM #61208Hello Henrik,
Okay that makes sense. No worries I look forward to your feedback when you have time to look into it.
I made some slight adjustments to your code by translating some of the phrases so it will be easier for our friends here to use and improve. I also tried to reverse the code to have a version for shorts but have not managed yet since it enters into 4 contracts right away.
Long which is working as intended;
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108//BREAKOUT////////////////////////////////////////////////////////////////////////K=highest[1](close) //IC*0.25//EXPECTED DAILY RANGE (PERCANTAGE) = ENTRY/STOP////////////////////////DP=0.007//GRID STEP DISTANCE/ STOP////////////////////////////////////////////////IC=((CLOSE*DP)/4)GRIDSTEP=IC//-------------------------------------------------------------------------//graph close as "close"//GRAPH K AS "BREAKOUT"//GRAPH START AS "START"//GRAPH IC AS "AVERAGE RANGE"//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+GRIDSTEP STOPBUY 2 CONTRACT AT CLOSE+K+(GRIDSTEP*2) STOP//BUY 4 CONTRACT AT START+(GRIDSTEP*3) STOPENDIFIF c1 AND COUNTOFPOSITION=1 THENBUY 1 CONTRACT AT START+GRIDSTEP STOPBUY 2 CONTRACT AT START+(GRIDSTEP*2) STOP//BUY 4 CONTRACT AT START+(GRIDSTEP*3) STOPENDIFIF c1 AND COUNTOFPOSITION=2 THENBUY 2 CONTRACT AT START+(GRIDSTEP*2) STOP//BUY 4 CONTRACT AT START+(GRIDSTEP*3) STOPENDIF//IF c1 AND COUNTOFPOSITION=4 THEN//BUY 4 CONTRACT AT START+(GRIDSTEP*3) STOP//ENDIF////////////////////////////////////////////////////////////////////////////////////////// SAFETY STOPS MATTA////////////////////////////////////////////////////////////////////////////////////////// Stops and targetsif countofposition=1 thenSELL AT START-GRIDSTEP STOPENDIFif countofposition=2 thenSELL AT START STOPENDIFif countofposition=4 thenSELL AT START+GRIDSTEP STOPENDIF//if countofposition=8 then//SELL AT START+(GRIDSTEP*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"Short version which is not working properly yet;
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108//BREAKOUT////////////////////////////////////////////////////////////////////////K=highest[1](close) //IC*0.25//EXPECTED DAILY RANGE (PERCANTAGE) = ENTRY/STOP////////////////////////DP=0.007//GRID STEP DISTANCE/ STOP////////////////////////////////////////////////IC=((CLOSE*DP)/4)GRIDSTEP=IC//-------------------------------------------------------------------------//graph close as "close"//GRAPH K AS "BREAKOUT"//GRAPH START AS "START"//GRAPH IC AS "AVERAGE RANGE"//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=KSELLSHORT 1 CONTRACT AT K STOPSELLSHORT 1 CONTRACT AT CLOSE+K-GRIDSTEP STOPSELLSHORT 2 CONTRACT AT CLOSE+K-(GRIDSTEP*2) STOP//BUY 4 CONTRACT AT START+(GRIDSTEP*3) STOPENDIFIF c1 AND COUNTOFPOSITION=1 THENSELLSHORT 1 CONTRACT AT START-GRIDSTEP STOPSELLSHORT 2 CONTRACT AT START-(GRIDSTEP*2) STOP//BUY 4 CONTRACT AT START+(GRIDSTEP*3) STOPENDIFIF c1 AND COUNTOFPOSITION=2 THENSELLSHORT 2 CONTRACT AT START-(GRIDSTEP*2) STOP//BUY 4 CONTRACT AT START+(GRIDSTEP*3) STOPENDIF//IF c1 AND COUNTOFPOSITION=4 THEN//BUY 4 CONTRACT AT START+(GRIDSTEP*3) STOP//ENDIF////////////////////////////////////////////////////////////////////////////////////////// SAFETY STOPS MATTA////////////////////////////////////////////////////////////////////////////////////////// Stops and targetsif countofposition=1 thenEXITSHORT AT START+GRIDSTEP STOPENDIFif countofposition=2 thenEXITSHORT AT START STOPENDIFif countofposition=4 thenEXITSHORT AT START-GRIDSTEP STOPENDIF//if countofposition=8 then//SELL AT START+(GRIDSTEP*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 thenEXITSHORT AT FPP STOPendifENDIFGRAPH FPP AS "floatingprofit stop FPP"//GRAPH floatingprofit AS "floatingprofit"GRAPH CLOSE AS "Close"02/19/2018 at 8:19 PM #63211@Henrik, I have been to trying to develope your code further and also run it live for testing but I keep getting the divided by zero error and has not managed to fix or work around it. Even if you are a little short on time do you think you could take a look to see if you can figure out the divided by zero problem so we can forward test the current code?
Everyone with decent coding skills is welcome to help, with real time stops and grid entries the system has huge potential 🙂
02/19/2018 at 11:44 PM #63234Hi Cfta!
Nice to here that you are looking in to it. I’ll try to clean up my stopporder version so that we get rid of the dbz error ! This one was only long and I havnt tried for shorts. But I’ll look into it.
Can you share the ha and squeeze indicators as itf:s so that we have the same material.
Regards
Henrik
02/20/2018 at 8:12 AM #6325002/20/2018 at 1:56 PM #63294Hello fellows,
Thanks for the fast replies, here are the itf. files. The Squeeze is the more important one, the HA Change indicator is very useful but I think we can get rid of a lot of false signals if we replace it with Heiken Ashi Smoothed instead, if you think we can include it in the code. Maybe we can use this version Nicolas has made already (though we don’t need the bar painting function which I guess requires more calculations, it would be sufficient if it returns a 1 or -1 value but let’s use whatever is easier to code);
https://www.prorealcode.com/prorealtime-indicators/hpt-heikin-ashi-smoothed/
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253//PRC_HPT Heikin Ashi Smoothed | indicator//25.04.2017//Nicolas @ www.prorealcode.com//Sharing ProRealTime knowledge//translated from MT4 indicator code//---settings//MaPeriod=6//MaPeriod2=2//---end of settingsonce maOpen=Openonce maClose=Closeonce maLow=Lowonce maHigh=Highif barindex>0 thenmaOpen=(maOpen[1]*(MAperiod-1)+Open)/MAPeriodmaClose=(maClose[1]*(MAperiod-1)+Close)/MAPeriodmaLow=(maLow[1]*(MAperiod-1)+Low)/MAPeriodmaHigh=(maHigh[1]*(MAperiod-1)+High)/MAPeriodhaOpen=(ExtMapBuffer5[1]+ExtMapBuffer6[1])/2haClose=(maOpen+maHigh+maLow+maClose)/4haHigh=Max(maHigh, Max(haOpen, haClose))haLow=Min(maLow, Min(haOpen, haClose))if (haOpen<haClose) thenr=0g=191b=255ExtMapBuffer7=haLowExtMapBuffer8=haHighelser=255g=10b=0ExtMapBuffer7=haHighExtMapBuffer8=haLowendifExtMapBuffer5=haOpenExtMapBuffer6=haCloseExtMapBuffer1=weightedaverage[MAperiod2](ExtMapBuffer7)ExtMapBuffer2=weightedaverage[MAperiod2](ExtMapBuffer8)ExtMapBuffer3=weightedaverage[MAperiod2](ExtMapBuffer5)ExtMapBuffer4=weightedaverage[MAperiod2](ExtMapBuffer6)endifDRAWCANDLE(ExtMapBuffer3,ExtMapBuffer2,ExtMapBuffer1,ExtMapBuffer4) coloured(r,g,b)short = ExtMapBuffer7[1]>ExtMapBuffer8[1] and ExtMapBuffer7[2]<ExtMapBuffer8[2] and ExtMapBuffer7[0]>ExtMapBuffer8[0]long = ExtMapBuffer7[1]<ExtMapBuffer8[1] and ExtMapBuffer7[2]>ExtMapBuffer8[2] and ExtMapBuffer7[0]<ExtMapBuffer8[0]RETURN long as "long signal", short as "short signal"03/15/2018 at 10:12 AM #65344Hi fellows,
I have been developing the strategy further and made some progress thanks to the new marvelous Heiken Ashi of higher timeframes indicator developed by Nicolas;
https://www.prorealcode.com/prorealtime-indicators/heikin-ashi-higher-hourly-timeframe/
The below code is intended to be run M1 TF. The HA Change indicator has been posted here on the last couple of pages. Squeeze has been substituted for Bollinger Bandwidth which is a default indicator on PRT, it has a 20 period SMA on it.
Conditions to go long are; HA Change and HA of higher TF (1) to be above zero and for BBW to be above its SMA and for the current period to be above the previous period.
Conditions to go short are opposite for HA Change and HA of higher TF but the same for BBW and its SMA.
Also note that I have set new conditions for adding on to a trade, “countofposition<3” on line 41, of course this can be removed or set at each traders discretion. BBW to be above its SMA and for the current period to be above the previous period.
Exit is set to when HA of higher TF crosses zero. This seem to have nullified the BB Exit, I would like to have both in place but can’t figure out how to code it, advice is welcome.
If Nicolas or any other skilled coder find time and manages to adapt the HA of higher TF for minutes we can easily make this strategy even better, for instance running it on M1 and use HA of higher TF for H1 as filter and M15 for entries and exits.
PS. We are only one month from this thread’s 2 year anniversary 🙂
Long;
CFTA - Long HA BBW1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798/// Definition of code parametersdefparam preloadbars =10000DEFPARAM CumulateOrders = true // Cumulating positions deactivatedHAC= call "HA Change"HAH= call "PRC_Heikin Ashi higher TF"[1]BollBW= 3*std[20](close)/WilderAverage[20](close)BollSMA= WilderAverage[20](3*std[20](close)/WilderAverage[20](close))once RRreached = 0accountbalance = 10000 //account balance in money at strategy startriskpercent = 2 //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.1 //standard deviation of MA floating profit//dynamic step gridminSTEP = 30 //minimal step of the gridmaxSTEP = 100 //maximal step of the gridATRcurrentPeriod = 300 //recent volatility 'instant' periodATRhistoPeriod = 6000 //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 positions. Add "AND STRATEGYPROFIT=0" on line 40 for one cycle only.c1 = (HAC > 0)c2 = (HAH > 0)c3 = (BollBW > BollSMA)c4 = (BollBW > BollBW[1])IF NOT ONMARKET AND c1 AND c2 AND c3 AND c4 THENBUY 1 LOT AT MARKETENDIF// case BUY - add orders on the same trendif longonmarket and c3 and c4 and countofposition<3 and close-tradeprice(1)>=gridstep thenBUY amount LOT AT MARKETendif// Conditions to exit long positionsc5 = (HAH[1] CROSSES UNDER 0)IF c5 THENSELL 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 = 0endif//GRAPH floatingprofit as "float"//GRAPH RRreached as "rr"//GRAPH floatingprofit as "floating profit"//GRAPH BBfloatingprofit coloured(255,0,0) as "BB Floating Profit"//GRAPH positionprice-mindistancetoclose//GRAPH moneyrisk//GRAPH onepointvaluebasket//GRAPH gridstepShort;
CFTA - Short HA BBW1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798/// Definition of code parametersdefparam preloadbars =10000DEFPARAM CumulateOrders = true // Cumulating positions deactivatedHAC= call "HA Change"HAH= call "PRC_Heikin Ashi higher TF"[1]BollBW= 3*std[20](close)/WilderAverage[20](close)BollSMA= WilderAverage[20](3*std[20](close)/WilderAverage[20](close))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.1 //standard deviation of MA floating profit//dynamic step gridminSTEP = 25 //minimal step of the gridmaxSTEP = 100 //maximal step of the gridATRcurrentPeriod = 300 //recent volatility 'instant' periodATRhistoPeriod = 6000 //historical volatility periodATR = averagetruerange[ATRcurrentPeriod]histoATR= highest[ATRhistoPeriod](ATR)resultMAX = MAX(minSTEP*pipsize,histoATR - ATR)resultMIN = MIN(resultMAX,maxSTEP*pipsize)gridstep = (resultMIN)// Conditions to short positions. Add "AND STRATEGYPROFIT=0" on line 40 for one cycle only.c1 = (HAC < 0)c2 = (HAH < 0)c3 = (BollBW > BollSMA)c4 = (BollBW > BollBW[1])IF NOT ONMARKET AND c1 AND c2 AND c3 AND c4 THENSELLSHORT 1 LOT AT MARKETENDIF// case sell add orders on the same trendif shortonmarket and c3 and c4 and countofposition<3 and close-tradeprice(1)>=gridstep thenSELLSHORT amount LOT AT MARKETendif// Conditions to exit short positionsc5 = (HAH[1] CROSSES OVER 0)IF c5 THENEXITSHORT 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 = 0endif//GRAPH floatingprofit as "float"//GRAPH RRreached as "rr"GRAPH floatingprofit as "floating profit"GRAPH BBfloatingprofit coloured(255,0,0) as "BB Floating Profit"//GRAPH positionprice-mindistancetoclose//GRAPH moneyrisk//GRAPH onepointvaluebasket//GRAPH gridstep -
AuthorPosts
Find exclusive trading pro-tools on