Description
these darvas boxes are a variant of my darvas box indicator that attempt to take advantage of late asia session breakouts when volatility begins
using cAlgo.API;
using System;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class DarvasBox : Indicator
{
private double boxTop;
private double boxBottom;
private bool isBoxActive;
private int boxStart;
private int boxCount;
[Parameter("Tick Percentage", DefaultValue = 0.5, MinValue = 0, MaxValue = 100)]
public double TickPercentage { get; set; }
protected override void Initialize()
{
isBoxActive = false;
boxCount = 0;
}
public override void Calculate(int index)
{
if (index <= 0)
return;
// Check if the current index is within the Asian session
if (!IsAsianSession(index))
return;
if (isBoxActive)
{
// Close the box if price goes below 50% of the box or above 50% of the box
if (MarketSeries.Low[index] < boxBottom * (1 - TickPercentage / 100) || MarketSeries.High[index] > boxTop * (1 + TickPercentage / 100))
{
DrawDarvasBox(boxStart, index);
isBoxActive = false;
}
}
else
{
// Open a new box if the high breaks the previous high
if (MarketSeries.High[index] > MarketSeries.High[index - 1])
{
boxTop = MarketSeries.High[index];
boxBottom = MarketSeries.Low[index];
boxStart = index;
isBoxActive = true;
}
}
}
private void DrawDarvasBox(int startIndex, int endIndex)
{
// Draw Darvas Box lines
double boxHeight = Symbol.PipSize * 10; // You can adjust the height as needed
ChartObjects.DrawLine("DarvasBoxTop" + boxCount, startIndex, boxTop, endIndex, boxTop, Colors.Blue, 3, LineStyle.Solid);
ChartObjects.DrawLine("DarvasBoxBottom" + boxCount, startIndex, boxBottom, endIndex, boxBottom, Colors.Blue, 3, LineStyle.Solid);
boxCount++;
}
private bool IsAsianSession(int index)
{
DateTime currentTime = MarketSeries.OpenTime[index];
DateTime asianOpen = new DateTime(currentTime.Year, currentTime.Month, currentTime.Day, 0, 0, 0);
DateTime asianClose = new DateTime(currentTime.Year, currentTime.Month, currentTime.Day, 8, 0, 0);
return currentTime >= asianOpen && currentTime <= asianClose;
}
}
}
DE
DELETED_USER
Joined on 28.06.2022 Blocked
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: DARVASASIA.algo
- Rating: 0
- Installs: 236
- Modified: 18/12/2023 17:40
Note that publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section, please use the Copyright Infringement Notification form to submit a claim.
Comments
Log in to add a comment.
No comments found.