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

Viewing 15 posts - 121 through 135 (of 308 total)
  • Author
    Posts
  • #8018 quote
    cfta
    Participant
    Senior

    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;

    //-------------------------------------------------------------------------
    // Main code : LONG GRID BB Exit
    //-------------------------------------------------------------------------
    defparam preloadbars = 100
    once RRreached = 0
    
    //parameters
    accountbalance = 10000 //account balance in money at strategy start
    riskpercent = 2 //whole account risk in percent%
    gridstep = 10 //grid step in point
    amount = 1 //lot amount to open each trade
    rr = 2 //risk reward ratio (set to 0 disable this function)
    
    //first trade whatever condition
    if NOT ONMARKET AND close>close[1] AND STRATEGYPROFIT=0 then
    BUY 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
    
    //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
    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
    SELL AT positionprice-mindistancetoclose STOP
    endif
    
    //stoploss trigger when risk reward ratio has been reached
    if onmarket and RRreached=1 then
    if floatingprofit crosses under BBfloatingprofit then
    SELL AT MARKET
    endif
    endif
    
    //resetting the risk reward reached variable
    if not onmarket then
    RRreached = 0
    endif
    

    Short;

    //-------------------------------------------------------------------------
    // Main code : Grid Short BB Exit
    //-------------------------------------------------------------------------
    defparam preloadbars = 100
    once RRreached = 0
    
    //parameters
    accountbalance = 10000 //account balance in money at strategy start
    riskpercent = 2 //whole account risk in percent%
    gridstep = 10 //grid step in point
    amount = 1 //lot amount to open each trade
    rr = 2 //risk reward ratio (set to 0 disable this function)
    
    //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
    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
    endif
    
    //resetting the risk reward reached variable
    if not onmarket then
    RRreached = 0
    endif
    Brage thanked this post
    PRT-grid-error-18.png PRT-grid-error-18.png PRT-grid-error-17.png PRT-grid-error-17.png
    #8022 quote
    Nicolas
    Keymaster
    Master

    Because you didn’t change the line 32 to:

    floatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize //actual trade gains

    That’s the reason why your loss is not well calculated.

    cfta thanked this post
    #8026 quote
    davidp13
    Participant
    Average

    @cfta and Nicolas – quick question pls. When I run the code as is it only produces one trade, but when i remove STRATEGYPROFIT=0 from the first trade condition it works? Thanks

    #8028 quote
    cfta
    Participant
    Senior

    @davidp13

    Does 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.

    #8036 quote
    Nicolas
    Keymaster
    Master

    @davidp13

    Yes if you remove this STRATEGYPROFIT=0 condition, it will start over again after each cycle.

    #8045 quote
    gforton
    Participant
    Average

    Hi,

    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

    #8054 quote
    cfta
    Participant
    Senior

    Good 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?

    //-------------------------------------------------------------------------
    // Main code : LONG GRID BB Exit
    //-------------------------------------------------------------------------
    defparam preloadbars = 100
    once RRreached = 0
    
    //parameters
    accountbalance = 10000 //account balance in money at strategy start
    riskpercent = 1 //whole account risk in percent%
    gridstep = 15 //grid step in point
    amount = 1 //lot amount to open each trade
    rr = 3 //risk reward ratio (set to 0 disable this function)
    
    //first trade whatever condition
    if NOT ONMARKET AND close>close[1] AND STRATEGYPROFIT=0 then
    BUY 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
    
    //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
    SELL AT positionprice-mindistancetoclose STOP
    endif
    
    //stoploss trigger when risk reward ratio has been reached
    if onmarket and RRreached=1 then
    if floatingprofit crosses under BBfloatingprofit then
    SELL AT MARKET
    endif
    endif
    
    //resetting the risk reward reached variable
    if not onmarket then
    RRreached = 0
    endif
    
    PRT-grid-error-19.png PRT-grid-error-19.png
    #8063 quote
    deleted190722
    Participant
    New

    Hi 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.

    #8068 quote
    Nicolas
    Keymaster
    Master

    That’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.

    #8123 quote
    Nicolas
    Keymaster
    Master

    @cfta

    Because 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.

    #8168 quote
    cfta
    Participant
    Senior

    @Nicolas

    I 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;

    //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

    Regarding 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 🙂

    PRT-grid-error-20.png PRT-grid-error-20.png
    #8173 quote
    Nicolas
    Keymaster
    Master

    Did the profit reached the risk reward ratio?

    #8176 quote
    cfta
    Participant
    Senior

    No 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?

    #8177 quote
    Nicolas
    Keymaster
    Master

    I understand, but did some tests again today and everything’s fine in Probacktest so far… Does the same problem occurs in Probacktest on your side please?

    #8181 quote
    cfta
    Participant
    Senior

    I 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.

    PRT-grid-error-21.png PRT-grid-error-21.png PRT-grid-error-22.png PRT-grid-error-22.png
Viewing 15 posts - 121 through 135 (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...