show icon in Max high candle
Created at 01 Sep 2022, 17:56
show icon in Max high candle
01 Sep 2022, 17:56
i want to show an arrow in max candle but i dont know how to get this candle time in a period
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System.Collections.Generic;
using System.Linq;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class AWBoxLiveTime : Indicator
{
[Parameter("Period", DefaultValue = 10, MinValue = 1, Group = "Rectangle")]
public int Period { get; set; }
[Parameter("Color", DefaultValue = "Red", Group = "Rectangle")]
public string Color { get; set; }
[Parameter("LineStyle", DefaultValue = LineStyle.Solid, Group = "Rectangle")]
public LineStyle ls { get; set; }
[Parameter("Thickness", DefaultValue = 2, Group = "Rectangle")]
public int Thickness { get; set; }
[Parameter("Mid Line", DefaultValue = true, Group = "Mid Line")]
public bool Midline { get; set; }
[Parameter("Mid Line Color", DefaultValue = "Red", Group = "Mid Line")]
public string Color2 { get; set; }
[Parameter("Mid Line Style", DefaultValue = LineStyle.Lines, Group = "Mid Line")]
public LineStyle ls2 { get; set; }
[Parameter("Mid Line Thickness", DefaultValue = 1, Group = "Mid Line")]
public int Thickness2 { get; set; }
[Parameter("Mid Time Line", DefaultValue = true, Group = "Mid Line")]
public bool MidTimeline { get; set; }
protected override void Initialize()
{
}
public override void Calculate(int index)
{
var rectangle = Chart.DrawRectangle("rectangle_sample", Bars.Count, Bars.LowPrices.Minimum(Period), Chart.LastVisibleBarIndex - Period, Bars.HighPrices.Maximum(Period), Color);
rectangle.IsInteractive = false;
rectangle.IsFilled = false;
rectangle.LineStyle = ls;
rectangle.Thickness = Thickness;
Chart.DrawIcon("iconName", ChartIconType.DownArrow,GetHighLowInSelection().Point1.BarIndex, Bars.HighPrices.Maximum(Period), "Blue");
if (Midline)
{
var trendLine = Chart.DrawTrendLine("trendLine", Chart.LastVisibleBarIndex + 1, (Bars.LowPrices.Minimum(Period) + Bars.HighPrices.Maximum(Period)) / 2, Chart.LastVisibleBarIndex - Period, (Bars.LowPrices.Minimum(Period) + Bars.HighPrices.Maximum(Period)) / 2, Color2, Thickness2, ls2);
}
if (MidTimeline)
{
var trendLine1 = Chart.DrawTrendLine("TimeLine",(Chart.LastVisibleBarIndex+Chart.LastVisibleBarIndex - Period)/2,Bars.HighPrices.Maximum(Period),(Chart.LastVisibleBarIndex+Chart.LastVisibleBarIndex - Period)/2,Bars.LowPrices.Minimum(Period), Color2, Thickness2, ls2);
}
}
private ChartPoints GetHighLowInSelection()
{
var priceMax = double.MinValue;
var priceMin = double.MaxValue;
int barIndexMin = -1;
int barIndexMax = -1;
for (int i = Chart.LastVisibleBarIndex; i >= Chart.LastVisibleBarIndex-Period; i++)
{
var high = Bars.HighPrices[i];
var low = Bars.LowPrices[i];
if (high > priceMax)
{
priceMax = high;
barIndexMax = i;
}
if (low < priceMin)
{
priceMin = low;
barIndexMin = i;
}
}
var maximum = new ChartPoint(barIndexMax, priceMax);
var minimum = new ChartPoint(barIndexMin, priceMin);
return new ChartPoints(minimum, maximum);
}
class ChartPoint
{
public ChartPoint(int barIndex, double price)
{
BarIndex = barIndex;
Price = price;
}
public int BarIndex { get; private set; }
public double Price { get; private set; }
}
class ChartPoints
{
public ChartPoints(ChartPoint point1, ChartPoint point2)
{
Point1 = point1;
Point2 = point2;
}
public ChartPoint Point1 { get; private set; }
public ChartPoint Point2 { get; private set; }
}
}
}
Replies
PanagiotisCharalampous
05 Sep 2022, 10:19
Hi khoshroomahdi,
Your arrows are set at the level you define i.e. Bars.HighPrices.Maximum(Period) and Bars.LowPrices.Minimum(Period)
Chart.DrawIcon("iconName", ChartIconType.DownTriangle,GetHighLowInSelection().Point2.BarIndex, Bars.HighPrices.Maximum(Period), Color2);
Chart.DrawIcon("iconName2", ChartIconType.UpTriangle,GetHighLowInSelection().Point1.BarIndex, Bars.LowPrices.Minimum(Period), Color2);
If you need them at a different place, you need to add/subtract distance accordingly.
Best Regards,
Panagiotis
Join us on Telegram and Facebook
@PanagiotisCharalampous
IRCtrader
02 Sep 2022, 01:23 ( Updated at: 21 Dec 2023, 09:22 )
RE: SHOW arrow in max and min candle in period
i fix this but i have a mini problem with distance betwwen arrow and candle. how can i fix it...
i want to add normal space between arrow and line.
@IRCtrader