FVG(Fair Value Gap) indicator – convert to Trading Code
Forums › ProRealTime English forum › ProOrder support › FVG(Fair Value Gap) indicator – convert to Trading Code
- This topic has 8 replies, 3 voices, and was last updated 18 hours ago by
Andre Vorster.
-
-
08/07/2025 at 4:17 PM #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
NEXTIF 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)
ENDIFValid = 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
ENDIFIF 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
ENDIFNEXT
ENDIF
RETURN
08/07/2025 at 4:32 PM #249482I deleted the other post in the French forum.
08/07/2025 at 4:36 PM #249483See the images for more clarity when to Buy or Sell.
08/08/2025 at 12:03 PM #249502Post 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:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495// 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 DORI = 1BI = RI//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] = RIIF Not OnMarket THEN // or IF Not ShortOnMarket THENSELLSHORT 1 CONTRACT AT MARKETENDIFENDIFIF High[BI + 1] < Low[BI - 1] THENRangeIdx = RangeIdx + 1//$RangeHigh[RangeIdx] = Low[BI - 1]//$RangeLow[RangeIdx] = High[BI + 1]//$RangeIndex[RangeIdx] = RIIF Not OnMarket THEN // or IF Not LongOnMarket THENBUY 1 CONTRACT AT MARKETENDIFENDIFSET STOP pLOSS 100SET TARGET pPROFIT 300//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//IF (close[RI-1] > open[RI-1]) THEN//DRAWRECTANGLE($RangeIndex[RI], $RangeHigh[RI], TotalBars+20, $RangeLow[RI]) COLOURED(0,0,0,0) FILLCOLOR("Green")//(173,194,201)//ELSE//DRAWRECTANGLE($RangeIndex[RI], $RangeHigh[RI], TotalBars+20, $RangeLow[RI]) COLOURED(0,0,0,0) FILLCOLOR("Red")//(173,194,201)//ENDIF////COLOURED(0,0,0,0) FILLCOLOR(173,194,201)////(0,0,0,30) 201,40,51//ENDIF//NEXT//ENDIF08/08/2025 at 12:14 PM #249503Thank you for moving the post.
Plus Thank you for the script !1 user thanked author for this post.
08/08/2025 at 12:50 PM #249510The 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.08/08/2025 at 9:14 PM #249526It 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.
08/10/2025 at 1:22 PM #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?
08/10/2025 at 1:24 PM #249583Thank you.
I’ll test it in the next 2 days. I want to run it asap 🙂 -
AuthorPosts
Find exclusive trading pro-tools on