Request for a simple strategy to be coded for spread betting

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #108174 quote
    AugustusKing
    Participant
    Junior
    Dear ProRealCoders, I’ve enjoyed using this site for a few years now, checking out and testing all the cool systems you guys have coded. This is the first time I’ve posted on the forum, and I hope that this isn’t against any regulation to request a build of a strategy, but I thought I’d ask anyway. The thing that I have no idea how to achieve here is the way I’d like the trailing stop loss to work, need some people with actual mad skills to help me get it live! I’m looking to build a simple price action strategy using the following criteria:

    New Daily Hi/Lo with Trailing Stop

    Assets to trade
    • FTSE 100.
    Bet Size
    • £1 per pip.
    Time Frame
    • Daily.
    Conditions for BUY
    • Price is greater than the previous candle’s high. (NOT the close, the high!)
    • Stop loss should be placed 15 pips below the low of the previous candle.
    • With each new candle that’s formed where you’re not stopped out, move the stop loss to 15 pips lower than the previous candles’ low.
    • Open BUY bet on next candle open
    Conditions for SELL
    • Price is less than the previous candle’s low. (NOT the close, the low!)
    • Stop loss should be placed 15 pips above the high of the previous candle.
    • With each new candle that’s formed where you’re not stopped out, move the stop loss to 15 pips higher than the previous candles’ high.
    • Open SELL bet on next candle open

    Condition for EXIT

    • When trailing stop loss is triggered.
    Times to trade
    • No limitations on time of day to trade.
    EXTRA NOTES
    • I don’t plan for this simple system to open any new positions when there’s already a trade open.
    • This is for spread betting NOT CFD trading

      I’m incredibly grateful for any help or guidance provided here. Many thanks coders! Matt
    #108183 quote
    Vonasi
    Moderator
    Master
    AugustusKing – Welcome to the forums. Your topic is about an automated strategy code so I have moved it to the ProOrder forum which is dedicated to automated strategies. I will move the topic to that forum. Please try to post in the most relevant forum with any future topics.
    AugustusKing thanked this post
    #108185 quote
    GraHal
    Participant
    Master
    Well done @AugustusKing your strategy specification is one of the best laid out / formatted I’ve ever seen on here … I’m sure somebody will help you out soon! 🙂
    AugustusKing thanked this post
    #108186 quote
    AugustusKing
    Participant
    Junior
    I really appreciate that, I have manually backtested over various assets including main fx pairs, indices and commodities and it appears to be profitable to a realistic and sustainable level. Drawdowns are low and it performs robustly across various market conditions. I’m excited to see if anyone is willing to help me code this so that I can test it more extensively and then apply it across multiple asset classes. Appreciate the support.
    #108187 quote
    Vonasi
    Moderator
    Master
    This does what you describe but not profitably! Image shows FTSE100 daily. Even if you separate the long and short parts of the strategy it is not pretty.
    defparam cumulateorders = false
    
    c1 = close > high[1]
    c2 = close < low[1]
    
    if c1 then
    buy 1 contract at market
    sell at low[1] - 15 stop
    endif
    
    if longonmarket then
    sell at low[1] - 15 stop
    endif
    
    if c2 then
    sellshort 1 contract at market
    exitshort at high[1] + 15 stop
    endif
    
    if shortonmarket then
    exitshort at high[1] + 15 stop
    endif
    
    Screenshot_8-3.png Screenshot_8-3.png Screenshot_9-2.png Screenshot_9-2.png Screenshot_10-3.png Screenshot_10-3.png
    #108192 quote
    AugustusKing
    Participant
    Junior
    Hi, and thank you so much for taking a bash on the code for this. Can I just ask if this trails the stop loss with each new candle that is formed or if it fixes the stop at 15 below the low on entry? I only ask because when I run the backtest on the code you’ve given me it gets the entries just as I would do it manually, but the exits are different to where I’m taking them manually, so I feel like I’ve possibly left something out of my description or not conveyed it well. I have written on a screengrab of one trade example to highlight where my intended system differs from the code you’ve included. Follow the steps in the order I’ve numbered them. You can see where the PRT backtesting has entered and exited and where I’d need it to exit. Basically the SL is not moving along when a new candle is formed (it’s staying where it was initially placed). This is the major problem here from what I can see. Additionally, I notice this code deals in ‘contracts’ rather than ‘bet size’, would this still work for automating trading on a spread bet account within PRT? I hope this is helpful. Just want to reiterate how much I appreciate you taking the time to help with this. Regards Matt
    Screenshot-2019-09-22-at-23.02.31.png Screenshot-2019-09-22-at-23.02.31.png
    #108198 quote
    Vonasi
    Moderator
    Master
    Sorry – I got the exits one candle too far back Try this instead:
    defparam cumulateorders = false
     
    c1 = close > high[1]
    c2 = close < low[1]
     
    if c1 then
    buy 1 contract at market
    sell at low - 15 stop
    endif
     
    if longonmarket then
    sell at low - 15 stop
    endif
     
    if c2 then
    sellshort 1 contract at market
    exitshort at high + 15 stop
    endif
     
    if shortonmarket then
    exitshort at high + 15 stop
    endif
    AugustusKing thanked this post
    #108202 quote
    AugustusKing
    Participant
    Junior
    Thank you Vonasi, That seems to all work as intended at first glance. I will dig a little deeper, but for now, it’s thrown up some unexpected surprises for me (which is a good thing, even if negative!!). I manually backtested it on EUR/USD for 2019 and it was profitable, but on this code it’s not… it’s more likely there was an error with my manual backtest I’m sure, but I’ll double-check things to make sure. I can see that it works profitably in the long term on the following markets:

    DAILY CHARTS

    • NIKKEI
    • DAX
    • NASDAQ
    • DOW
    • BRENT CRUDE

    4HR CHARTS

    • DOW
    • NATURAL GAS

    1HR CHARTS

    • Italy 40
    • NASDAQ
    • DOW
    Time to dig a little deeper, actually look at drawdowns, profit factor and how it performs in the various market conditions to see if it’s a viable system to persist with developing 🙂 Do you, or anyone else have any thoughts, observations or ideas on it? Thanks for this Vonasi Matt
    #108203 quote
    Vonasi
    Moderator
    Master
    A fixed SL distance of +/- 15 will not fit all markets. Range on markets changes with time so something like the Dow will have a smaller range in 2010 compared to today but as a percentage of price it is lower so an adaptable SL distance will most likely work better than a fixed one.
    #108204 quote
    AugustusKing
    Participant
    Junior
    A fixed SL distance of +/- 15 will not fit all markets. Range on markets changes with time so something like the Dow will have a smaller range in 2010 compared to today but as a percentage of price it is lower so an adaptable SL distance will most likely work better than a fixed one.
    Yep definitely, will need to go through various markets experimenting with which SL ranges work best, that’ll help!! 🙂 Thanks, have a great week as well by the way!
    #108208 quote
    GraHal
    Participant
    Master
    I have written on a screengrab
    Gold star for clarity of layout  … what screengrab sw have you used for this?
    AugustusKing wrote:
    Additionally, I notice this code deals in ‘contracts’ rather than ‘bet size’, would this still work for automating trading on a spread bet account within PRT?
    Yes
    AugustusKing thanked this post
    #238169 quote
    Gravitywa
    Participant
    New
    Any luck with getting that code? Well, for me, it seemed simple, but it turns out it’s not simple at all.
    #238171 quote
    Kentztory
    Participant
    New
    I’ve dabbled in a bit of spread betting myself, and finding that sweet spot for stop-loss is always a challenge. For me, it seems like a trial-and-error game, figuring out what works across different markets and timeframes.
    #238174 quote
    PeterSt
    Participant
    Master
    It shouldn’t be that difficult as long as you know how to trade manually and have the “insight”. Example below. The staircasing you see is a normal behavior. The climb vs the retrace (dropping back to a lower price level) is what you’ll try to cover with Trailing. So would you (manually) exit at say 13:24 ? perhaps. But would you at 13:36 after you experienced the part around 13:36 ? No ? then your Trailing should bear the distance to NOT exit at both the 13:24 and 13:36. Now, when that is just covered for, your Trailing will exit at ~14:36. This should not be found by optimizing, but by looking at the instrument’s behavior.   Btw, I hope you both are serious and don’t turn out to be some kind of spammers (up to being the same person). We’ll see …
    druby thanked this post
    image_2024-09-28_015503432.png image_2024-09-28_015503432.png
    #238436 quote
    PeterSt
    Participant
    Master
    That is what I promised, Mr Spam …
Viewing 15 posts - 1 through 15 (of 16 total)
  • You must be logged in to reply to this topic.

Request for a simple strategy to be coded for spread betting


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 15 replies,
has 7 voices, and was last updated by JC_Bywan
1 year, 4 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 09/22/2019
Status: Active
Attachments: 5 files
Logo Logo
Loading...