PGX
October 7, 2023, 1:19pm
1
Would be really great if someone could create a bullish and bearish FVG indicator with option to leave or close when mitigated , it’s all I use on trading view along with standard ICT stuff …
Fair Value Gaps are Essential when trading off the algorithms macros day to day . I won’t get into why ,Bc if you know you know etc…
You could take the TV contributors LM or LuxAlgo free pinescripts and adapt ? Idk I do not code .
Thank You for your consideration
Best
P
const SMA = require("./tools/SMA");
const EMA = require('./tools/EMA');
const WMA = require('./tools/WMA');
const MMA = require('./tools/MMA');
const predef = require("./tools/predef");
const meta = require('./tools/meta');
const medianPrice = require("./tools/medianPrice");
const typicalPrice = require("./tools/typicalPrice");
const trueRange = require("./tools/trueRange");
const p = require("./tools/plotting");
const { ParamType } = meta;
class FairValueGap {
init() {
}
map(d, i, history) {
const prior = history.prior();
if (!prior) {
return;
}
const high = d.high();
const low = d.low();
const close = d.close();
return {
high,
low,
i,
close,
};
}
filter(d) {
return d.high !== undefined;
}
}
function fvgPlotter(canvas, indicatorInstance, history) {
console.log("FVG Plotter");
let i =3;
let gap = indicatorInstance.props.fvgGap;
for(i=3;i<history.size()-1;i++){
let pCandle = history.get(i-1);
let cCandle = history.get(i);
let nCandle = history.get(i+1);
//console.log("pCandle " + Object.keys(pCandle));
//console.log("cCandle " + Object.keys(cCandle));
//console.log("nCandle " + Object.keys(nCandle));
isBullishFVG = pCandle.high < nCandle.low && (nCandle.low - pCandle.high >= gap);
isBearishFVG = pCandle.low > nCandle.high && (pCandle.low - nCandle.high >= gap);
let isBullishMitigated = false;
let isBearishMitigated = false;
if(isBullishFVG ){
for (let k = i; k < history.size(); k++) {
let fCandle = history.get(k);
if(fCandle.low < cCandle.low ){
isBullishMitigated = true;
break;
}
}
}
if(isBearishFVG ){
for (let k = i; k < history.size(); k++) {
let fCandle = history.get(k);
if(fCandle.high > cCandle.high ){
isBearishMitigated = true;
break;
}
}
}
if(isBullishFVG && !isBullishMitigated){
const x = p.x.get(cCandle);
const last = p.x.get(history.get(history.size()-1))
console.log("Drawing Bullish FVG " + x + " " + cCandle.close);
canvas.drawLine(
p.offset(x, (cCandle.high + cCandle.low )/2 ),
p.offset(last, (cCandle.high + cCandle.low )/2),
{
color: indicatorInstance.props.bullishFVGColor,
width: indicatorInstance.props.lineWeight,
opacity: 70
}
);
}
if(isBearishFVG && !isBearishMitigated){
console.log("Drawing Bearish FVG");
const x = p.x.get(cCandle);
const last = p.x.get(history.get(history.size()-1))
canvas.drawLine(
p.offset(x, (cCandle.low + cCandle.high) /2 ),
p.offset(last, (cCandle.low + cCandle.high) /2),
{
color: indicatorInstance.props.bearishFVGColor,
width: indicatorInstance.props.lineWeight,
opacity: 70
}
);
}
}
}
module.exports = {
name: "FairValueGap",
description: "Vinay-FairValueGap",
calculator: FairValueGap,
params: {
bearishFVGColor: predef.paramSpecs.color("#fcba03"),
bullishFVGColor: predef.paramSpecs.color("#03fcf8"),
lineWeight: predef.paramSpecs.number(2, 1, 1, 5),
fvgGap:predef.paramSpecs.number(1.0, .1, 0.00001),
},
tags: ['vinay'],
inputType: meta.InputType.BARS,
plotter: [
predef.plotters.custom(fvgPlotter),
],
};
1 Like