FVG(Fair Value Gap) indicator – convert to Trading Code

Forums ProRealTime English forum ProOrder support FVG(Fair Value Gap) indicator – convert to Trading Code

Viewing 9 posts - 1 through 9 (of 9 total)
  • #249481

    Hello.

    Can someone please help me modify this indicator so that it can be used in AutoTrader to open and close trades?
    The indicator works, but I need it to open buy/sell positions when it displays an indication on the screen.
    Also needed only run between certain times of the day as well as position Qty and TS options.

    Thank you.

     

    // FVG (Fair Value Gap) indicator

    DEFPARAM DrawOnLastBarOnly = true
    DEBUG = 0

    // Start of code, don’t change anything below

    IF IsLastBarUpdate THEN
    $RangeHigh[0] = 0
    $RangeLow[0] = 0
    $RangeIndex[0] = 0
    RangeIdx = 0
    BI = 0
    B = 0
    RI = 0
    TotalBars = BarIndex[0]

    IF DEBUG = 1 THEN
    DRAWTEXT(“Total bars: #TotalBars#”, BarIndex[0], High[0])
    ENDIF

    // List all imbalance
    FOR RI = 1 TO TotalBars – 2 DO
    BI = BarIndex[RI]
    //drawtext(“#BI#”, BI, High[RI])
    IF High[BI – 1] < Low[BI + 1] THEN
    RangeIdx = RangeIdx + 1
    $RangeHigh[RangeIdx] = Low[BI + 1]
    $RangeLow[RangeIdx] = High[BI – 1]
    $RangeIndex[RangeIdx] = RI
    ENDIF
    IF High[BI + 1] < Low[BI – 1] THEN
    RangeIdx = RangeIdx + 1
    $RangeHigh[RangeIdx] = Low[BI – 1]
    $RangeLow[RangeIdx] = High[BI + 1]
    $RangeIndex[RangeIdx] = RI
    ENDIF
    NEXT

    IF DEBUG = 1 THEN
    DRAWTEXT(“Imbalance found: #RangeIdx#”, BarIndex[0], Low[0])
    ENDIF

    // Remove mitigated imbalance
    FOR RI = 1 TO RangeIdx DO
    IF DEBUG = 1 THEN
    DRAWRECTANGLE($RangeIndex[RI] – 1, $RangeHigh[RI], $RangeIndex[RI] + 1, $RangeLow[RI]) COLOURED(0,0,200)
    //DRAWRECTANGLE($RangeIndex[RI] – 1, $RangeHigh[RI], $RangeIndex[RI] + 1, $RangeLow[RI]) COLOURED(0,0,200)
    ENDIF

    Valid = 1
    FOR B = $RangeIndex[RI] + 2 TO TotalBars DO
    LB = Low[BarIndex[B]]
    HB = High[BarIndex[B]]
    // Candle is above or below our zone, ignore it
    IF LB >= $RangeHigh[RI] OR HB <= $RangeLow[RI] THEN
    IF DEBUG = 1 THEN
    DRAWTEXT(“Out”, B, High[BarIndex[B]])
    ENDIF
    CONTINUE
    ENDIF

    IF LB <= $RangeLow[RI] THEN
    // Candle engulfs our zone, so imbalance is mitigated
    IF HB >= $RangeHigh[RI] THEN
    IF DEBUG = 1 THEN
    DRAWTEXT(“Mitigated”, B, High[BarIndex[B]])
    ENDIF
    Valid = 0
    BREAK
    ENDIF
    IF DEBUG = 1 THEN
    DRAWTEXT(“High”, B, High[BarIndex[B]])
    ENDIF
    $RangeLow[RI] = HB
    ELSE
    // In this case, Low is within the zone
    IF DEBUG = 1 THEN
    DRAWTEXT(“Low”, B, High[BarIndex[B]])
    ENDIF
    $RangeHigh[RI] = LB
    ENDIF
    NEXT
    IF Valid = 1 THEN
    DRAWRECTANGLE($RangeIndex[RI], $RangeHigh[RI], TotalBars+2000, $RangeLow[RI]) COLOURED(0,0,0,0) FILLCOLOR(173,194,201)
    //COLOURED(0,0,0,0) FILLCOLOR(173,194,201)
    //(0,0,0,30) 201,40,51
    ENDIF

    NEXT

    ENDIF

    RETURN

    #249482

    I deleted the other post in the French forum.

     

    #249483

    See the images for more clarity when to Buy or Sell.

    #249502

    Post your topic in the correct forum:
    _ ProRealTime Platform Support: only platform related issues.
    _ ProOrder: only strategy topics.
    _ ProBuilder: only indicator topics.
    _ ProScreener: only screener topics
    _ General Discussion: any other topics.
    _ Welcome New Members: for new forum members to introduce themselves.

    I moved it from the ProScreener support.

    There you go:

     

    #249503

    Thank you for moving the post.
    Plus Thank you for the script !

    1 user thanked author for this post.
    #249510

    The script is working – does open/close trades.
    Will it be possible for the script to only open positions when the indicator(grey) is activated. When the indicator draws on the screen and not trade at any other time.
    The earlier attached images shows what I try to say in words when to open positions.

    #249526

    It uses the same code, so it can only enter when the indicator detects a FVG.ù

    If it doesn’t, please post the name of the instrument traded, timeframe used, date and time of one or more incorrect enrtries.

     

    #249582

    @ ROBERTO

    Sorry, but I feel that with all the //  that you’ve placed, this script is only selecting these lines:

    IF High[BI – 1] < Low[BI + 1] THEN              or

    IF High[BI + 1] < Low[BI – 1] THEN

    where, however, B1 is always = 1.      Therefore the lines become:

    IF High[0] < Low[2] THEN       or

    IF High[2] < Low[0] THEN

    Is it right or maybe there should be less //  to filter more variables?

     

    #249583

    Thank you.
    I’ll test it in the next 2 days. I want to run it asap 🙂

Viewing 9 posts - 1 through 9 (of 9 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login