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.
-
-
04/14/2016 at 8:38 PM #5409
Hi Traders,
This is my first post in the forum so let me introduce myself. I discovered the user friendly and creative PRT platform a couple of months ago and made the switch from the more frustrating MT4 platform, I have been trading FX along with commodity and index CFDs for over 7 years and picked up a few good strategies along the way, one which I am going to share and ask for help coding.
The strategy is based on scaling into positions while maintaining the same risk by placing stop orders in the direction of the trend and momentum of the selected instrument, for instance earlier this week I was anticipating that EUR/USD would drop and at the time the market price was 1.1385. I would start the system placing an order to sell 1 contract at market price along with several sell stop orders to sell additional contracts at predetermined intervals by 20 pips, 1.1365, 1.1345 and 1.1325 etc.
The key for the strategy is to maintain the same risk as more contracts are added to the position, starting with a 1% risk on the initial market order taken at 1.1385 with 1% risk equaling 100 pips with a stop loss at 1.1485, once the second order is filled at 1.1365 the 1% risk is maintained by the stop loss being moved automatically to 1.1425 (50 pips from the average price at 1.1375), once the third order is filled at 1.1345 the 1% risk is maintaned by the stop loss being moved automatically to 1.1398 (33 pips from the new average price at 1.1365) and on it goes until reaching the desired number of contracts, in my case most often 5-10 contracts. In a perfect world I would like to include a function to set the stop loss to break even once reaching a certain percentage of profit but I have not figured that part out yet…
If going for 5 contracts at 20 pip intervalls the first 100 pips yield a 3% return and evry additional 20 pips yield 1 additional percent, for instance given that pullbacks and whipsaws are moderate and do not cause an exit by the stop loss a 240 pip move yield a 10% profit with only 1% risk, I say that is pretty sweet R:R and MM 🙂
I already have the code to do this on the frustrating and not so reliable MT4 platform but can it be coded for PRT?
A few weeks ago I thought of course it can be done! Now I am a bit less convinced since I have made two requests to the inhouse ProRealTime programmers and been given two different sets of code but neither of them works as intended for my IG account so now I am asking all of you and in particular Nicolas if it es even possible to code this?
This is the first code provided by the PRT programmers;
1234567891011121314151617181920212223242526272829303132333435363738394041424344stop1=round(close*1000)/1000if stop1 <= close thenstop1=stop1+0.001endiftradesum=0stop2=stop1+0.002stop3=stop2+0.002stop4=stop3+0.002stop5=stop4+0.002buy 1 share at stop1 stopbuy 1 share at stop2 stopbuy 1 share at stop3 stopbuy 1 share at stop4 stopbuy 1 share at stop5 stopif longonmarket thenfor i=0 to countoflongshares-1 dotradesum=tradesum+tradeprice(i)nextaveragetrade=tradesum/countoflongsharessell at averagetrade-((100/countoflongshares)*pointsize) stopendifAnd here is the second code;
1234567891011121314151617181920212223242526DefParam CumulateOrders = TrueOnce firstPrice = undefined// Change these settings accordinglyOnce lotSize = 10Once orderLimit = 5Once pipInterval = 10Once profitPercentage = 0.2Once lossPercentage = 0.5If CountofLongShares[1]=0 and CountofLongShares=lotSize thenfirstPrice = TradePriceElsif CountOfLongShares>lotSize thenSell At firstPrice StopEndifIf Not LongOnMarket thenBuy lotSize Lots At MarketElsif CountOfLongShares<orderLimit*lotSize thenBuy lotSize Lots At TradePrice+pipInterval*PointValue StopEndifSet Target %Profit profitPercentageSet Stop %Loss lossPercentageIn the first code the SL function seemed to be working fine but not the order placement which tended to place all orders virtually instantly at the same price, in second code the orders were sometimes place at the proper intervalls and sometimes at the same price as a previous order.
Please help me figure this out, I look forward to any replies and assistance!
Regards, Filip
1 user thanked author for this post.
04/14/2016 at 9:46 PM #541404/15/2016 at 3:16 PM #5440Hello,
Welcome here and thanks for sharing your strategy with everyone.
About your tests and bugs finding, have you spotted them in real market conditions or only in backtest please?
So the 1% stoploss would be dynamically compute at each bar for the whole basket orders, isn’t it?
04/16/2016 at 10:55 AM #5482Hi fellows,
I appreciate your interest and fast replies.
I have only been forward testing in real market conditions so far.
Yes, I suppose so regarding the stoploss or alternatively move automatically to a new fixed level once a new order is triggerd.
As mentioned above it seems that the first code is working better for the stoploss but the entry orders have been filled at the same or random levels…
04/16/2016 at 1:05 PM #5487Hi,
I rewrote the whole thing for the sell side only. I think it should make it, but test it with minimal lot size under real market conditions please.
I add 2 GRAPH instructions for displaying the new stoploss and the average price position of the whole basket for debugging purpose (see picture attached). Please have a look if it’s ok with your strategy.
12345678910111213141516171819// first trade whatever conditionif NOT ONMARKET AND close<close[1] thenSELLSHORT 1 LOT AT MARKETendif// case SELL - add orders on the same trendif tradeprice(1)-close>20*pipsize thenSELLSHORT 1 LOT AT MARKETendif// stoploss at 1% from the average price of the whole positions on marketif shortonmarket thennewSL = positionprice + (positionprice*0.01)if close>newSL thenEXITSHORT AT MARKETendifGRAPH newsl coloured(200,0,0) as "stop loss 1%"GRAPH positionprice coloured(100,100,100) as "position price"endif04/16/2016 at 2:14 PM #548904/16/2016 at 5:37 PM #5499HI!
This would work in small timeframe like 1 sec but not in 1h, 1d or 1w. The problem is that its hard to find god buy/sell conditions in small timeframes. How do you solve that? Im using IG version by the way. Is it possible to build indicators to simulate 15min, 1d, 1w price and then connect other inducaters to that simulated price timeframe?
Regards, Henrik
04/18/2016 at 6:39 PM #5597Hello Nicolas,
Unfortunately I lost my remote connection from work today so I have only been able to test for a couple of hours tonight. I learned that graphs are not allowed when testing in real market conditions so I did a slight modification to the code removing the graphs;
1234567891011121314151617// first trade whatever conditionif NOT ONMARKET AND close<close[1] thenSELLSHORT 1 LOT AT MARKETendif// case SELL - add orders on the same trendif tradeprice(1)-close>20*pipsize thenSELLSHORT 1 LOT AT MARKETendif// stoploss at 1% from the average price of the whole positions on marketif shortonmarket thennewSL = positionprice + (positionprice*0.01)if close>newSL thenEXITSHORT AT MARKETendifendifHowever I also did some backtesting and it seems like the code cause the positions to close at -1 % each instead of -1 % in total, see the attached screenshot, for the first set of trades with 10 sell orders the average price once all orders had been filled was 1.4162 and the-1 % in total SL should have kicked in at about 10 pips higher around 1.4172.
Nicolas do you have an idea how to fix this please?
04/18/2016 at 7:01 PM #5603Sorry for graph instruction, i always forget to remove it when i send code to people … 🙂 It’s only for debugging purpose and not allowed by ProOrder.
Well, I never used averaging down in real market conditions with IG. So I believe the problem is in the use of POSITIONPRICE which would return the average open price of the whole trades… Apparently not! I will ask PRT guys why.
So I believe the solution is in the first code you post (from ProRealTime services), so remove the lines 11 to 19 from my code and add this instead:
1234567891011if shortonmarket thenfor i=0 to countofshortshares-1 dotradesum=tradesum+tradeprice(i)nextaveragetrade=tradesum/countofshortsharessell at averagetrade-((100/countofshortshares)*pointsize) stopendif04/18/2016 at 9:21 PM #5607No worries I would probably forget it all the time too 🙂
I updated the code with some minor modifications replacing “lots” with “shares” to match your code with the first one I got;
123456789101112131415161718192021// first trade whatever conditionif NOT ONMARKET AND close<close[1] thenSELLSHORT 1 SHARE AT MARKETendif// case SELL - add orders on the same trendif tradeprice(1)-close>20*pipsize thenSELLSHORT 1 SHARE AT MARKETendifif shortonmarket thenfor i=0 to countofshortshares-1 dotradesum=tradesum+tradeprice(i)nextaveragetrade=tradesum/countofshortsharessell at averagetrade-((100/countofshortshares)*pointsize) stopendifIn backtesting the problem remains, five orders triggered but not exited until way past the total -1 %. Could it be due to the first code being a long only and yours being short only? Or is necessary for line 1 – 9 in the first code to be included for the SL to work?
04/18/2016 at 9:55 PM #560904/19/2016 at 9:39 AM #5623I have just tested once more, this time with long only orders, and set the exit at 1% and things go well under tester:
123456789101112131415161718// first trade whatever conditionif NOT ONMARKET AND close>close[1] thenBUY 1 LOT AT MARKETendif// case BUY - add orders on the same trendif close-tradeprice(1)>20*pipsize thenBUY 1 LOT AT MARKETendif// stoploss at 1% from the average price of the whole positions on marketif longonmarket thennewSL = positionprice - (positionprice*0.01)if close<=newSL thenSELL AT MARKETendifGRAPH newSLendifPOSITIONPRICE is really the average open price of the whole opened orders.
04/19/2016 at 6:47 PM #5678Thanks Nicolas, it looks like we are making a lot of progress.
I only removed a zero from (positionprice*0.001), the entry orders seem to be working good except for a minor issue that sometimes when the system is started it buys two contracts instead of one, in addition occasionally the intervals are a bit larger around 30 instead of 20 pips I guess this is due to dependency to close of the current candle?
If you have time it would be great if it is possible to a limit function to exit all positions for an instrument.
I have begun testing your latest code in real time market conditions so we will see if it works and I will give an update tomorrow!
04/19/2016 at 6:58 PM #5680About the 30 pips instead of 20, it is obviously about the one time test only on each bar.
And for the 2 contracts instead of 1 only at system start up, I have no clue right now… sorry. Maybe the entry position has to be better defined than a close versus close[1] ?
04/20/2016 at 7:47 PM #5716Hey guys,
I bought a new aparment today so I haven’t had as much time for testing as I wanted but I set up the system on NZD/JPY and Dax which have been running on real market conditions for about 24 hours now.
The good news is that the entries seem to work very good with orders being filled at every 20 pips with small differencies. The less good news is that the SL seem to kick in too early with (positionprice*0.001) at only -0.1 % but kick in too late with (positionprice*0.01) with floating loss of CAD 200 on a USD 10 000 account. I may have missed something in the calculations but so far I can’t figure it out.
NOTE! Due to my lack of experience of PRT and lack of coding knowledge I have not mentioned one of the most important features, since this strategy is meant to manage R:R and MM for manual trades, though taken automatically, it is crucial that no new entry orders are placed after a SL kicked in. The system must wait to be started again manually, how can this feature be added?
-
AuthorPosts
Find exclusive trading pro-tools on