Entry on fib retracement?

Viewing 15 posts - 1 through 15 (of 26 total)
  • Author
    Posts
  • #18115 quote
    kg6450
    Participant
    Average

    Hi, I was wondering if someone could help me with writing how to enter a position on a fib extension.

    I am trying to code for price breaking out of a range, and then reaching a high. I have gotten that far, but once price has reached that high, I want to set an order to enter the market at the 62.8% fib retracement of that high.

    I was wondering if anyone else has coded fib retracements before?

    #18134 quote
    Nicolas
    Keymaster
    Master

    There is a nice example of Fibonacci extension calculation from a recent high here in this stock screener: Fibonacci 61.8% retracement screener

    #18135 quote
    kg6450
    Participant
    Average

    Hi Nicolas, thanks for the reply!

    I was looking at that when I was writing my code, So far I have this:

    IF Close > hh AND MakeTrade = 1 THEN
    IF TurnDown THEN
    fib = (highest[16](high) - ll) * 0.382
    Entry = ll + fib
    ENDIF
    ENDIF
    

     

    Where MakeTrade refers to the time of day, ll is the lowest low of the period I want to measure from and hh is the breakout.

    What I’m struggling is setting the order for entry, I thought that by defining Entry as the fib + ll and placing an order there would work but my code completely ignores it?

    #18138 quote
    Nicolas
    Keymaster
    Master

    Maybe because if your Close is superior to the current hh, your Close IS THE NEW hh. So you should refer to a previous hh to test if your Close has actually breach this level.

    #18144 quote
    kg6450
    Participant
    Average

    Hmm I don’t think that is the case, I want to set a between 5pm and 7am the next day, so when I code that I do it by saying

    IF Time = 070000 THEN 
    hh = highest[n](high)
    ll = lowest[n](low)
    ENDIF

    When n is the number of bars going back to 5 pm the previous day. Then once that is recorded for that day, I want to check for a breakout between two times later the next day. if price breaks out between these times, wait for a turning point (as in a highest high) and then use that to work out the fib retracement from the previous low.

    I know it sounds really complicated to type, but any help would be really appreciated!

    I know its quite complicated to type, but any help would be really appreciated!

    #18145 quote
    Nicolas
    Keymaster
    Master

    Please post the whole code, as I could read it in complete and better understand where is the problem. Thanks.

    #18151 quote
    kg6450
    Participant
    Average

    Ok sure, here it is:

     

    DEFPARAM CumulateOrders = False
    DEFPARAM FlatAfter = 214500
    
    StartTime = 070000
    FinalTime = 100000
    
    // Set Breakout box for between 5pm and 7am
    If Time = 070000 THEN
    hh = highest[n](high)
    ll = lowest[n](low)
    ENDIF
    //Only make trade between 7am and 10am
    If Time >= StartTime AND Time <= FinalTime THEN
    MakeTrade = 1
    ELSE
    MakeTrade = 0
    ENDIF
    
    IF MakeTrade = 1 AND highest[y](high) > hh THEN
    fib = (highest[y](high) - ll) * 0.382
    Entry = ll + fib
    ENDIF
    
    IF MakeTrade = 1 AND highest[y](high) > hh THEN
    SELLSHORT 1 SHARE AT Entry LIMIT
    ENDIF
    
    SET TARGET pPROFIT 50
    SET STOP pLOSS 50
    

    Its still a very rough version but its what I have so far, n = number of bars from 5pm to 7am, and y = number of bars from 7 to 10am

    It would find the significant turning point (or the closest thing to that) between 7 and 10 and calculate the fib from there. Ultimately I want to code it to work both ways, but for now while I’m still getting to grip with coding I’m just doing the break to the upside.

    I was also wondering, since it should only technically make one trade a day if conditions are met, do I have to tell it to restart every day? or will it automatically start doing that at 5pm anyway?

    Thanks 🙂

    #18194 quote
    kg6450
    Participant
    Average

    Hi Nicolas, do you have any ideas about how I can tackle this? Or is it a lost cause haha

    #21926 quote
    GraHal
    Participant
    Master

    Hi KJ

    Did you get any further with this one please? Maybe it slipped through a crack in Nicolas busy schedule? He might catch sight of it again now.

    I manual trade using Fib levels and so I’ve run your code on Demo since 11 Dec and results look very promising – see attached. I made a few very minor changes … I’ll put them on here tomorrow.

    Thanks
    GraHal

    Fib-Retrace.jpg Fib-Retrace.jpg
    #21953 quote
    GraHal
    Participant
    Master

    Here’s my few changes, main change is Buy (Sell in original code??) in Line 25.

    Results attached for DAX 5M @ £1 per point.

    (Why cant I see ‘Insert PRT Code’ again Mods?)

     

    DEFPARAM CumulateOrders = False
    DEFPARAM FlatAfter = 214500
    
    StartTime = 065000
    FinalTime = 113000
    
    // Set Breakout box for between 5pm and 7am
    If Time = 065000 THEN
    hh = highest[80](high)
    ll = lowest[80](low)
    ENDIF
    //Only make trade between 7am and 10am
    If Time >= StartTime AND Time <= FinalTime THEN
    MakeTrade = 1
    ELSE
    MakeTrade = 0
    ENDIF
    
    IF MakeTrade = 1 AND highest[20](high) > hh THEN
    fib = (highest[20](high) - ll) * 0.382
    Entry = ll + fib
    ENDIF
    
    IF MakeTrade = 1 AND highest[20](high) > hh AND close > ExponentialAverage[15](close) THEN
    Buy 1 SHARE AT Entry LIMIT
    ENDIF
    
    SET TARGET pPROFIT 150
    SET STOP pLOSS 240
    Fib-Retrace-1.jpg Fib-Retrace-1.jpg Fib-Retrace-2.jpg Fib-Retrace-2.jpg
    #21964 quote
    JC_Bywan
    Moderator
    Master

    Hi Grahal,

    Maybe Nicolas was installing some upgrades on the website resulting on the “insert PRT code” function temporarily not available, no worry I’ll edit your post with PRT code style

    #21970 quote
    Nicolas
    Keymaster
    Master

    The text editor of forums have 2 tabs, you’ll find them on its upper right side, choose “Visual” one to get the rich text capabilities and the “insert PRT code” button.

    About this topic, I’m sorry, because I’m involved in many ones, this one came out of my head.. Thanks GraHal about the help you give to kg6450. Let him answer to your code fix and see if you were correct about the BUY order instead of the SELLSHORT one.

    Results seems decent, did you test any further in the past data?

    #21977 quote
    GraHal
    Participant
    Master

    I tried both tabs, even Visual Tab did not have insert PRT Code available; also same for me a day or two back. No big deal for me, but I didn’t want you / mods thinking I’m causing you work 🙂

    I’ve got  qty 4 PRT Platforms open (I’m rationalising my 200 Demo Algos! :)) if I can’t see PRT code button again, I’ll close platforms one by one to see if it makes any difference. Maybe this is why I’ve had a few other odd ‘platform scenarios’ this week!?

    The results above are over 100,000 units @ 5M as this is the most history I get with IG.

    Cheers
    Graham

    #21978 quote
    GraHal
    Participant
    Master

    If only we could ‘edit out our crap’ 🙂 … I’m mixing up PRT Platform snags and PRC Website snags now … apologies, disregard the 2nd paragraph above please!! I must slow down my brain & fingers, I must slow down my ………. ! haha

    GraHal

    #21983 quote
    Nicolas
    Keymaster
    Master

    I’m glad to have you on board  GraHal,  always diverting on a Saturday evening 🙂

    GraHal thanked this post
Viewing 15 posts - 1 through 15 (of 26 total)
  • You must be logged in to reply to this topic.

Entry on fib retracement?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
kg6450 @kg6450 Participant
Summary

This topic contains 25 replies,
has 4 voices, and was last updated by GraHal
9 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 12/09/2016
Status: Active
Attachments: No files
Logo Logo
Loading...