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

Viewing 15 posts - 16 through 30 (of 308 total)
  • Author
    Posts
  • #5723 quote
    Nicolas
    Keymaster
    Master

    Something’s wrong here, you’re right. The average position price minus 1% is 75.626 for your basket of 3 orders this morning and they exited @76.30 at 16:00 …

    Just to be sure: exit is calculated @ average position price minus 1% of this price = average position * 0.99 / are we ok with this?

    On my backtest (screenshot attached), trades are not closed, graph instruction return exactly the ‘newsl’ variable where the trades are supposed to close… Are you sure you don’t have change the multiplier to 0.001 instead of 0.01?

    As for the strategy to shutdown after a loss, we can use STRATEGYPROFIT to achieve this, just change the line2 with this code:

    if NOT ONMARKET AND close>close[1] AND STRATEGYPROFIT=0 then

    So the first order will only be launched one time and grid orders are not initiated if there are no other orders on market.

    backtest-prorealtime-grid-orders.png backtest-prorealtime-grid-orders.png
    #5733 quote
    cfta
    Participant
    Senior

    Good morning Nicolas,

    Yes I’m absolutely ok with  exit is calculated @ average position price minus 1% of this price = average position * 0.99.

    It turns out that I had indeed changed the multiplier to 0.001, sorry about the mix up.

    Thanks, I keep on testing today adding the shut down after loss feature 🙂

    #5761 quote
    cfta
    Participant
    Senior

    So for todays update of the real market testing, I changed the 2nd line as above but kept (positionprice*0.01) thinking it’s best to make one change at the time but the system still placed new entry orders after SL with this code;

    // first trade whatever condition
    if NOT ONMARKET AND close>close[1] AND STRATEGYPROFIT=0 then
    BUY 1 LOT AT MARKET
    endif
    
    // case BUY - add orders on the same trend
    if close-tradeprice(1)>20*pipsize then
    BUY 1 LOT AT MARKET
    endif
    
    // stoploss at 1% from the average price of the whole positions on market
    if longonmarket then
    newSL = positionprice - (positionprice*0.01)
    if close<=newSL then
    SELL AT MARKET
    endif
    endif
    

    No I have changed to 0.99 running it along with the change of the second line, let’t se it it works 🙂

    PRT-grid-error-10.png PRT-grid-error-10.png
    #5766 quote
    Nicolas
    Keymaster
    Master

    Hmmm I think i know why, change this lines too :

    // case BUY - add orders on the same trend
    if longonmarket and close-tradeprice(1)>20*pipsize then
     BUY 1 LOT AT MARKET
    endif

    Because it will open a new trade even if the previous one is closed already … miss that thing sorry 🙂

    #5879 quote
    cfta
    Participant
    Senior

    Thanks once again Nicolas. Unfortunately I have not been able to test your latest addition yet since my PRT demo with IG expired a couple of days ago and I’m waiting for IG to allocate my deposit to my account so I should be back on track soon enough, I’ll give a new update in the days to come…

    #6254 quote
    Nicolas
    Keymaster
    Master

    Any update here?

    #6303 quote
    cfta
    Participant
    Senior

    Hello Nicolas,

    Yes finally I got an update! IG had a major delay in allocating my deposit to my account, partly my own fault though, but I got it sorted a couple of days ago and today I set up my demo account again. I have been doing some backtesting this evening with the latest modified code you provided and things look very promising!

    I ran it on a Dax 3 minute chart (hence some entries are not exactly 20 pips when the market moved fast) and all entries were triggered properly and so was the SL. In addition no new entry orders were placed after the SL was triggered 🙂

    This is the code I used;

    // first trade whatever condition
    if NOT ONMARKET AND close>close[1] AND STRATEGYPROFIT=0 then
    BUY 1 LOT AT MARKET
    endif
    
    // case BUY - add orders on the same trend
    if longonmarket and close-tradeprice(1)>20*pipsize then
    BUY 1 LOT AT MARKET
    endif
    
    // stoploss at 1% from the average price of the whole positions on market
    if longonmarket then
    newSL = positionprice - (positionprice*0.99)
    if close<=newSL then
    SELL AT MARKET
    endif
    endif

    Tomorrow I will start the forward testing in real time demo and if looking good I might even try it on my real account though I will watch it very closely if I do.

    So if the current code keep on working as intended there are two additions that I hope we can make;

    • A limit function for taking profit at a given percentage level with a default level of 10 %.
    • A function to bring the SL to break even once a given profit is reached, perhaps 3 %.

    Another general question due to my lack of PRT and coding experience, is it possible to modify a system while it is running in real market conditions? The point would be to manually change SL or limit levels.

    I’ll be back with a new update tomorrow after some forward testing.

    PRT-grid-progress-1.png PRT-grid-progress-1.png
    #6307 quote
    cfta
    Participant
    Senior

    Hmm when testing the same code on GBPCAD the SL is not triggered which it should have been at around 1.8300 or a bit lower due to the lower pip value of this pair. Makes no sense to me…

    Please ignore the first pic, I uploaded the wrong one but don’t know how to remove it.

    PRT-grid-error-11.png PRT-grid-error-11.png
    #6312 quote
    Nicolas
    Keymaster
    Master

    Please use

    GRAPH newSL

    To be sure the stoploss price value have been correctly calculated.

    #6318 quote
    David
    Participant
    Veteran

    Another general question due to my lack of PRT and coding experience, is it possible to modify a system while it is running in real market conditions? The point would be to manually change SL or limit levels.

    1. As an IG client you cannot modify a system once it’s running in PRT.
    2. You can only Stop it and there are options in the general settings if you Stop a system should it close positions or leave them open.
    3. If you manually modify a position on the IG platform it will Stop the system but your position will stay open if you only changed the PT/Limit or Stop Loss and then you have to Restart the system in PRT  it will state user intervention stopped the system.

    I assume the reason for this is if there’s a bug that’s not in your system but a bug with PRT, PRT can test for it as they did for one of my systems that started opening positions until it hit the PRT 50 positions per day per system limit.

    #6322 quote
    Nicolas
    Keymaster
    Master

    Because programs are running server side, it must be stop there before you can make modifications on the program. That’s the reason why PRT always want you to “prepare” the code, before it can be launched in their servers.

    #6355 quote
    cfta
    Participant
    Senior

    Thanks guys, that makes perfect sense, I figured it’s not possible but doesn’t hurt to ask. Being able to modify the positions on IG and maintain them open even if the system is stopped it a great benefit to change the SL to lock in profit or raise the limit after building up large positions and price takes off in the right direction after news announcements.

    Today I have been testing in real market conditions on demo and things look very good, entry orders are taken is intended with small differences which can probably be adjusted by changing to a second or tick chart from the 1 minute chart. I started the system on Dax, EURJPY and GBPCAD this morning taking 3, 4 and 3 entries accordingly, I’m hoping Dax will turn down during the evening or tomorrow to see if the SL works properly.

    Nicolas, could you possibly provide a code for short positions too please? I tried reversing one of the long codes earlier on but never managed to make it work properly I’m afraid.

    New updates to come tomorrow or the next day.

    PRT-grid-progress-2.png PRT-grid-progress-2.png
    #6358 quote
    Nicolas
    Keymaster
    Master

    Sure I can do it. This grid orders code is a nice example for everyone.

    Maybe you could describe for us all how you are using it in your trading plan? It surely be in interest for a lot of people around here! 🙂

    #6423 quote
    cfta
    Participant
    Senior

    Hi fellows it’s been a long day and getting late so I’ll keep this update bried but I will tell you more about my strategy and trading plan tomorrow 🙂

    Today’s performance has been bad news since Dax dropped as expected but the SL was not triggerd and drawdown went over -5 %. This is the code currently running;

    // first trade whatever condition
    if NOT ONMARKET AND close>close[1] AND STRATEGYPROFIT=0 then
    BUY 1 LOT AT MARKET
    endif
    
    // case BUY - add orders on the same trend
    if longonmarket and close-tradeprice(1)>20*pipsize then
    BUY 1 LOT AT MARKET
    endif
    
    // stoploss at 1% from the average price of the whole positions on market
    if longonmarket then
    newSL = positionprice - (positionprice*0.99)
    if close<=newSL then
    SELL AT MARKET
    endif
    endif
    

    Nicolas, do you have any idea why the SL was not triggered?

    PRT-grid-error-12.png PRT-grid-error-12.png
    #6438 quote
    Nicolas
    Keymaster
    Master

    Before I change anything on code. You are talking about drawdown, but drawdown about what precisely? In the current code, we are not testing money account at all, only the spread between the average open price of the whole positions and the current close of the instrument.

    Since I don’t have informations about your 3 still opened trades, I don’t have any idea about where is the price stoploss computed by the program itself 🙂

Viewing 15 posts - 16 through 30 (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, 9 months ago.

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