Grid orders with one combined stop loss and limit, can it be done?

Viewing 15 posts - 166 through 180 (of 308 total)
  • Author
    Posts
  • #9976 quote
    Nicolas
    Keymaster
    Master

    Hi siaoman,

    The code I posted in the last version is a dummy strategy for further development, it is not suitable to be traded “as is” because of needs to find good entries, as already discussed. The commented codes are a part of this “testing” strategy.

    Also, as you noticed, there is only one cycle of trades because of the test on STRATEGYPROFIT=0, that you have commented in lines 28 and 32 of your code.

    #9977 quote
    cfta
    Participant
    Senior

    Nicolas, the forward testing of the dynamic grid step looks very promising and the system appear to adjust the entries to the current volatility so both the idea and the coding works great 🙂

    However one issue we need to take into account is that the system should preferably be run on the 1 second timeframe for the most accurate entries but on that timeframe it is difficult to measure the volatility properly and the default ATRcurrentPeriod of 5 does not have much of a meaning measuring the volatility over the last 5 seconds. Of course we can adjust these parameters, for instance if I would like to measure ATR on the 5 min timeframe I can multiply the value by 300 (60 seconds * 5 min = 300) and change the parameter accordingly, do you this is a good way of dealing with the issue or would it be better to adjust the ATR function of the system to measure the ATR on a higher timeframe than the system is running on?

    @ siaoman, the system is only intended to run for one cycle until it is started manually again otherwise it would be too much of a gamble to leave it running, if markets are ranging or choppy with high volatility one could easily blow a quarter of one’s account in an hour.

    BTW now there are only 7 matches left in the Euro Cup so I will become more active here again than I’ve been the last couple of weeks 🙂

    #9983 quote
    siaoman
    Participant
    Average

    Cheers for the response Nicolas. I had a feeling that was the case. I’m going to continue testing the system to enter based on some entry rules I have, but so far the dynamic grid works really well. If I get something to work well, I’ll post it here in spirit of sharing!

    Thanks again.

    #9984 quote
    Nicolas
    Keymaster
    Master

    @cfta

    Yes you can adjust the ATR period the way you do by multiplying the ATR period, that’s why I left ATR period in parameters, for everyone set to their needs. I’m used to say that I make the weapons but I rarely use them on the battlefield 🙂

    #10113 quote
    simon_json
    Participant
    Average

    @cfta Sorry, its from a friend. I have not tested it.

    #10250 quote
    cfta
    Participant
    Senior

    Nicolas, the testing goes on and for the most part it looks great but there are a couple of issues that might turn out to be a problem.

    The dynamic step grid min and max grid step seem to work perfectly for indices such as the DAX but not at all for FX pairs. I have noticed this in both backtesting and in real time, for a sample I ran a test on GBP/USD with min grid step 10 and max 50 but some trades ended up being taken with just 2 pips in between, I thought this might be a decimal issue and increased the step tenfold to 100 and 500 but it didn’t seem to solve the problem and trades were still entered at the same small grid steps. Please look into how we can solve it 🙂

    The other issue is the one in my last post about multiplying the number of ATR periods which turned out to be a problem for me when reaching high numbers with an error message saying historic bars were insufficient even though I increased the defparam bars to an even higher number, this might be due to my inexperience with PRT though…

    Here’s the code I used for testing shorts in case I erased or changed something by accident;

    defparam preloadbars = 3000
    once RRreached = 0
    
    //parameters
    accountbalance = 10000 //account balance in money at strategy start
    riskpercent = 2 //whole account risk in percent%
    amount = 1 //lot amount to open each trade
    rr = 3 //risk reward ratio (set to 0 disable this function)
    
    //dynamic step grid
    minSTEP = 10 //minimal step of the grid
    maxSTEP = 50 //maximal step of the grid
    ATRcurrentPeriod = 25 //recent volatility 'instant' period
    ATRhistoPeriod = 500 //historical volatility period
    
    ATR = averagetruerange[ATRcurrentPeriod]
    histoATR= highest[ATRhistoPeriod](ATR)
    
    resultMAX = MAX(minSTEP*pipsize,histoATR - ATR)
    resultMIN = MIN(resultMAX,maxSTEP*pipsize)
    
    gridstep = ROUND(resultMIN)
    
    //first trade whatever condition
    if NOT ONMARKET AND close<close[1] AND STRATEGYPROFIT=0 then
    SELLSHORT amount LOT AT MARKET
    endif
    
    // case SELL - add orders on the same trend
    if shortonmarket and tradeprice(1)-close>=gridstep*pipsize then
    SELLSHORT amount LOT AT MARKET
    endif
    
    //money management
    liveaccountbalance = accountbalance+strategyprofit
    moneyrisk = (liveaccountbalance*(riskpercent/100))
    if onmarket then
    onepointvaluebasket = pointvalue*countofposition
    mindistancetoclose =(moneyrisk/onepointvaluebasket)*pipsize
    endif
    //floating profit
    floatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize //actual trade gains
    MAfloatingprofit = average[20](floatingprofit)
    BBfloatingprofit = MAfloatingprofit - std[20](MAfloatingprofit)*2
    
    //floating profit risk reward check
    if rr>0 and floatingprofit>moneyrisk*rr then
    RRreached=1
    endif
    
    
    //stoploss trigger when risk reward ratio is not met already
    if onmarket and RRreached=0 then
    EXITSHORT AT positionprice-mindistancetoclose STOP
    endif
    
    //stoploss trigger when risj reward ratio has been reached
    if onmarket and RRreached=1 then
    if floatingprofit crosses under BBfloatingprofit then
    EXITSHORT AT MARKET
    endif
    EXITSHORT AT positionprice-mindistancetoclose STOP
    endif
    
    //resetting the risk reward reached variable
    if not onmarket then
    RRreached = 0
    endif
    

    For everyone following the developement of the system I’m happy to share that I have been practicing using it for intraday trades with small grid step, it takes more time and patience but when the right move comes we can easily harvest 5-10 % in an hour or two 🙂

    PRT-grid-error-25.png PRT-grid-error-25.png
    #10260 quote
    Nicolas
    Keymaster
    Master

    Thank you for your feedback. Just spotted the problems for the dynamic step grid, my fault! 🙂

    The line 22 should be replace with:

    gridstep = (resultMIN)

    Because ROUND can’t round decimal number.

    Also the instructions “pipsize” must be deleted from the add orders conditions because the dynamic step is already calculated this way (with pips decimal numbers).

    Please find attached the fixed version.

    cfta thanked this post
    Grid-Orders-BBexit-DynamicStep.itf
    #10384 quote
    Brage
    Participant
    Senior

    Hi cfta

    Interesting that you have tested it on intraday trends with promising results. I’ve tested to run it on the swedish omx30 with signals on 5-min chart and then grid orders on 1 minute and 1 second. My experience so far is that although being right on the direction, when being filled and building the position and therefore adjusting the stop and getting it closer to the actual price, the position gets very sensitive for a minor countermove and therefore often get stopped out before reaching my target. I asume that I need to adjust my values (grid step, s/l, target, atr-period and so on) and need some input on how to think. Have you tested on the omx30 and if so what values do you use? If not what timeframes and settings have you tested with good results on other indices? Any other ideas on how to set and test values to get better results?

    Thanks to you and Nicolas for your continued work on this promising idea:)

    #10386 quote
    Nicolas
    Keymaster
    Master

    Because the stoploss is continuously moving to be 1% of your equity, while adding orders, at some point it is very close to the price. So market whipsaws can often trigger the stoploss.

    #10391 quote
    Brage
    Participant
    Senior

    Thanks Nicolas

    I understand. Then one need to find out the best relationship between the s/l, target and the other values so that you can take a small countermove in the trend you ride just before your target is hit. Would a wider stoploss be better in this case? Feels like it is necessary to combine grid-orders with an entry strategy into a complete trading system to be able to get a real backtest. For the moment I do it manually with some ideas but it is not effective enough.


    @cfta
    Do you set fixed targets when you run your tests or do you only use the built in exits?

    #10428 quote
    cfta
    Participant
    Senior

    Thanks for the fixed code Nicolas 🙂

    @ Brage, remember that the initial idea behind this strategy is to look for swing trades on the H4 charts with 20 pip grid steps wich provides a decent margin for the trade to trend in one direction and turn profitable before being stopped out, preferably by the BB exit securing some profit rather than losing 1 %. Either way this system requires a fairly high degree of accuracy in picking entries in which the market will go one way with only minor retracements to work, the last couple of months the market conditions have been quite bad for this mostly related to the rash moves related to the brexit concerns.

    Bottom line is that the larger the grid step the smaller the risk of being stopped out, of course increasing the SL also reduce the risk of being stopped out but once you have built up a large position with 6-10 entries you will get stopped out fast by a moderate retracement anyway unless having a huge SL of 10-20 % which I wouldn’t recommend. My advice is to have a fairly low RR for the BB exit to kick in at 2 or 3 which will save you from a fair amount of stop outs and to start experimenting with the ATR settings of the dynamic grid step so entries will not be taken or only taken with large steps when the markets are choppy and stack up the orders once the price starts moving. Usually I trust the BB exit and SL to do their job but sometimes I stop the system manually if I reckon the price is about to turn and saving the extra profit before the BB exit.

    Here is a table I posted earlier in the thread for reference on how the SL mover closer to the average entry price;

    http://www.prorealcode.com/topic/grid-orders-with-one-combined-stop-loss-and-limit-can-it-be-done/page/3/#post-6728

    Brage thanked this post
    #10436 quote
    Brage
    Participant
    Senior

    Thanks for answers

    Will try larger timeframes and a lower rr and experiment more with the ATR settings. Had a couple of questions in a previous post. Have you tested on the omx30 and if so what values do you use? If not what timeframes and settings have you tested with good results on other indices? Do you prefer FX pairs for this code?

    #10468 quote
    cfta
    Participant
    Senior

    Welcome Brage!

    No I have never traded OMX 30 at all but it might be worth a try, in particular since it is almost 24 hours a day with IG and hence avoiding the worst gapping. I mostly focus on the DAX, Dow Jones and Nikkei for indices and spend about as much time on FX pairs with a bit more attention to the EUR and GBP crosses with AUD and CAD. I like the yen pairs most but have not yet gotten around to tweak the code to suit yen-pairs which I beleive are very suited for the system since they often have nice and smooth swings with moderate tracements and spikes. For TF I either view H4 or H1 for the lareger grid steps and then switch to 5m to pinpoint where to start the system and for smaller grid steps I look at m15 or m15 and then switch to m1 or 10 sec chart to start it up.

    Please share your progress on the different ATR settings!

    #11377 quote
    Nicolas
    Keymaster
    Master

    Hi everybody,


    @cfta
    , EURO is over! what about your tests?

    #11457 quote
    cfta
    Participant
    Senior

    Hey fellows,

    The EURO is over and so is my holiday though volatility has been irratic and choppy or virtually non existant so testing has been limited but slowly progressing. As mentioned previously focus has been on determining the most profitable settings for the dynamic step grid, I like to to run the system on 10 second to avoid delayed entries when the market is moving quickly and hence we need high number on the ATR period to get entries adjusted to the volatility. The most recent settings I have been testing is 10 and 50 for min and max grid step along with 500 and 10 000 for ATRcurrentperiod and ATRhistoperiod.

    Nicolas, the ATR measures the volatility of the market but not the direction do you think it would be useful to replace the ATR with ADX instead? In a dream scenario I would like to implement an ADX matrix measuring the ADX for multiple timeframes on multiple number of periods at once, on Metatrade I used to use such an indicator for manual entries which proved very useful, perhaps I should start a seperate thread for indicator development if we have a go at it?

Viewing 15 posts - 166 through 180 (of 308 total)
  • You must be logged in to reply to this topic.

Grid orders with one combined stop loss and limit, can it be done?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
cfta @cfta Participant
Summary

This topic contains 307 replies,
has 1 voice, and was last updated by OtherAttorney
1 year, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/14/2016
Status: Active
Attachments: 106 files
Logo Logo
Loading...