Grid orders with one combined stop loss and limit, can it be done?
- 104 - CFTA-Short-HA-BBW-1.itf
- 103 - CFTA-Short-HA-BBW.itf
- 102 - CFTA-Long-HA-BBW.itf
- 101 - HA-Change.itf
- 100 - Squeeze.itf
- 99 - CTFA-HA-SQ-Long-5-min-29122017-results.pdf
- 98 - CTFA-HA-SQ-Long-5m-29122017.itf
- 97 - Squeeze.itf
- 96 - squeeze-1.png
- 95 - squeeze.png
- 94 - Capture.jpg
- 93 - Screenshot_69.jpg
- 92 - CFTA-Cross.itf
- 91 - CFTA-Trend.itf
- 90 - CFTA-indi-comparison.png
- 89 - CFTA-2-sec-DAX-LOW-ver-3.11.itf
- 88 - CFTA-v3.0.itf
- 87 - Screenshot_38.jpg
- 86 - CFTA-indicator-v2.5.itf
- 85 - Screenshot_36.jpg
- 84 - CFTA-Screener-v1.5.itf
- 83 - Screenshot_35.jpg
- 82 - image1.png
- 81 - CFTA-indicator-v2.itf
- 80 - Screenshot_34.jpg
- 79 - CFTA-indicator-v1.5.itf
- 78 - coppock-EMA34.itf
- 77 - Screenshot_31.jpg
- 76 - Screenshot_2.jpg
- 75 - USDJPY-CFTA-SHORT.itf
- 74 - fcta-indicator.jpg
- 73 - CFTA-indicator.itf
- 72 - sim_DAX_1s_trades.png
- 71 - Proorder-DAX-Report.png
- 70 - Proorder-DAX-executed.png
- 69 - DAX-SETUP-and-Entry.png
- 68 - EURJPY-result.png
- 67 - OMX30.png
- 66 - tt-long2.png
- 65 - TT-long.png
- 64 - DOW-TS-20161013.png
- 63 - DOW-20161013.png
- 62 - ctfa.png
- 61 - Grid-step-error.png
- 60 - Trend-chaser-CCI-beta.png
- 59 - ADX-matrix.png
- 58 - Trend-Chaser-v.3.0-with-MM-Italy40-M1.png
- 57 - Trend-Chaser-v.3.0-Italy40-M1.png
- 56 - Grid-Orders-BBexit-DynamicStep.itf
- 55 - PRT-grid-error-25.png
- 54 - Squeeze-On-Screener.itf
- 53 - Grid-Orders-BBexit-DynamicStep.itf
- 52 - dynamic-step-grid-orders-DAX.png
- 51 - dynamic-grid-step-code.jpg
- 50 - Squeeze-Momentum-Indicator.itf
- 49 - PRT-grid-error-23.png
- 48 - PRT-grid-error-24.png
- 47 - PRT-grid-error-22.png
- 46 - PRT-grid-error-21.png
- 45 - PRT-grid-error-20.png
- 44 - PRT-grid-error-19.png
- 43 - PRT-grid-error-18.png
- 42 - PRT-grid-error-17.png
- 41 - PRT-grid-success-2.png
- 40 - 1-2.png
- 39 - BBexit-working-trading-money-management-system.jpg
- 38 - PRT-grid-error-15.png
- 37 - 1-1.png
- 36 - 1.png
- 35 - 2.png
- 34 - adding-orders-to-alex.png
- 33 - image2.png
- 32 - alex-fixed-profit-dax-15m.png
- 31 - alex-bb-exit-dax-15m.png
- 30 - ssgrind-bb-price-1.png
- 29 - Grid-Orders-cfta-with-BB-exit.itf
- 28 - without-BB-exit-system.png
- 27 - with-BB-exit-system.png
- 26 - PRT-grid-error-14.png
- 25 - Test-brekoutgrid.itf
- 24 - PRT-grid-progress-3-1.png
- 23 - GBPCAD-20160502.png
- 22 - GJ-BOJ-April.png
- 21 - Money-management.pdf
- 20 - Namnlös10.png
- 19 - PRT-grid-success.png
- 18 - Namnlös9.png
- 17 - Grid-Orders-cfta.itf
- 16 - grid-profitable-trades-long-positions.png
- 15 - grid-orders.png
- 14 - PRT-grid-progress-3.png
- 13 - PRT-grid-error-13.png
- 12 - PRT-grid-error-12.png
- 11 - PRT-grid-progress-2.png
- 10 - PRT-grid-error-11.png
- 9 - PRT-grid-progress-1.png
- 8 - PRT-grid-error-10.png
- 7 - backtest-prorealtime-grid-orders.png
- 6 - PRT-grid-error-9.png
- 5 - PRT-grid-error-8.png
- 4 - positionprice.jpg
- 3 - PRT-grid-error-2.png
- 2 - PRT-grid-error.png
- 1 - grid-pyramidal-orders-prorealtime.png
04/14/2016 at 8:38 PM #5409
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) stopendif
And 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=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 lossPercentage
In 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!
1 user thanked author for this post.04/14/2016 at 9:46 PM #541404/15/2016 at 3:16 PM #5440
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 #5482
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 #5487
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 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 #5489
Wow, you are really fast Nicolas, I’m impressed!
Sure thing, I will test it in real market conditions first thing on Monday morning and come back with an update.
Thanks a lot for your help and have a nice weekend.04/16/2016 at 5:37 PM #5499
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, Henrik04/18/2016 at 6:39 PM #5597
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 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 MARKETendifendif
However 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 #5603
Sorry 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 #5607
No 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 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) stopendif
In 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 #5623
I 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 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 newSLendif
POSITIONPRICE is really the average open price of the whole opened orders.04/19/2016 at 6:47 PM #5678
Thanks 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 #5680
About 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 ?04/20/2016 at 7:47 PM #5716
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?