Parabolic Short/Long Strategy

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #211550 quote
    Francesco
    Participant
    Veteran

    Hi everyone, after taking a break for a while, I’m back to jot down a few more ideas during my free time. Since I’m a bit rusty, I would like some help in converting some elements into a code that I will then assemble and share with you if it’s decent.

    First code: Identify an increase/decrease of x percent in a stock during the past y days;

    Second code: Enter short during the breakdown of the opening range low if the candle is red/Enter long during the breakout of the opening range high if the candle is green;

    Third code: Open a position when the price, after crossing over or under the VWAP, fails and bounces back.

    Thanks!

    #211567 quote
    JS
    Participant
    Senior

    Hi @Francesco,

    Here is the first code…

    Period = y //y days
    Gain = x // x%
    
    Increase = 0
    Decrease = 0
    
    If (Close - Close[y]) / Close[y] * 100 >= x then
    Increase = 1
    ElsIf (Close - Close[y]) / Close[y] * 100 <= x then
    Decrease = 1
    EndIf
    Francesco thanked this post
    #211568 quote
    JS
    Participant
    Senior
    If (Close Close[y]) / Close[y] * 100 >= x then
    Increase = 1
    ElsIf (Close Close[y]) / Close[y] * 100 <= x then
    Decrease = 1
    EndIf
    #211577 quote
    robertogozzi
    Moderator
    Master
    I suggest to modify the code as follows, to make sure both variables are always different:
    If (Close – Close[y]) / Close[y] * 100 >= x then
       Increase = 1
       Decrease = 0
    ElsIf (Close – Close[y]) / Close[y] * 100 <= –x then
       Increase = 0
       Decrease = 1
    EndIf
    Francesco thanked this post
    #211592 quote
    Francesco
    Participant
    Veteran
    Thank you guys! For the second request, could something like this work? (the time refers to NASDAQ opening hours)
    // Entry Conditions
    if time>= 153000 and time <= 153500 then
    if time= 153000 then
    dailyhigh= high
    dailylow= low
    endif
    if high> dailyhigh then
    dailyhigh= high
    endif
    if low< dailylow then
    dailylow = low
    endif
    endif
    
    cl= close crosses over dailyhigh
    cs= close crosses under dailylow
    #211593 quote
    Francesco
    Participant
    Veteran
    Seems not to work properly… i’ll explain better with the attached image, an example of a long setup. Is this possible to code?
    example.jpg example.jpg
    #211603 quote
    JS
    Participant
    Senior

    When I use Time >=153000 the high and Low of the previous candle is used, hence Time >= 153500…

    DefParam CumulateOrders=False
    TimeFrame(5 minutes, UpDateOnClose)
    
    Once HighEntry=0
    Once LowEntry=0
    
    If Time >= 153500 and Time <= 154000 and NOT OnMarket then
    If Time = 153500 then
    HighEntry = High
    LowEntry = Low
    EndIf
    If (HighEntry + LowEntry) <> 0 then
    Buy 1 contract at HighEntry STOP
    SellShort 1 contract at LowEntry STOP
    EndIf
    EndIf
    
    Francesco thanked this post
    Scherm­afbeelding-2023-03-15-om-17.36.14.png Scherm­afbeelding-2023-03-15-om-17.36.14.png
    #211613 quote
    Francesco
    Participant
    Veteran
    It seems to open the positions correctly now! But i’m still missing on how to put the stop loss on the high/low of the entry candle. Also in your example @js the postion should be closed at 15:55 after crossing under the low of the entry candle. Any suggestion? Current code version below:
    // Entry Conditions
    once highentry=0
    once lowentry=0
    
    if time= 153000 then
    highentry=high
    lowentry=low
    endif
    
    cl=close crosses over highentry
    cs=close crosses under lowentry
    
    // Time Conditions
    t=time>=153500 and time< 154000
    
    // Enter Long
    if not onmarket and cl and t then
    buy n contract at market
    endif
    
    // Enter Short
    if not onmarket and cs and t then
    sellshort n contract at market
    endif
    #211647 quote
    Francesco
    Participant
    Veteran
    I implemented the following code and it seems that i’m getting closer
    // Entry Conditions
    if time=153000 then
    highentry=high
    lowentry=low
    endif
    
    cl=close crosses over highentry
    cs=close crosses under lowentry
    
    // Time Conditions
    t=time>=153500 and time<154000
    
    // Stop Loss Conditions
    sll=abs(close-low)
    sls=abs(close-high)
    
    // Enter Long
    if not onmarket and cl and t then
    buy n contract at market
    set stop loss sll
    endif
    
    // Enter Short
    if not onmarket aand cs and t then
    sellshort n contract at market
    set stop loss sls
    endif
    But as you can see in the image attached, the position is closed when crossing the high of the opening range candle and not when crossing the high of the candle where the position was opened
    Immagine.jpg Immagine.jpg
    #211666 quote
    Francesco
    Participant
    Veteran
    Ok i think i managed to solve the issue changing with:
    // Stop Loss Conditions
    sll=abs(close[2]-low)
    sls=abs(close[2]-high)
    But looking at the backtests, putting the stop loss on the high/low of the opening range candle (so at the daily high/low) instead of the candle where the position was opened (as i wanted to during last posts) seems more effective for gains. Below the first version of the system (i’m still figuring out if it’s necessary to implement the VWAP condition) on NASDAQ 5M – 1.5 Contracts (939€ atm)
    // Parabolic Long/Short v1 by Francesco
    // ProRealCode.com - 20230316
    // NASDAQ - 5M
    
    // Setup
    defparam cumulateorders=false
    
    n=1.5
    
    once long=1
    once short=1
    
    timeframe (1 day)
    // Filter
    x=3
    
    if (close-close[1])/close*100>=x then
    increase=1
    decrease=0
    elsif (close-close[1])/close*100<=-x then
    increase=0
    decrease=1
    endif
    
    timeframe (default)
    // Entry Conditions
    if time=153000 then
    highentry=high
    lowentry=low
    endif
    
    cl=close crosses over highentry
    cs=close crosses under lowentry
    
    // Time Conditions
    t=time>=153500 and time<154000
    
    // Stop Loss Conditions
    sll=abs(close-low)
    sls=abs(close-high)
    
    // Enter Long
    if long then
    if not onmarket and decrease=1 and cl and t then
    buy n contract at market
    set stop loss sll
    endif
    endif
    
    // Enter Short
    if short then
    if not onmarket and increase=1 and cs and t then
    sellshort n contract at market
    set stop loss sls
    endif
    endif
    
    // Trailing Stop
    trailingstart=200
    trailingstep=5
    
    If not onmarket then
    newsl=0
    endif
    
    if longonmarket then
    if newsl=0 and close-tradeprice(1)>=trailingstart*pipsize then
    newsl=tradeprice(1)+trailingstep*pipsize
    endif
    if newsl>0 and close-newsl>=trailingstep*pipsize then
    newsl=newSL+trailingstep*pipsize
    endif
    endif
    
    if shortonmarket then
    if newsl=0 and tradeprice(1)-close>=trailingstart*pipsize then
    newsl=tradeprice(1)-trailingstep*pipsize
    endif
    if newsl>0 and newSL-close>=trailingstep*pipsize then
    newsl=newsl-trailingstep*pipsize
    endif
    endif
    
    if newsl>0 then
    sell at newsl stop
    exitshort at newsl stop
    endif
    Few details about the system:
    • Entirely based on price action
    • Pretty easy to optimize (just 1 value to edit)
    • No optimization needed for stop loss, just play with the trailing stop
    • Running just the Long version drastically decreases drawdown but generates less gains
      Please find attached a 10y backtest; feel free to give your contribution
    backtest.jpg backtest.jpg
Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.

Parabolic Short/Long Strategy


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 9 replies,
has 3 voices, and was last updated by Francesco
2 years, 11 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 03/14/2023
Status: Active
Attachments: 4 files
Logo Logo
Loading...