
Mahdi

Info
Username: | khoshroomahdi |
Name: | Mahdi |
Member since: | 17 Jun 2021 |
About
Signature
Last Algorithm Comments
@AW Moving Cloud: 12 Dec 2021, 22:44
@opit78 how could we have sepeate color for cloud and moving average? for example: different color for fast ema and up cloud.
@AW Moving Cloud: 12 Dec 2021, 22:43
@opit78 May i Use your code to update this indicator?
@Pattern Drawing: 22 Jun 2021, 20:12
why you didin't add this code to internal ctrader tools.? ex: Draw Traingle and fork is better than default tools
@Draw Spread: 18 Jun 2021, 16:54
Please add color parameter. enable $disable label, position on chart parameter
Last Forum Posts
@Fractal Calculate problem: 05 Jan 2023, 12:48
it shows wrong fractal based fractal fomula
Blue line is correct fractal
but my code show red line.
i think DrawUpFractal() and DrawDownFractal() have problems.
PanagiotisChar said:
Hi there,
I cannot understand the problem. Can you explain the issue better?
@Fractal Calculate problem: 03 Jan 2023, 21:16
i make code to draw line between fractal and show distance , pip and percenge
but it has problem to calculate fracral.
using cAlgo.API;
using System;
using System.Collections.Generic;
using System.Text;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class AwFractal : Indicator
{
private class SwingPoint
{
public int Index { get; set; }
public double Price { get; set; }
public SwingPoint()
{
Index = 0;
Price = double.MaxValue;
}
public SwingPoint(int index, double price)
{
Index = index;
Price = price;
}
}
#region Fields
// Bar Index
private int _index;
// Direction of the Fractal
private Direction direction = Direction.Down;
// Price of recent High
private double high;
// Price of recent Low
private double low;
private bool isBullish;
private SwingPoint swingPoint;
private List<SwingPoint> swingPointList;
private enum Direction
{
Up,
Down
}
#endregion Fields
#region Parameters
[Parameter("Period", DefaultValue = 5, MinValue = 5, Group = "Fractal")]
public int Period { get; set; }
[Parameter("Show Distance?", DefaultValue = false, Group = "Fractal")]
public bool ShowDistance { get; set; }
[Parameter("Show Pip?", DefaultValue = false, Group = "Fractal")]
public bool ShowPip { get; set; }
[Parameter("Show Percentage?", DefaultValue = true, Group = "Fractal")]
public bool ShowPercentChange { get; set; }
#endregion Parameters
#region Output
[Output("Fractal", LineColor = "Red", Thickness = 2, PlotType = PlotType.Line)]
public IndicatorDataSeries Result { get; set; }
#endregion Output
public override void Calculate(int index)
{
_index = index;
low = Bars.LowPrices.LastValue;
high = Bars.HighPrices.LastValue;
if (Bars.ClosePrices.Count < 2)
return;
switch (direction)
{
case Direction.Up:
DrawUpFractal();
break;
case Direction.Down:
default:
DrawDownFractal();
break;
}
}
protected override void Initialize()
{
swingPoint = new SwingPoint();
swingPointList = new List<SwingPoint>();
}
#region Append Text
public string GetFractalText(double currentValue, double previousValue, double thirdValue)
{
StringBuilder sb = new StringBuilder();
if (ShowDistance)
AppendDistance(sb);
if (ShowPip)
AppendPip(sb);
if (ShowPercentChange)
AppendPercentageChange(currentValue, previousValue, thirdValue, sb);
return sb.ToString();
}
private void AppendPercentageChange(double currentValue, double previousValue, double thirdValue, StringBuilder sb)
{
if (ShowDistance || ShowPip)
sb.AppendLine();
string sign = isBullish ? "+" : "-";
string percentage = (isBullish ? CalculatePercentageChange(thirdValue, previousValue, currentValue) : CalculatePercentageChange(thirdValue, previousValue, currentValue)).ToString("N0");
sb.Append(string.Format("{0}{1}%", sign, percentage));
}
private void AppendDistance(StringBuilder sb)
{
sb.Append((swingPointList[swingPointList.Count - 1].Index - swingPointList[swingPointList.Count - 2].Index).ToString(""));
}
private void AppendPip(StringBuilder sb)
{
if (ShowDistance)
sb.AppendLine();
sb.Append(((swingPointList[swingPointList.Count - 1].Price - swingPointList[swingPointList.Count - 2].Price) / Symbol.PipSize).ToString("N1"));
}
private double CalculatePercentageChange(double third, double previous, double current)
{
double lastChange = Math.Abs(third - previous);
double change = Math.Abs(current - previous);
return 100 * (double)change / lastChange;
}
#endregion Append Text
#region Create Fractal
public void ShowFractalLabel()
{
// Get last value
double currentValue = swingPointList[swingPointList.Count - 1].Price;
// Get second last value
double previousValue = swingPointList[swingPointList.Count - 2].Price;
//get thirdValue
double thirdValue = swingPointList[swingPointList.Count - 3].Price;
isBullish = currentValue > previousValue;
string objName = "FractalLabel" + swingPoint.Index;
Color textColour = isBullish ? "Green" : "Red";
string labelText = GetFractalText(currentValue, previousValue, thirdValue);
ChartText text = Chart.DrawText(name: objName, text: labelText, barIndex: swingPoint.Index, y: swingPoint.Price, color: textColour);
text.VerticalAlignment = isBullish ? VerticalAlignment.Top : VerticalAlignment.Bottom;
text.HorizontalAlignment = HorizontalAlignment.Center;
}
private void DrawDownFractal()
{
int period = Period % 2 == 0 ? Period - 1 : Period;
int middleIndex = _index - period / 2;
double middleValue = Bars.LowPrices[middleIndex];
bool down = true;
for (int i = 0; i < period; i++)
{
if (middleValue > Bars.LowPrices[_index - i])
{
down = false;
break;
}
}
if (down)
{
bool moveExtremum = low <= swingPoint.Price;
bool changeDirection = high >= swingPoint.Price;
if (moveExtremum)
MoveExtremum(low);
else if (changeDirection)
{
SetExtremum(high);
direction = Direction.Up;
}
}
}
private void DrawUpFractal()
{
int period = Period % 2 == 0 ? Period - 1 : Period;
int middleIndex = -_index - period / 2;
double middleValue = Bars.HighPrices[middleIndex];
bool up = true;
for (int i = 0; i < period; i++)
{
if (middleValue < Bars.HighPrices[-_index - i])
{
up = false;
break;
}
}
if (up)
{
bool moveExtremum = high >= swingPoint.Price;
bool changeDirection = low <= swingPoint.Price;
if (moveExtremum)
MoveExtremum(high);
else if (changeDirection)
{
SetExtremum(low);
direction = Direction.Down;
}
}
}
private void MoveExtremum(double price)
{
Result[swingPoint.Index] = double.NaN;
if (swingPointList.Count > 0)
swingPointList.Remove(swingPointList[swingPointList.Count - 1]);
Chart.RemoveObject("FractalLabel" + swingPoint.Index);
SetExtremum(price);
}
private void SetExtremum(double price)
{
swingPoint = new SwingPoint(_index, price);
swingPointList.Add(swingPoint);
Result[swingPoint.Index] = swingPoint.Price;
if (swingPointList.Count < 2)
return;
ShowFractalLabel();
}
#endregion Create Fractal
}
}
@ctrader 4.4.19 doesn't save line style,thickness: 20 Nov 2022, 14:26
4.4.19 is aweful
for a trader that use line, fibo, rectangle in chart is terrible that set every line color, thickness, fibo level and etc
pleeeeease fix that soooooon
@show icon in Max high candle: 02 Sep 2022, 01:23
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.DownTriangle,GetHighLowInSelection().Point2.BarIndex, Bars.HighPrices.Maximum(Period), Color2);
Chart.DrawIcon("iconName2", ChartIconType.UpTriangle,GetHighLowInSelection().Point1.BarIndex, Bars.LowPrices.Minimum(Period), Color2);
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-Period; i <= Chart.LastVisibleBarIndex;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; }
}
}
}
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.
@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; }
}
}
}
@ctrader 4.3 suspend this code: 08 Jul 2022, 12:32
PanagiotisCharalampous said:
Hi khoshroomahdi,
You need to be more specific regarding what is not working.
Best Regards,
Panagiotis
Arguments out of range error in logs.
@ctrader 4.3 suspend this code: 08 Jul 2022, 08:27
i have a problem with this code in 4.3
but it works in 4.1
using cAlgo.API;
using System;
using Microsoft.Win32;
namespace cAlgo
{
// This sample indicator shows how to add a text box control on your chart
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class AWCalcVolume : Indicator
{
double risk;
double pip;
TextBox textBox3 = new TextBox();
[Parameter("Horizontal Alignment ", DefaultValue = HorizontalAlignment.Left)]
public HorizontalAlignment HAlignment { get; set; }
[Parameter("Vertical Alignment", DefaultValue = VerticalAlignment.Top)]
public VerticalAlignment VAlignment { get; set; }
[Parameter("Orientation", DefaultValue = Orientation.Horizontal)]
public Orientation Orientation1 { get; set; }
[Parameter("Color", DefaultValue = "Red")]
public string color { get; set; }
protected override void Initialize()
{
var mainStackPanel = new StackPanel
{
HorizontalAlignment = HAlignment,
VerticalAlignment = VAlignment,
Orientation = Orientation1
};
var StackPanel1 = new StackPanel
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Orientation = Orientation.Vertical
};
var StackPanel2 = new StackPanel
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Orientation = Orientation.Vertical,
Margin = 3
};
var StackPanel3 = new StackPanel
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Orientation = Orientation.Vertical
};
var textBlock1 = new TextBlock
{
ForegroundColor = color,
HorizontalAlignment = HorizontalAlignment.Center,
Text = "Risk%"
};
var textBox1 = new TextBox
{
ForegroundColor = color,
HorizontalAlignment = HorizontalAlignment.Center,
Width = 50,
BorderThickness = 2,
BorderColor = color,
TextAlignment = TextAlignment.Center
};
var textBlock2 = new TextBlock
{
ForegroundColor = color,
HorizontalAlignment = HorizontalAlignment.Center,
Text = "SL(pips)"
};
var textBox2 = new TextBox
{
ForegroundColor = color,
HorizontalAlignment = HorizontalAlignment.Center,
Width = 50,
BorderThickness = 2,
BorderColor = color,
TextAlignment = TextAlignment.Center
};
var textBlock3 = new TextBlock
{
ForegroundColor = color,
HorizontalAlignment = HorizontalAlignment.Center,
Text = "Volume"
};
textBox3.ForegroundColor = color;
textBox3.HorizontalAlignment = HorizontalAlignment.Center;
textBox3.Width = 50;
textBox3.BorderThickness = 2;
textBox3.BorderColor = color;
textBox3.IsEnabled = false;
textBlock3.TextAlignment = TextAlignment.Center;
textBox1.TextChanged += TextBox1_TextChanged;
textBox2.TextChanged += TextBox2_TextChanged;
StackPanel1.AddChild(textBlock1);
StackPanel1.AddChild(textBox1);
StackPanel2.AddChild(textBlock2);
StackPanel2.AddChild(textBox2);
StackPanel3.AddChild(textBlock3);
StackPanel3.AddChild(textBox3);
mainStackPanel.AddChild(StackPanel1);
mainStackPanel.AddChild(StackPanel2);
mainStackPanel.AddChild(StackPanel3);
Chart.AddControl(mainStackPanel);
}
private void TextBox1_TextChanged(TextChangedEventArgs obj)
{
risk = Convert.ToDouble(obj.TextBox.Text);
}
private void TextBox2_TextChanged(TextChangedEventArgs obj)
{
pip = Convert.ToDouble(obj.TextBox.Text);
}
public override void Calculate(int index)
{
textBox3.Text = CalcVolume(risk, pip);
}
public string CalcVolume(double r, double p)
{
return Math.Round(Symbol.VolumeInUnitsToQuantity(Account.Balance * r / 100 / (pip * Symbol.PipValue)), 2).ToString();
}
}
}
@midline doesn't move: 19 Jun 2022, 11:21
in this below code i have a box with mid line.
when i move vertical line box move but midline disapper.
i know that problem is in Chart_ObjectsUpdated part. but i coudln't fix that.
using cAlgo.API;
using System.Linq;
using System;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class AWBoxOffline2 : Indicator
{
private ChartVerticalLine _vl;
private ChartRectangle _box;
private ChartTrendLine _midline;
[Parameter("Period", DefaultValue = 60, MinValue = 1)]
public int Period { get; set; }
[Parameter("Line Color", DefaultValue = "Red", Group = "Line")]
public string LineColor { get; set; }
[Parameter("LineStyle", DefaultValue = LineStyle.Solid, Group = "Line")]
public LineStyle ls { get; set; }
[Parameter("Thickness", DefaultValue = 2, Group = "Line")]
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.Solid, Group = "Mid Line")]
public LineStyle ls2 { get; set; }
[Parameter("Mid Line Thickness", DefaultValue = 2, Group = "Mid Line")]
public int Thickness2 { get; set; }
protected override void Initialize()
{
_vl = Chart.DrawVerticalLine("scrollLine", Chart.LastVisibleBarIndex, Color.FromName(LineColor), Thickness, ls);
_vl.IsInteractive = true;
var verticalLineBarIndex = Bars.OpenTimes.GetIndexByTime(_vl.Time);
if (Midline)
{
_midline = Chart.DrawTrendLine("trendLine",verticalLineBarIndex , (Bars.LowPrices.Minimum(Period) + Bars.HighPrices.Maximum(Period)) / 2, verticalLineBarIndex-Period, (Bars.LowPrices.Minimum(Period) + Bars.HighPrices.Maximum(Period)) / 2,Color2,Thickness2,ls2);
}
_box = Chart.DrawRectangle("rectangle_sample", verticalLineBarIndex, Bars.LowPrices.Minimum(Period), verticalLineBarIndex - Period, Bars.HighPrices.Maximum(Period), Color.FromArgb(100, Color.Red));
_box.IsFilled = true;
_box.IsInteractive = false;
_box.IsFilled = false;
_box.Thickness = Thickness;
_box.Color = LineColor;
_box.LineStyle = ls;
Chart.ObjectsUpdated += Chart_ObjectsUpdated;
}
private void Chart_ObjectsUpdated(ChartObjectsUpdatedEventArgs obj)
{
if (!obj.ChartObjects.Contains(_vl))
return;
var verticalLineBarIndex = Bars.OpenTimes.GetIndexByTime(_vl.Time);
_box.Time1 = Bars.OpenTimes[verticalLineBarIndex];
_box.Time2 = Bars.OpenTimes[verticalLineBarIndex - Period];
_box.Y1 = GetMinimum(Bars.LowPrices, verticalLineBarIndex, Period);
_box.Y2 = GetMaximum(Bars.HighPrices, verticalLineBarIndex, Period);
_midline.Time1=Bars.OpenTimes[verticalLineBarIndex];
_midline.Time2 = Bars.OpenTimes[verticalLineBarIndex - Period];
_midline.Y1=GetMinimum(Bars.LowPrices, verticalLineBarIndex, Period)+GetMaximum(Bars.HighPrices, verticalLineBarIndex, Period)/2;
_midline.Y2 = GetMinimum(Bars.LowPrices, verticalLineBarIndex, Period)+GetMaximum(Bars.HighPrices, verticalLineBarIndex, Period)/2;
}
private double GetMinimum(DataSeries source, int index, int periods)
{
double min = double.MaxValue;
var lastBarIndex = index - periods;
for (int i = index; i > lastBarIndex; i--)
{
min = Math.Min(min, source[i]);
}
return min;
}
private double GetMaximum(DataSeries source, int index, int periods)
{
double max = double.MinValue;
var lastBarIndex = index - periods;
for (int i = index; i > lastBarIndex; i--)
{
max = Math.Max(max, source[i]);
}
return max;
}
public override void Calculate(int index)
{
}
}
}
@problem with 4.2(aw ichimoku indicator): 30 May 2022, 18:47
amusleh said:
Hi,
Try this:
using System; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; using cAlgo.Indicators; namespace cAlgo { [Indicator(IsOverlay = true, AccessRights = AccessRights.None)] [Cloud("Up Kumo", "Down Kumo", Opacity = 0.2)] public class AwIchimoku : Indicator { [Parameter("Tenkan sen", DefaultValue = 9, MinValue = 1)] public int Ten_Period { get; set; } [Parameter("Kijun sen", DefaultValue = 26, MinValue = 1)] public int K_Period { get; set; } [Parameter("Senkou span B", DefaultValue = 52, MinValue = 1)] public int SB_Period { get; set; } [Output("Tenkan sen", LineStyle = LineStyle.Solid, LineColor = "Red")] public IndicatorDataSeries Ten_Result { get; set; } [Output("Kijun sen", LineStyle = LineStyle.Solid, LineColor = "Blue")] public IndicatorDataSeries K_Result { get; set; } [Output("Chiku span", LineStyle = LineStyle.Solid, LineColor = "Purple")] public IndicatorDataSeries C_Result { get; set; } [Output("Up Kumo", LineStyle = LineStyle.Solid, LineColor = "Green")] public IndicatorDataSeries Up_Result { get; set; } [Output("Down Kumo", LineStyle = LineStyle.Solid, LineColor = "FFFF6666")] public IndicatorDataSeries Down_Result { get; set; } [Output("Span A", LineStyle = LineStyle.Solid, LineColor = "Green")] public IndicatorDataSeries SA_Result { get; set; } [Output("Span B", LineStyle = LineStyle.Solid, LineColor = "FFFF6666")] public IndicatorDataSeries SB_Result { get; set; } private IchimokuKinkoHyo _ICHI; protected override void Initialize() { _ICHI = Indicators.IchimokuKinkoHyo(Ten_Period, K_Period, SB_Period); } public override void Calculate(int index) { Ten_Result[index] = _ICHI.TenkanSen[index]; K_Result[index] = _ICHI.KijunSen[index]; C_Result[index - 26] = _ICHI.ChikouSpan[index]; SA_Result[index + 26] = (_ICHI.TenkanSen[index] + _ICHI.KijunSen[index]) / 2; SB_Result[index + 26] = _ICHI.SenkouSpanB[index]; Up_Result[index + 26] = (_ICHI.TenkanSen[index] + _ICHI.KijunSen[index]) / 2; Down_Result[index + 26] = _ICHI.SenkouSpanB[index]; } } }
it doesn't show chico span
@problem with 4.2(aw ichimoku indicator): 28 May 2022, 14:17
this code work in 4.1 but doesn't work correctly in 4.2. i couldn't resolve that.
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
[Cloud("Up Kumo", "Down Kumo", Opacity = 0.2)]
public class AwIchimoku : Indicator
{
[Parameter("Tenkan sen", DefaultValue = 9, MinValue = 1)]
public int Ten_Period { get; set; }
[Parameter("Kijun sen", DefaultValue = 26, MinValue = 1)]
public int K_Period { get; set; }
[Parameter("Senkou span B", DefaultValue = 52, MinValue = 1)]
public int SB_Period { get; set; }
[Output("Tenkan sen", LineStyle = LineStyle.Solid, LineColor = "Red")]
public IndicatorDataSeries Ten_Result { get; set; }
[Output("Kijun sen", LineStyle = LineStyle.Solid, LineColor = "Blue")]
public IndicatorDataSeries K_Result { get; set; }
[Output("Chiku span", LineStyle = LineStyle.Solid, LineColor = "Purple")]
public IndicatorDataSeries C_Result { get; set; }
[Output("Up Kumo", LineStyle = LineStyle.Solid, LineColor = "Green")]
public IndicatorDataSeries Up_Result { get; set; }
[Output("Down Kumo", LineStyle = LineStyle.Solid, LineColor = "FFFF6666")]
public IndicatorDataSeries Down_Result { get; set; }
[Output("Span A", LineStyle = LineStyle.Solid, LineColor = "Green")]
public IndicatorDataSeries SA_Result { get; set; }
[Output("Span B", LineStyle = LineStyle.Solid, LineColor = "FFFF6666")]
public IndicatorDataSeries SB_Result { get; set; }
private IchimokuKinkoHyo _ICHI;
protected override void Initialize()
{
_ICHI = Indicators.IchimokuKinkoHyo(Ten_Period, K_Period, SB_Period);
}
public override void Calculate(int index)
{
Ten_Result[index] = _ICHI.TenkanSen.Last(0);
K_Result[index] = _ICHI.KijunSen.Last(0);
C_Result[index - 26] = _ICHI.ChikouSpan.Last(0);
SA_Result[index + 26] = (_ICHI.TenkanSen.Last(0) + _ICHI.KijunSen.Last(0)) / 2;
SB_Result[index + 26] = _ICHI.SenkouSpanB.Last(0);
Up_Result[index + 26] = (_ICHI.TenkanSen.Last(0) + _ICHI.KijunSen.Last(0)) / 2;
Down_Result[index + 26] = _ICHI.SenkouSpanB.Last(0);
}
}
}