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

Viewing 15 posts - 151 through 165 (of 308 total)
  • Author
    Posts
  • #9101 quote
    cfta
    Participant
    Senior

    I’m still working on the screener I mentioned in my last post but I havn’t been able to devote as much time as I would like to it. So far my parameters for a screener are;

    Triggers:

    • MACD Zero lag to cross the zero line and for candle to close, or;
    • Divergence MACD open source to give signal for divergence and close.

    Filters for the candle giving the trigger must close with;

    • Heiken Ashi candle in the same color as the trigger, green for buy and red for sell.
    • Envelopes ADX (10) to be above 25 and rising, the most recently closed candle must have a higher value than the previous one.

    An additional filter may be added and I’m somewhat uncertain about the ADX since it also filter out a few good entries, the point is to filter out ranging periods with entries which will not lead to substancial moves. ATR may work better but I don’t have much experience from using it so I’m uncertain about how to implement it.

    CCI divergence may also be an additional trigger.

    As Nicolas mentioned please share your ideas for developement or if any existing screeners would be useful 🙂

    #9102 quote
    davidp13
    Participant
    Average

    So are you mainly focusing on the entry signals at the moment?

    #9103 quote
    cfta
    Participant
    Senior

    @ davidp13

    Yeah mainly entry signals for the time being but also experimenting a bit with different uses of the system such as scalping small to medium market moves with smaller grid steps and more contracts at each entry, it can yield large gains very fast but also requires very well timed entries and virtually watching your screen for quite a while to find an entry and then keep on watching as the trade progresses.

    I have not done anything regarding the dynamic grid step since I’m almost clueless about the coding I leave that to Nicolas…

    #9104 quote
    davidp13
    Participant
    Average

    Personally I think the effort should go into managing the trade rather than finding the perfect entry. Tape readers don’t care about perfect all the care about is take profit off the table when the time is right. I have messed around with the money management code trying to find the best balance of when to close out or stay in across multiple systems and it seems very promising. Think we should work on the management aspect. Just my 2c

    #9131 quote
    Nicolas
    Keymaster
    Master

    This money management strategy is only reliable if the market don’t retrace too much.. So entries IMO are very important and must be made before the market ‘explode’. Use of many different periods Bollinger bands could be helpful, or Keltner/…any other band into Bbands.. I have don’t came across something very relevant for the moment. I need to spend time on it.


    @davidp13

    What are you calling money management aspect? Since it’s already built-in? You mean: exit trades at the right moment? A big problem here is the no possibility to manage trades individually, so it’s kind of rough to find the best exit.. 🙂

    #9179 quote
    simon_json
    Participant
    Average

    Hi friends!

    Maybe a Squeeze for entry?

    All the best!

    Robin, cfta and Patrick Andersson thanked this post
    Squeeze-Momentum-Indicator.itf
    #9377 quote
    Nicolas
    Keymaster
    Master

    At least, I had time to finish the dynamic grid step function. This is only an indicator for the moment, but it would be easy to integrate it into the whole function later, or if anyone got time to test, I would be grateful!

    As discussed this dynamic grid step has an inverted scale to the recent ATR volatility. So if the instant volatility increase, the grid step is dynamically reduced and vice-versa.

    I implemented lower and higher boundaries to the grid (minSTEP and maxSTEP), so we can limit the effect of the dynamic step to not go too much high or low (a grid step of only 1 point would mean nothing for example).

    The other parameter that can be changed at will is the ATRcurrentPeriod one, which represent the instant volatility of the instrument: understand that if this variable is low, the dynamic step would be quick to change its value or if this variable is higher, the dynamic step would be smoother.

    I attach a picture of the indicator for comprehension purpose 🙂

    Here is the code:

    //dynamic step grid
    minSTEP = 5 //minimal step of the grid 
    maxSTEP = 20 //maximal step of the grid 
    ATRcurrentPeriod = 5 //recent volatility 'instant' period
    ATRhistoPeriod = 100 //historical volatility period
    
    ATR = averagetruerange[ATRcurrentPeriod]
    histoATR= highest[ATRhistoPeriod](ATR)
    
    resultMAX = MAX(minSTEP*pipsize,histoATR - ATR)
    resultMIN = MIN(resultMAX,maxSTEP*pipsize)
    
    step = ROUND(resultMIN)
    
    RETURN ATR, step coloured(10,20,255)

    (edit: add a picture of the strategy with the dynamic grid step built-in, seems ok).

    cfta, Brage and Robin thanked this post
    dynamic-grid-step-code.jpg dynamic-grid-step-code.jpg dynamic-step-grid-orders-DAX.png dynamic-step-grid-orders-DAX.png
    #9404 quote
    cfta
    Participant
    Senior

    Great work Nicolas, I will start testing asap! Judging by the second picture above I guess you managed to integrate the dynamig step grid into the system? Can the function be pasted anywhere in the code or does it need to be added at any specific line? Since I’m so eager to try it I have tried integrating it myself but not quite managed…

    @ Simon, excellent suggestion with the Squeeze indicator, it’s new to me and I’m trying it with different settings to optimize it. I have also been trying Nicolas’s indicator Choppiness index but the Squeeze seem more suitable. In fact I have never noticed Keltner before but put the regular bands on my chart since those are a good substitut for Heiken Ashi Smoothed which I’m used to trade with have not managed to find for PRT yet.

    @ davidp13, I appreciate your input and two cents however since we have a fairly aggresive money management entries must be selected very carefully when the market conditions are right otherwise we will be stopped out very quick and there will be no trade to manage left 🙂

    So testing goes on and I will come back with updates however progress will be slower since I’m very distracted by the Euro football 🙂

    Brage and simon_json thanked this post
    #9407 quote
    Nicolas
    Keymaster
    Master

    Please find attached the complete code of the grid orders + dynamic step. For learning and further development purpose! 🙂

    cfta, Robin, Henrik and 8 others thanked this post
    Grid-Orders-BBexit-DynamicStep.itf
    #9429 quote
    cfta
    Participant
    Senior

    Awesome! I’ll start testing asap 🙂

    GraHal thanked this post
    #9820 quote
    simon_json
    Participant
    Average

    Hello friends!

    Here is Squeeze screener, from a friend. I have not tested it.


    @cfta
    How is the testing going? 🙂

    Squeeze-On-Screener.itf
    #9833 quote
    Sofitech
    Participant
    Master

    If somebody can post the code  (text code ) of the last Grid-Orders-BBexit-DynamicStep.itf pposted by Nicolas it would be great.  I have an Itf import problem… thanks

    #9837 quote
    simon_json
    Participant
    Average
    defparam preloadbars = 200
    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 = 4 //risk reward ratio (set to 0 disable this function)
    
    //dynamic step grid
    minSTEP = 5 //minimal step of the grid
    maxSTEP = 20 //maximal step of the grid
    ATRcurrentPeriod = 5 //recent volatility 'instant' period
    ATRhistoPeriod = 100 //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
    //BUY amount LOT AT MARKET
    //endif
    
    if NOT ONMARKET AND close<close[1] AND STRATEGYPROFIT=0 then
    SELLSHORT amount LOT AT MARKET
    endif
    
    // case BUY - add orders on the same trend
    if longonmarket and close-tradeprice(1)>=gridstep*pipsize then
    BUY 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
    
    //GRAPH floatingprofit as "float"
    //GRAPH RRreached as "rr"
    //GRAPH floatingprofit as "floating profit"
    //GRAPH BBfloatingprofit as "deviation of floating profit"
    //GRAPH positionprice-mindistancetoclose
    //GRAPH moneyrisk
    //GRAPH onepointvaluebasket
    GRAPH gridstep
    
    //stoploss trigger when risk reward ratio is not met already
    if onmarket and RRreached=0 then
    SELL AT positionprice-mindistancetoclose STOP
    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
    SELL AT MARKET
    EXITSHORT AT MARKET
    endif
    SELL AT positionprice-mindistancetoclose STOP
    EXITSHORT AT positionprice-mindistancetoclose STOP
    endif
    
    //resetting the risk reward reached variable
    if not onmarket then
    RRreached = 0
    endif
    
    #9859 quote
    cfta
    Participant
    Senior

    Hi fellows,

    @ Simon, thanks for sharing the screener but would you care to explain what it screens for? Judging by the name one might think it screens for Squeeze On but we want to detect when Squeeze changes from on to off right? 🙂

    As for the testing I have been very buys the last two weeks and have not had time for any real time testing at all, however next week I think I will manage and the backtests look good. I hope some more traders around here test it too in order to find the best parameters for ATR period along with min and max grid distance. There has been a general delay for a while now but more progress is to come!

    #9975 quote
    siaoman
    Participant
    Average

    Hi all,

    Firstly, I want to say a big thank you to cfta for bringing up this idea to ProRealCode, and also a massive thanks to Nicolas for spending so much time getting it to the state it’s currently in. I’ve been following this since the beginning and am amazed at how well it’s been developed, so big thanks to everyone.

    I’ve been testing this on a demo account (IG) while also forward-testing it at the same time. I’ve noticed that the .itf provided by Nicolas has the below code commented out. Was there a reason why it was commented out? Anyways, I realise the code is also used to initiate long trades so I’ve uncommented it and results seem quite good in back-testing.

    //first trade whatever condition
    //if NOT ONMARKET AND close>close[1] AND STRATEGYPROFIT=0 then
    //BUY amount LOT AT MARKET
    //endif

    However, I am encountering an issue when running it as a system. Somehow the system does not initiate a new trade when the first one either TP or SL. Therefore, if the system goes SHORT to start, then commences building up the grid and suddenly gets SL, the system will then just idle without creating a new trade to go LONG. Are others also experiencing this?

    I’ll paste my code below in case anyone wants to see it. I’ve added in 2 extra lines of code to; 1) Close all trades after a specific time, and 2) Only allow the system to open trades during a specified time (with start and end time).

    I’m also running this system on the 1second timeframe.

    defparam preloadbars = 2000
    DEFPARAM FLATAFTER = 232959 //NOTE: Added in to close all trades after this time
    once RRreached = 0
    
    //parameters
    accountbalance = 12000 //account balance in money at strategy start
    riskpercent = 1 //whole account risk in percent%
    amount = 2 //lot amount to open each trade
    rr = 2 //risk reward ratio (set to 0 disable this function)
    
    //dynamic step grid
    minSTEP = 5 //minimal step of the grid
    maxSTEP = 20 //maximal step of the grid
    ATRcurrentPeriod = 5 //recent volatility 'instant' period
    ATRhistoPeriod = 100 //historical volatility period
    
    ATR = averagetruerange[ATRcurrentPeriod]
    histoATR= highest[ATRhistoPeriod](ATR)
    
    resultMAX = MAX(minSTEP*pipsize,histoATR - ATR)
    resultMIN = MIN(resultMAX,maxSTEP*pipsize)
    
    gridstep = ROUND(resultMIN)
    
    IF OPENTIME >= 150000 AND OPENTIME <= 232959 THEN //NOTE: Added to only allow the system to trade during this time period
    
    //first trade whatever condition
    if NOT ONMARKET AND close>close[1] then //AND STRATEGYPROFIT=0 then
    BUY amount LOT AT MARKET
    endif
    
    if NOT ONMARKET AND close<close[1] then //AND STRATEGYPROFIT=0 then
    SELLSHORT amount LOT AT MARKET
    endif
    
    // case BUY - add orders on the same trend
    if longonmarket and close-tradeprice(1)>=gridstep*pipsize then
    BUY 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
    
    //GRAPH floatingprofit as "float"
    //GRAPH RRreached as "rr"
    //GRAPH floatingprofit as "floating profit"
    //GRAPH BBfloatingprofit as "deviation of floating profit"
    //GRAPH positionprice-mindistancetoclose
    //GRAPH moneyrisk
    //GRAPH onepointvaluebasket
    //GRAPH gridstep
    
    //stoploss trigger when risk reward ratio is not met already
    if onmarket and RRreached=0 then
    SELL AT positionprice-mindistancetoclose STOP
    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
    SELL AT MARKET
    EXITSHORT AT MARKET
    endif
    SELL AT positionprice-mindistancetoclose STOP
    EXITSHORT AT positionprice-mindistancetoclose STOP
    endif
    
    //resetting the risk reward reached variable
    if not onmarket then
    RRreached = 0
    endif
    
    endif
    
Viewing 15 posts - 151 through 165 (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...