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/25/2016 at 7:31 PM #8018
So another day of real time testing, as I mentioned in my post yeterday the BB exit is working great so far but the regular SL at 1 % does not seem to be working. The Nikkei trade I opened on Monday and wrote about was not closed at -2% neitherr was a GBPJPY trade which i took today setting the SL at -1 %, the floating loss reached about -2.3 % before I stopped the system manually. Please have a look guys to see what might be the problem…
@Brage & Simon, sure thing guys there is so much code around it is starting to get tricky to keep track of all of them. These are the ones I have been testing live this week note that I change the parameters depending on which system I run it on;Long;
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556//-------------------------------------------------------------------------// Main code : LONG GRID BB Exit//-------------------------------------------------------------------------defparam 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 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)*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//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 = 0endifShort;
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556//-------------------------------------------------------------------------// Main code : Grid Short BB Exit//-------------------------------------------------------------------------defparam 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 thenSELLSHORT 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//stoploss trigger when risk reward ratio is not met alreadyif onmarket and RRreached=0 thenEXITSHORT AT positionprice-mindistancetoclose STOPendif//stoploss trigger when risj 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 = 0endif1 user thanked author for this post.
05/25/2016 at 7:43 PM #8022Because you didn’t change the line 32 to:
1floatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize //actual trade gainsThat’s the reason why your loss is not well calculated.
1 user thanked author for this post.
05/25/2016 at 8:04 PM #802605/25/2016 at 8:37 PM #8028Does it only take one set of trades or only one single order? It’s only supposed to run one cycle after being started and not take any new trades until started manually again, in addition keep in mind to run it on low timeframes otherwise it will for conditions to be met and for the candle to close.
05/25/2016 at 9:36 PM #803605/25/2016 at 10:09 PM #8045Hi,
I am following your work as it progresses and it is positively AWESOME! But I have to agree with Davidp13: if you run the code like this, it only produces 1 (one) trade, not one cycle.
Therefore, if your remove the expression STRATEGYPROFIT=0, it keeps going on. However, as ctfa has pointed out, the idea is that this code finishes a whole cycle of trades, not just one trade. After the cycle, it has to be started manually again. If you remove the STRATEGYPROFIT=0 expression, it keeps going on and that is not the idea either. So, I respectfully conclude that something isn’t perfect with the AND STRATEGYPROFIT=0 condition.
I hope this helps somewhat.
Kind regards
05/26/2016 at 7:30 AM #8054Good morning traders, I still have issues with JPY pairs in real time testing since the SL kick in way too early, do anyone have an idea what might be the issue?
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 = 15 //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)*pipsizeendif//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 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 = 0endif05/26/2016 at 8:23 AM #8063Hi guys please read all the topic and not only last page. We have explained why it takes only one sets of entry the code posted by nicolas!
I have shared a version that doesn’t stop working after the first entry.
05/26/2016 at 8:35 AM #8068That’s a very long topic now, maybe if someone plan to make a fork with this code with other concept and strategy, he’s welcome to open a new topic. This forum belong to the community. Me and other coders here can help everyone to make things better, but since I have only one brain 🙂 , please make things happen by yourself, I’ll be not too far.
05/26/2016 at 12:46 PM #8123Because the floating profit is calculated in Yen… And it’s the case in any other forex pairs (pipvalue = 1$, 1CHF, 1PLN), pip value is returned in the current currency of the pair and since Japanese pairs have only 3 digits, the pipvalue = 100 Yen.. So all money management has to be reviewed for this case.. I just came across the same error elsewhere.. Need to think for the better way to fix this issue, sorry for that.
05/26/2016 at 5:20 PM #8168I updated the code yesterday as you adviced but I still have problems to make the SL work, today I tried it on GBPAUD set to kick in at -1 % but it didn’t trigger. I have been paying attention to update the corrections and changes of the code, I may have missed something but I can’t figure out what. This is the section that I changed;
123456789//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=1endifRegarding the floating profit issue calculation with the Yen I would not mind having several sets of systems adapted for different assets if it is easier to fix than one system which works for all, such as one for indices, another for FX pairs with one digit and five decimals, a third one for Yen pairs and other crosses with more than one digit and so on.
Is anyone else testing in real market conditions and having the same problem?
Today I will start testing david-1984’s code too 🙂
05/26/2016 at 7:03 PM #817305/26/2016 at 7:11 PM #8176No the profit did not reach the risk reward ratio, whenever it has reached the ratio the BB exit seem to work perfectly, it is when one or a few entry orders are triggered and price then turns around going the wrong way.
The first type of SL fixed at X % worked great for the first code you wrote with 1 % SL of account balance before we implemented the BB exit, could it be possible to integrate parts of that code into the current BB exit code?
05/26/2016 at 7:31 PM #817705/26/2016 at 7:44 PM #8181I just checked and entered the same time and parameters as the GBPAUD trades from earlier today but in Probacktest the SL worked perfectly. I ran it on both 1 minute and 1 second, only differnce was that one more trade was entered on 1 seconed and the SL kicked in accordingly at about 33 pips below the average price of the three positions.
My Nikkei trade from Tuesday which did not stop out yesterday in real time worked fine in test now.
-
AuthorPosts
Find exclusive trading pro-tools on