Zorro-Project Fair Value Gap/FVG Script
Zorro FVG⌗

WIP…
// sleep FVG ///////////////////
#include <profile.c>
#include <stdio.h>
#define FVG_len 20
#define FVG_min 0.0025
#define FVG_plotHL false
#define FVG_plot true
typedef struct {
int tf; // Timeframe in min, e.g 240 (4H)
bool bullish; // False = bearish
double start;
double half;
double end;
int expires; // How many bars FVG is valid for
// struct FVG* child; // Pointer to another FVG struct
} FVG;
FVG *FVGs[1024];
function plotline(string n, double Price, int left, int right, int col) {
plotGraph(n, left, Price, LINE, col); // FVG Start
plotGraph(n, right, Price, LINE | END, col);
}
double FVG_compute(FVG fvg) {
char n[32];
var col = GREEN;
if (!fvg.bullish) { // Bearish FVG
sprintf(n, "%-dm", fvg.tf);
col = RED;
} else
sprintf(n, "+%dm", fvg.tf);
double half =
fvg.start + (fvg.end - fvg.start) / fix0(2); // Avoid zero division
if (FVG_plotHL) {
plotline(n, fvg.start, 2, -FVG_len, BLACK); // FVG Start
plotline(n, fvg.end, 0, -FVG_len, BLACK); // FVG End
}
sprintf(n, " HALF", fvg.tf);
plotline(n, half, 1, -FVG_len, col); // FVG Start
return half;
}
function run() {
// BarPeriod = 240; // 4H
Hedge = 2; // Allow hedging
set(LOGFILE, PLOTNOW); // log all trades
StartDate = 20200101;
// EndDate = 20150101;
Verbose = 2;
LookBack = 3; // Needed for FVG
asset("EUR/USD");
Capital = 100000;
EntryTime = FVG_len;
Risk = 1000;
// vars HT_FVG = series(price),1440) //for later, going to implement MTF
// FVG's. - sleep
set(PARAMETERS);
if (priceC(1) > priceO(1)) { // Bullish FVG
if (priceL(0) >= priceH(2) + FVG_min) {
FVG fvg;
fvg.tf = BarPeriod;
fvg.bullish = true;
fvg.start = priceH(2);
fvg.end = priceL(0);
fvg.expires = FVG_len;
FVGs[0] = &fvg;
printf("\n%d\n", FVGs[0]->start);
Entry = FVG_compute(fvg) - priceC(0);
Stop = priceL(1);
TakeProfit = 0.01;
enterLong();
}
} else if (priceH(0) + FVG_min <= priceL(2)) { // Bearish FVG
FVG fvg;
fvg.tf = BarPeriod;
fvg.bullish = false;
fvg.start = priceL(2);
fvg.end = priceH(0);
fvg.expires = FVG_len;
FVGs[0] = &fvg;
printf("\n%d\n", FVGs[0]->start);
Entry = priceC(0) - FVG_compute(fvg);
Stop = priceH(1);
TakeProfit = 0.01;
enterShort();
}
}
function main() {
// vars FVGs[1000]
}
Read other posts