AirBag Defense System

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #61821 quote
    Ivan Donatiello
    Participant
    Average

    Hello everyone, Ivan Donatiello Here.

    My intention is to create a trading system that works to defend other strty, as breakout and meanrevertin systems in the portfolio.

    For example, I should trade the S & P 500 with an breakout system and mean reverting, and probably this week the high downward volatility is very dangerous.

    Then I implement a strategy that works as follows:

    Conditions to enter the trade short:

    1. Open> Close
    2. Close of today < Close of yesterday
    3. Today’s range higher than the average range of the last n days

    If the conditions are verified:

    1. Open a trade short at today’s low

    Stop loss conditions.

    1. + n point on today’s high

    Eixt:

    1. K * mean of the range at n days, where K is a decimal incremental factor> 1

    Here is the code that I did but that does not work:

    //AirBag System Trading Lab Capital - Ivan Donatiello
    defparam cumulateorders=false
     
    //Short Condition
    C1 = Open > Close
    C2 = Close < Close[1]
    C3 = Range > (summation[10](range)/10)
    
    if not longonmarket AND C1 AND C2 AND C3 then
    SELLSHORT 1 contract at lowest[1](low)[1] stop
    stoploss = close+highest[1](high)[1]
    endif
    
    //Exit Condition
    SET TARGET PROFIT  n2*AverageTrueRange[10]
    
    //Stop Loss Condition
    set stop loss stoploss
    

    If we can thank you 🙂

    #61852 quote
    robertogozzi
    Moderator
    Master

    You can write lines 10-11 as follows

    SELLSHORT 1 contract at low[1] stop
    stoploss = close+high[1]

    because both with LOWEST and HIGHEST you only check one bar, the previous one, making them unnecessary.

    Conditions look good and logically combined (assuming you are on a daily TF).  C2 requires the previous bar to be BEARISH or even BULLISH but with a current opening bearish gap no matter if filled, is that what you want?

    Maybe the average range of the last n bars is greater than the current one!

    #62302 quote
    Ivan Donatiello
    Participant
    Average

    These are daily bars.

    I do not care about the gap, but the explosion of downward volatility.

    Even with your lines of code, the system opens only 5 positions then no longer closes the stop loss leaving the last position at a loss.

    It would be a shame not to realize this system as it could be an excellent balance of equity systems.

    PS: The place also in the Italian forum?

    #62303 quote
    Vonasi
    Moderator
    Master

    I think that your stoploss calculation is incorrect. As it currently is the stoploss would be huge  as close + high[1] = 2623 + 2628 = massive number of pips!

    Surely it should be high[1] – close so 2628 – 2623 = 5 pips.

    Also you might want to change IF NOT LONGONMARKET to IF NOT ONMARKET or put the stoploss calculation in a separate IF decision as otherwise the stoploss will be repeatedly recalculated once you are short on the market if the same conditions are met again.

    Nicolas thanked this post
    #62555 quote
    robertogozzi
    Moderator
    Master

    PS: The place also in the Italian forum?

    Please do not duplicate topics in order to have a wider range of help, because this might cause the opposite effect, leaving some suggestions on a forum and others on a different one, making it difficult and annoying for members to search and help. Thank you.

    #62559 quote
    robertogozzi
    Moderator
    Master

    Since you used

    set stop loss stoploss

    you correctly used price instead of pips (pLOSS deals with pips), but you are ADDING two prices, which will never be reached (within Eur/Usd, say 1.2110 + 1.2165 = 2.4275 which is…. you know what!), you may want to write

    stoploss = high[1]

    or

    stoploss = high[1] + (3 * pipsize)

    whatever you want.

    #62568 quote
    Vonasi
    Moderator
    Master

    you correctly used price instead of pips (pLOSS deals with pips)

    Well spotted @robertogozzi. I didn’t spot that as I never use Loss always pLoss – so I assumed again! At least I was right about the stoploss calculation! 🙂

    #62581 quote
    Nicolas
    Keymaster
    Master

    “set stop loss” use distance in price and not a price level, so the correct syntax should be:

    stoploss = abs(high[1]-close)
    set stop loss stoploss

    Assuming it is a short order with the stoploss set at the High of the previous candlestick.

    robertogozzi thanked this post
    #62582 quote
    robertogozzi
    Moderator
    Master

    Thank you Nicolas, I also always use pLOSS, sorry for the incorrect suggestion!

    #62583 quote
    robertogozzi
    Moderator
    Master

    To set a Stop Loss at a given price you only have to use pending STOP orders (renewed at each bar), like

    SELL      AT .... STOP   //exit LONG trades
    EXITSHORT AT .... STOP   //exit SHORT trades

    is that correct Nicolas?

    #62585 quote
    Ivan Donatiello
    Participant
    Average

    Thank you for the tips 🙂

    I rewrote the code, now it works.

    //AirBag System Trading Lab Capital - Ivan Donatiello
    defparam cumulateorders=false
    
    //Short Condition
    
    C1 = Close CROSSES UNDER (Low[1] - atrmultipler*AverageTrueRange[20](close))
    
    if not onmarket AND C1 then
    SELLSHORT 1 contract at low stop
    endif
     
    
    
    //Exit Condition
    
    //First tipe of exit
    if onmarket and barindex-tradeindex(1)>=ndayforexit then
    EXITSHORT at market
    endif
    
    //Second tipe of exit (use either the first or the second or study a possible combination)
    set target profit atrmultipler*AverageTrueRange[20](close)
    
    //Stop Loss Condition
    set stop loss high + 1
    
    

    Now the system enters the market at the end of the current bar, it would be much better if the system entered the market during the bar when the volatility level was reached.

    For example:

    1. Enter the market when the price falls and volatility has exceeded 1.5 Atr [20].

    We hope we can do the metrics would improve a lot.

    See you soon 😉

    #62587 quote
    robertogozzi
    Moderator
    Master

    Be warned that the above code works with S&P500, Dax and similar instruments, but it would not work with EurUsd, since

    high + 1

    would give 2.1220 (1.1220 + 1), instead of 1.1221 (1.1220 + 0.0001), so you’d better always use

    set stop loss high + 1 * pipsize

    which will work with any instrument. It’s the system doing the conversion.

    GraHal thanked this post
    #62814 quote
    Ivan Donatiello
    Participant
    Average

    Thank You 🙂

    #62885 quote
    Nicolas
    Keymaster
    Master

    @robertogozzi

    Yes you are right about your statement for STOP orders. They expire at each bar so it’s necessary to put them continuously until your conditions are not true anymore.


    @richlab

    Not possible to do that until we get the long promise multiple timeframes support 😉

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.

AirBag Defense System


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 13 replies,
has 4 voices, and was last updated by Nicolas
8 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/07/2018
Status: Active
Attachments: No files
Logo Logo
Loading...