Hi guys My Name is Rade, im new please help
Hi guys My Name is Rade, im new please help
19 Aug 2024, 21:35
please help im trying to write this code
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Collections;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
[Robot(AccessRights = AccessRights.None, AddIndicators = true)]
public class SessionFVGHunter : Robot
{
[Parameter(DefaultValue = 3)]
public int FVGBars { get; set; } // Number of bars for FVG calculation
[Parameter(DefaultValue = 14)]
public int ATRPeriod { get; set; } // ATR period
[Parameter(DefaultValue = 1)]
public double FVGThreshold { get; set; } // Threshold for FVG strength
private AverageTrueRange _atr;
private DateTime _londonOpen = DateTime.Today.AddHours(9); // 9 AM London time
private DateTime _newYorkOpen = DateTime.Today.AddHours(16); // 4 PM New York time
protected override void OnStart()
{
_atr = Indicators.AverageTrueRange(ATRPeriod, MovingAverageType.Simple);
}
protected override void OnTick()
{
DetectFairValueGap();
}
private void DetectFairValueGap()
{
DateTime now = Server.Time;
if (now.Hour < 4 || now.Hour > 17) // Check if within working hours
return;
int lastIndex = Bars.Count - 1;
if (lastIndex < FVGBars)
return;
for (int i = FVGBars; i <= lastIndex; i++)
{
double open1 = Bars.OpenPrices[i - FVGBars];
double high1 = Bars.HighPrices[i - FVGBars];
double low1 = Bars.LowPrices[i - FVGBars];
double close1 = Bars.ClosePrices[i - FVGBars];
double high3 = Bars.HighPrices[i];
double low3 = Bars.LowPrices[i];
if ((open1 > close1 && low1 > high3) || (open1 < close1 && high1 < low3))
{
double fvgRange = high1 - low1;
double atrValue = _atr.Result[i];
double fvgStrength = fvgRange / atrValue;
if (fvgStrength >= FVGThreshold)
{
DateTime fvgTime = Bars.OpenTimes[i - FVGBars];
string gapType = open1 > close1 ? "Bearish" : "Bullish";
double equilibrium = (high1 + low1) / 2; // Calculate equilibrium of the FVG
Print("Detected {0} FVG at {1} with strength {2}", gapType, fvgTime, fvgStrength);
DrawFairValueGap(i - FVGBars, high1, low1, equilibrium);
// Check market behavior around the FVG
CheckMarketBehavior(i, equilibrium);
}
}
}
}
private void DrawFairValueGap(int index, double high, double low, double equilibrium)
{
// Ensure the index is within valid range
if (index < 0 || index >= Bars.Count)
{
Print("Index out of range.");
return;
}
// Draw the range of the FVG with a single line from high to low
ChartObjects.DrawLine("FVG_Range_" + index, index, high, index, low, Color.Red, 2, LineStyle.Solid);
// Draw the equilibrium line for the FVG
ChartObjects.DrawHorizontalLine("FVG_Equilibrium_" + index, equilibrium, Color.Blue, 1, LineStyle.Dots);
}
private void CheckMarketBehavior(int index, double equilibrium)
{
DateTime now = Server.Time;
// Adjust the time range based on session times
DateTime londonStart = DateTime.Today.AddHours(7); // 2 hours before London open
DateTime londonEnd = DateTime.Today.AddHours(9);
DateTime newYorkStart = DateTime.Today.AddHours(14); // 2 hours before New York open
DateTime newYorkEnd = DateTime.Today.AddHours(16);
if ((now >= londonStart && now <= londonEnd) || (now >= newYorkStart && now <= newYorkEnd))
{
// Check if the market tests or touches the equilibrium of the FVG
double currentPrice = Bars.ClosePrices[Bars.Count - 1];
if (currentPrice >= equilibrium - 10 && currentPrice <= equilibrium + 10) // Tolerance range
{
Print("Market price is near FVG equilibrium.");
// Optionally: Place orders, notify, or visualize the FVG here
}
}
}
protected override void OnStop()
{
// Handle cBot stop here
}
}
}
This code needs to tell this Story it happens most of the time before London and New York opening
1. Most Recent Low Created
2. Low Is Taken
3. first FVG
4. Lower Low
5. MSS CReated
6. OB Created
7. 2nd FVG Created
8. Entry (after FVG the gap needs to be left open to validate that shift in the marketing confirming the entry
this happen BEfore London and New York Opens and around London and NY LUnch
PanagiotisCharalampous
20 Aug 2024, 04:51
Hi there,
I don't think anybody will write the strategy for you for free. If you need professional assistance, feel free to contact a consultant
https://ctrader.com/consultants/
Best regards,
Panagiotis
@PanagiotisCharalampous