Opening Range Breakout with Fib

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #241847 quote
    bertoluce
    Participant
    New

    Dear coders, I am new to ProRealtime, coming from ThinkOrSwim.

    Could you please convert this code. It is very important to me 😉

    MultiTimeFrame would be excellent! Thanks.

    ++++++++++++++++++++++++++++++++++++++++++++

    #Opening Range Fibs
    #Using the first candle to create Fib Support/Resist Levels
    #Added Options to Hide/Show lines

    def na = double.nan;

    input ORBegin = 0930;
    input OREnd = 1000;
    def dayend = 1600;

    input cloud = yes;

    Input FibExt1 = 1.000;
    Input FibExt2 = 1.618;
    Input FibExt3 = 2.000;
    Input FibExt4 = 2.618;
    Input FibExt5 = 3.618;
    Input FibExt6 = 4.236;
    Input ShowORH = yes;
    Input ShowORL = yes;
    Input ShowFibMid = yes;
    Input ShowFibExt1 = yes;
    Input ShowFibExt2 = yes;
    Input ShowFibExt3 = yes;
    Input ShowFibExt4 = yes;
    Input ShowFibExt5 = yes;
    Input ShowFibExt6 = yes;

    input ShowTodayOnly = Yes;
    def s = ShowTodayOnly;

    input extend_lines = yes;

    Def daytime = if (secondsfromtime(ORBegin)>=0 and secondstilltime(dayend)>0 ) then 1 else 0;
    def daytimex = (isnan(close) and daytime);
    def currentday = getday()==getlastday();

    def daysafter = getday() > getlastday();
    def daysbefore = getday() <= getlastday();

    Def ORActive = if secondsfromtime(ORBegin) >= 0 and secondstilltime(OREnd) > 0 then 1 else 0;
    Def today = if s == 0 OR getday()==getlastday() AND secondsfromtime(ORBegin)>=0 then 1 else 0;

    Def ORHigh = if daysafter then na
    else if (extend_lines and isnan(close)) then ORHigh[1]
    else if ORHigh[1] == 0 or ORActive[1] == 0 AND ORActive == 1 then high
    else if ORActive AND high > ORHigh[1] then high
    else ORHigh[1];

    Def ORLow = if daysafter then na
    else if (extend_lines and isnan(close)) then ORlow[1]
    else if ORLow[1] == 0 or ORActive[1] == 0 AND ORActive == 1 then low
    else if ORActive AND low < ORLow[1] then low
    else ORLow[1];

    Def ORWidth = ORHigh – ORLow;

    Def fib_mid = (ORHigh+ORLow)/2;
    Def fib_ext_up1 = ORHigh + ORWidth*(FibExt1 – 1);
    Def fib_ext_down1 = ORLow – ORWidth*(FibExt1 – 1);
    Def fib_ext_up2= ORHigh + ORWidth*(FibExt2 – 1);
    Def fib_ext_down2 = ORLow – ORWidth*(FibExt2 – 1);
    Def fib_ext_up3= ORHigh + ORWidth*(FibExt3 – 1);
    Def fib_ext_down3 = ORLow – ORWidth*(FibExt3 – 1);
    Def fib_ext_up4= ORHigh + ORWidth*(FibExt4 – 1);
    Def fib_ext_down4 = ORLow – ORWidth*(FibExt4 – 1);
    Def fib_ext_up5= ORHigh + ORWidth*(FibExt5 – 1);
    Def fib_ext_down5 = ORLow – ORWidth*(FibExt5 – 1);
    Def fib_ext_up6= ORHigh + ORWidth*(FibExt6 – 1);
    Def fib_ext_down6 = ORLow – ORWidth*(FibExt6 – 1);
    #
    # Define all the plots:
    #
    Plot ORH = if ORActive OR today < 1 OR !ShowORH then double.nan else ORHigh;
    Plot ORL = if ORActive OR today < 1 or !ShowORL then double.nan else ORLow;
    Plot FibMid = if ORActive OR today < 1 or !ShowFibMid then double.nan else fib_mid;
    Plot FibExtUp1 = if ORActive OR today < 1 or !ShowFibExt1 then double.nan else fib_ext_up1;
    Plot FibExtDown1 = if ORActive OR today < 1 or !ShowFibExt1 then double.nan else fib_ext_down1;
    Plot FibExtUp2 = if ORActive OR today < 1 or !ShowFibExt2 then double.nan else fib_ext_up2;
    Plot FibExtDown2 = if ORActive OR today < 1 or !ShowFibExt2 then double.nan else fib_ext_down2;
    Plot FibExtUp3 = if ORActive OR today < 1 or !ShowFibExt3 then double.nan else fib_ext_up3;
    Plot FibExtDown3 = if ORActive OR today < 1 or !ShowFibExt3 then double.nan else fib_ext_down3;
    Plot FibExtUp4=if ORActive OR today < 1 then double.nan else fib_ext_up4;
    Plot FibExtDown4=if ORActive OR today < 1 then double.nan else fib_ext_down4;
    Plot FibExtUp5=if ORActive OR today < 1 then double.nan else fib_ext_up5;
    Plot FibExtDown5=if ORActive OR today < 1 then double.nan else fib_ext_down5;
    Plot FibExtUp6=if ORActive OR today < 1 then double.nan else fib_ext_up6;
    Plot FibExtDown6=if ORActive OR today < 1 then double.nan else fib_ext_down6;

    ORH.setdefaultcolor(color.light_gray);
    ORH.setStyle(curve.Long_DASH);
    ORH.setlineweight(1);
    ORL.setdefaultcolor(color.light_gray);
    ORL.setStyle(curve.Long_DASH);
    ORL.setlineweight(1);
    FibMid.setdefaultcolor(color.gray);
    FibMid.setStyle(curve.SHORT_DASH);
    FibMid.setlineweight(1);
    FibExtUp1.setdefaultcolor(color.gray);
    FibExtUp1.setStyle(curve.SHORT_DASH);
    FibExtUp1.setlineweight(1);
    FibExtDown1.setdefaultcolor(color.gray);
    FibExtDown1.setStyle(curve.SHORT_DASH);
    FibExtDown1.setlineweight(1);
    FibExtUp2.setdefaultcolor(color.gray);
    FibExtUp2.setStyle(curve.SHORT_DASH);
    FibExtUp2.setlineweight(1);
    FibExtDown2.setdefaultcolor(color.gray);
    FibExtDown2.setStyle(curve.SHORT_DASH);
    FibExtDown2.setlineweight(1);
    FibExtUp3.setdefaultcolor(color.gray);
    FibExtUp3.setStyle(curve.SHORT_DASH);
    FibExtUp3.setlineweight(1);
    FibExtDown3.setdefaultcolor(color.gray);
    FibExtDown3.setStyle(curve.SHORT_DASH);
    FibExtDown3.setlineweight(1);
    FibExtUp4.setdefaultcolor(color.gray);
    FibExtUp4.setStyle(curve.SHORT_DASH);
    FibExtUp4.setlineweight(1);
    FibExtDown4.setdefaultcolor(color.gray);
    FibExtDown4.setStyle(curve.SHORT_DASH);
    FibExtDown4.setlineweight(1);
    FibExtUp5.setdefaultcolor(color.gray);
    FibExtUp5.setStyle(curve.SHORT_DASH);
    FibExtUp5.setlineweight(1);
    FibExtDown5.setdefaultcolor(color.gray);
    FibExtDown5.setStyle(curve.SHORT_DASH);
    FibExtDown5.setlineweight(1);
    FibExtUp6.setdefaultcolor(color.red);
    FibExtUp6.setStyle(curve.SHORT_DASH);
    FibExtUp6.setlineweight(1);
    FibExtDown6.setdefaultcolor(color.red);
    FibExtDown6.setStyle(curve.SHORT_DASH);
    FibExtDown6.setlineweight(1);

    AddCloud(ORH, FIBmid, Color.dark_GREEN, Color.dark_GREEN);
    AddCloud(FIBmid, ORL, Color.dark_RED, Color.dark_RED);

    AddChartBubble((showFibExt1), FibExt1 *1, “1,00 0%”, Color.dark_GREEN, yes);
    AddChartBubble((showFibExt2), FibExt2 *1, “1.618 0%”, Color.dark_RED, yes);

    #242473 quote
    Iván González
    Moderator
    Master

    Here it is:

    //--------------------------------------------//
    //PRC_Fibonacci Open Range
    //version = 0
    //13.01.2025
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //--------------------------------------------//
    // inputs
    //--------------------------------------------//
    ORBegin=090000
    OREnd=100000
    ShowpastFibo=1
    //--------------------------------------------//
    // Calculate Open Range
    //--------------------------------------------//
    if gettimeframe<=3600 then
    once ORHigh=0
    once ORLow=9999999
    // Puntos de Fibonacci
    ORWidth = ORHigh - ORLow
    FibMid = (ORHigh + ORLow) / 2
    FibExtUp1 = ORHigh + ORWidth * (1.0)
    FibExtDown1 = ORLow - ORWidth * (1.0)
    FibExtUp2 = ORHigh + ORWidth * (1.618)
    FibExtDown2 = ORLow - ORWidth * (1.618)
    FibExtUp3 = ORHigh + ORWidth * (2.0)
    FibExtDown3 = ORLow - ORWidth * (2.0)
    FibExtUp4 = ORHigh + ORWidth * (2.618)
    FibExtDown4 = ORLow - ORWidth * (2.618)
    FibExtUp5 = ORHigh + ORWidth * (3.618)
    FibExtDown5 = ORLow - ORWidth * (3.618)
    FibExtUp6 = ORHigh + ORWidth * (4.236)
    FibExtDown6 = ORLow - ORWidth * (4.236)
    
    if opentime>=ORBegin and opentime[1]<ORBegin then
    drawsegment(OREndIdx,ORHigh,barindex,ORHigh)coloured("red")style(line,1)
    drawsegment(OREndIdx,ORLow,barindex,ORLow)coloured("green")style(line,1)
    drawsegment(OREndIdx,FibMid,barindex,FibMid)coloured("blue")style(dottedline,1)
    drawsegment(OREndIdx,ORLow,barindex,ORLow)coloured("green")style(line,1)
    if ShowpastFibo then
    drawsegment(OREndIdx,FibExtDown1,barindex,FibExtDown1)coloured("green")style(dottedline,1)
    drawsegment(OREndIdx,FibExtDown2,barindex,FibExtDown2)coloured("green")style(dottedline,1)
    drawsegment(OREndIdx,FibExtDown3,barindex,FibExtDown3)coloured("green")style(dottedline,1)
    drawsegment(OREndIdx,FibExtDown4,barindex,FibExtDown4)coloured("green")style(dottedline,1)
    drawsegment(OREndIdx,FibExtDown5,barindex,FibExtDown5)coloured("green")style(dottedline,1)
    drawsegment(OREndIdx,FibExtDown6,barindex,FibExtDown6)coloured("green")style(dottedline,1)
    drawsegment(OREndIdx,FibExtUp1,barindex,FibExtUp1)coloured("red")style(dottedline,1)
    drawsegment(OREndIdx,FibExtUp2,barindex,FibExtUp2)coloured("red")style(dottedline,1)
    drawsegment(OREndIdx,FibExtUp3,barindex,FibExtUp3)coloured("red")style(dottedline,1)
    drawsegment(OREndIdx,FibExtUp4,barindex,FibExtUp4)coloured("red")style(dottedline,1)
    drawsegment(OREndIdx,FibExtUp5,barindex,FibExtUp5)coloured("red")style(dottedline,1)
    drawsegment(OREndIdx,FibExtUp6,barindex,FibExtUp6)coloured("red")style(dottedline,1)
    endif
    ORHigh=high
    ORLow=low
    ORBeginIdx=barindex
    drawvline(barindex)style(dottedline3)coloured("grey")
    elsif opentime>=ORBegin and opentime<=OREnd then
    ORHigh=max(ORHigh,high)
    ORLow=min(ORLow,low)
    elsif opentime>OREnd and opentime[1]<=OREnd then
    OREndIdx=barindex[1]
    drawsegment(ORBeginIdx,ORHigh,OREndIdx,ORHigh)coloured("red")style(line,3)
    drawsegment(ORBeginIdx,ORLow,OREndIdx,ORLow)coloured("green")style(line,3)
    elsif islastbarupdate then
    drawsegment(barindex+10,ORHigh,OREndIdx,ORHigh)coloured("red")style(line,1)
    drawsegment(barindex+10,ORLow,OREndIdx,ORLow)coloured("green")style(line,1)
    drawsegment(OREndIdx,FibMid,barindex+10,FibMid)coloured("blue")style(dottedline,1)
    drawsegment(OREndIdx,ORLow,barindex+10,ORLow)coloured("green")style(line,1)
    drawsegment(OREndIdx,FibExtDown1,barindex+10,FibExtDown1)coloured("green")style(dottedline,1)
    drawsegment(OREndIdx,FibExtDown2,barindex+10,FibExtDown2)coloured("green")style(dottedline,1)
    drawsegment(OREndIdx,FibExtDown3,barindex+10,FibExtDown3)coloured("green")style(dottedline,1)
    drawsegment(OREndIdx,FibExtDown4,barindex+10,FibExtDown4)coloured("green")style(dottedline,1)
    drawsegment(OREndIdx,FibExtDown5,barindex+10,FibExtDown5)coloured("green")style(dottedline,1)
    drawsegment(OREndIdx,FibExtDown6,barindex+10,FibExtDown6)coloured("green")style(dottedline,1)
    drawsegment(OREndIdx,FibExtUp1,barindex+10,FibExtUp1)coloured("red")style(dottedline,1)
    drawsegment(OREndIdx,FibExtUp2,barindex+10,FibExtUp2)coloured("red")style(dottedline,1)
    drawsegment(OREndIdx,FibExtUp3,barindex+10,FibExtUp3)coloured("red")style(dottedline,1)
    drawsegment(OREndIdx,FibExtUp4,barindex+10,FibExtUp4)coloured("red")style(dottedline,1)
    drawsegment(OREndIdx,FibExtUp5,barindex+10,FibExtUp5)coloured("red")style(dottedline,1)
    drawsegment(OREndIdx,FibExtUp6,barindex+10,FibExtUp6)coloured("red")style(dottedline,1)
    else
    ORHigh=ORHigh
    ORLow=ORLow
    endif
    endif
    //--------------------------------------------//
    return
    bertoluce thanked this post
    #242581 quote
    bertoluce
    Participant
    New

    Dear Iván

    Thank you very much for your effort 😉

    PRT is complaining about errors. Please find attached two screenshots with these errors.

    Could you please fix it? Thanks, Roberto

    #242588 quote
    bertoluce
    Participant
    New

    This is the error when exiting …

    #242590 quote
    Iván González
    Moderator
    Master

    Hi!

    This is because you have not copied the code correctly…
    You will see that if you copy the code shared above you have no problem.

    However, please find attached the itf file for your import.

    bertoluce thanked this post
    #242630 quote
    bertoluce
    Participant
    New

    Gracias por programar este código Iván. Me ayudará a utilizar mejor PRT.

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

Opening Range Breakout with Fib


ProBuilder: Indicators & Custom Tools

New Reply
Author
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by bertoluce
1 year ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 12/28/2024
Status: Active
Attachments: 4 files
Logo Logo
Loading...