TenkanSen and KijunSen cross
TenkanSen and KijunSen cross
03 Sep 2017, 12:19
hi
i want when TenkanSen and KijunSen cross at chart. alarm or show point in my chart.
can you help me?
tanks
my code is:
using System; using cAlgo.API; using cAlgo.API.Indicators; /* Version 1.0 Developed by hamidrtafx Email : hamidrtafx@gmail.com */ namespace cAlgo.Indicators { [Indicator(IsOverlay = true, AccessRights = AccessRights.None)] public class ichihamid : Indicator { [Parameter(DefaultValue = 9)] public int periodFast { get; set; } [Parameter(DefaultValue = 26)] public int periodMedium { get; set; } [Parameter(DefaultValue = 52)] public int periodSlow { get; set; } [Parameter(DefaultValue = 103)] public int periodbig { get; set; } [Parameter(DefaultValue = 26)] public int DisplacementChikou { get; set; } [Parameter(DefaultValue = 26)] public int DisplacementCloud { get; set; } [Parameter(DefaultValue = 26)] public int Displacementkijunsen { get; set; } [Parameter("Alarm", DefaultValue = true)] public bool Alarm { get; set; } [Output("TenkanSen", Color = Colors.Red)] public IndicatorDataSeries TenkanSen { get; set; } [Output("Kijunsen", Color = Colors.Blue)] public IndicatorDataSeries KijunSen { get; set; } [Output("ChikouSpan", Color = Colors.DarkViolet)] public IndicatorDataSeries ChikouSpan { get; set; } [Output("qualityline", Color = Colors.White)] public IndicatorDataSeries qualityline { get; set; } [Output("qualityline103", Color = Colors.Brown)] public IndicatorDataSeries qualityline103 { get; set; } [Output("SenkouSpanB", Color = Colors.Red, LineStyle = LineStyle.Lines)] public IndicatorDataSeries SenkouSpanB { get; set; } [Output("SenkouSpanA", Color = Colors.Green, LineStyle = LineStyle.Lines)] public IndicatorDataSeries SenkouSpanA { get; set; } [Output("Up Point", Color = Colors.Orange, PlotType = PlotType.Points, Thickness = 5)] public IndicatorDataSeries UpPoint { get; set; } double maxfast, minfast, maxmedium, minmedium, maxslow, minslow, maxbig, minbig, max26, max9; public override void Calculate(int index) { if ((index < periodFast) || (index < periodSlow)) { return; } maxfast = MarketSeries.High[index]; minfast = MarketSeries.Low[index]; maxmedium = MarketSeries.High[index]; minmedium = MarketSeries.Low[index]; maxbig = MarketSeries.High[index]; minbig = MarketSeries.Low[index]; maxslow = MarketSeries.High[index]; minslow = MarketSeries.Low[index]; max26 = MarketSeries.High.Last(26); max9 = MarketSeries.Low.Last(9); for (int i = 0; i < periodFast; i++) { if (maxfast < MarketSeries.High[index - i]) { maxfast = MarketSeries.High[index - i]; } if (minfast > MarketSeries.Low[index - i]) { minfast = MarketSeries.Low[index - i]; } } for (int i = 0; i < periodMedium; i++) { if (maxmedium < MarketSeries.High[index - i]) { maxmedium = MarketSeries.High[index - i]; } if (minmedium > MarketSeries.Low[index - i]) { minmedium = MarketSeries.Low[index - i]; } } for (int i = 0; i < periodbig; i++) { if (maxbig < MarketSeries.High[index - i]) { maxbig = MarketSeries.High[index - i]; } if (minbig > MarketSeries.Low[index - i]) { minbig = MarketSeries.Low[index - i]; } } for (int i = 0; i < periodSlow; i++) { if (maxslow < MarketSeries.High[index - i]) { maxslow = MarketSeries.High[index - i]; } if (minslow > MarketSeries.Low[index - i]) { minslow = MarketSeries.Low[index - i]; } } TenkanSen[index] = (maxfast + minfast) / 2; KijunSen[index] = (maxmedium + minmedium) / 2; ChikouSpan[index - DisplacementChikou] = MarketSeries.Close[index]; SenkouSpanA[index + DisplacementCloud] = (TenkanSen[index] + KijunSen[index]) / 2; SenkouSpanB[index + DisplacementCloud] = (maxslow + minslow) / 2; qualityline[index + Displacementkijunsen] = (maxmedium + minmedium) / 2; qualityline103[index + Displacementkijunsen] = (maxbig + minbig) / 2; } } }
Replies
hamidreza.taali@gmail.com
04 Sep 2017, 12:27
RE:
Spotware said:
Dear Trader,
Thanks for posting in our forum. You might find the following functions useful.
HasCrossedAbove and HasCrossedBelow can be used for checking if two dataseries have crossed each other in the respective direction. ChartObjects class contains functions to draw different objects on your charts. SendEmail function can be used to send emails and notifications when some events occur.
Let us know if the above information is helpful for you.
Best Regards,
cTrader Team
thanks.
do you have example indicator for cross?
im used.
@hamidreza.taali@gmail.com
Spotware
04 Sep 2017, 12:36
Dear Trader,
You can find examples on how to use the functions in the links above. HasCrossedAbove and HasCrossedBelow functions can be used for all indicators. See also below a small example checking if the simple moving average indicator has crossed above the exponential moving average indicator
var sma = Indicators.SimpleMovingAverage(MarketSeries.Close, 5); var ema = Indicators.ExponentialMovingAverage(MarketSeries.Close, 5); var crossedAbove = sma.Result.HasCrossedAbove(ema.Result, 5);
Let us know if you need any further explanation.
Best Regards,
cTrader Team
@Spotware
hamidreza.taali@gmail.com
05 Sep 2017, 23:55
RE:
Spotware said:
Dear Trader,
You can find examples on how to use the functions in the links above. HasCrossedAbove and HasCrossedBelow functions can be used for all indicators. See also below a small example checking if the simple moving average indicator has crossed above the exponential moving average indicator
var sma = Indicators.SimpleMovingAverage(MarketSeries.Close, 5); var ema = Indicators.ExponentialMovingAverage(MarketSeries.Close, 5); var crossedAbove = sma.Result.HasCrossedAbove(ema.Result, 5);Let us know if you need any further explanation.
Best Regards,cTrader Team
thank for answer.
but i cant edit my code for cross tekensen&kijunsen .
can you edit my code for cross ?please..
thanks
@hamidreza.taali@gmail.com
hamidreza.taali@gmail.com
06 Sep 2017, 01:28
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo.Indicators
{
[Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
public class IchimokuKinkoHyo : Indicator
{
[Parameter(DefaultValue = false)]
public bool ShowAlarm { get; set; }
[Parameter(DefaultValue = 9)]
public int periodFast { get; set; }
[Parameter(DefaultValue = 26)]
public int periodMedium { get; set; }
[Parameter(DefaultValue = 52)]
public int periodSlow { get; set; }
[Parameter(DefaultValue = 103)]
public int periodbig { get; set; }
[Parameter(DefaultValue = 26)]
public int DisplacementChikou { get; set; }
[Parameter(DefaultValue = 26)]
public int DisplacementCloud { get; set; }
[Parameter(DefaultValue = 26)]
public int Displacementkijunsen { get; set; }
[Parameter("star", DefaultValue = "▲")]
public string star_s { get; set; }
[Output("TenkanSen", Color = Colors.Red)]
public IndicatorDataSeries TenkanSen { get; set; }
[Output("Kijunsen", Color = Colors.Blue)]
public IndicatorDataSeries KijunSen { get; set; }
[Output("ChikouSpan", Color = Colors.DarkViolet)]
public IndicatorDataSeries ChikouSpan { get; set; }
[Output("qualityline", Color = Colors.White)]
public IndicatorDataSeries qualityline { get; set; }
[Output("qualityline103", Color = Colors.Brown)]
public IndicatorDataSeries qualityline103 { get; set; }
[Output("SenkouSpanB", Color = Colors.Red, LineStyle = LineStyle.Lines)]
public IndicatorDataSeries SenkouSpanB { get; set; }
[Output("SenkouSpanA", Color = Colors.Green, LineStyle = LineStyle.Lines)]
public IndicatorDataSeries SenkouSpanA { get; set; }
[Output("Down Point", Color = Colors.Orange, PlotType = PlotType.Points, Thickness = 5)]
public IndicatorDataSeries DownPoint { get; set; }
double maxfast, minfast, maxmedium, minmedium, maxslow, minslow, maxbig, minbig;
public override void Calculate(int index)
{
if (IsLastBar)
DisplaySpreadOnChart();
if ((index < periodFast) || (index < periodSlow))
{
return;
}
maxfast = MarketSeries.High[index];
minfast = MarketSeries.Low[index];
maxmedium = MarketSeries.High[index];
minmedium = MarketSeries.Low[index];
maxbig = MarketSeries.High[index];
minbig = MarketSeries.Low[index];
maxslow = MarketSeries.High[index];
minslow = MarketSeries.Low[index];
for (int i = 0; i < periodFast; i++)
{
if (maxfast < MarketSeries.High[index - i])
{
maxfast = MarketSeries.High[index - i];
}
if (minfast > MarketSeries.Low[index - i])
{
minfast = MarketSeries.Low[index - i];
}
}
for (int i = 0; i < periodMedium; i++)
{
if (maxmedium < MarketSeries.High[index - i])
{
maxmedium = MarketSeries.High[index - i];
}
if (minmedium > MarketSeries.Low[index - i])
{
minmedium = MarketSeries.Low[index - i];
}
}
for (int i = 0; i < periodbig; i++)
{
if (maxbig < MarketSeries.High[index - i])
{
maxbig = MarketSeries.High[index - i];
}
if (minbig > MarketSeries.Low[index - i])
{
minbig = MarketSeries.Low[index - i];
}
}
for (int i = 0; i < periodSlow; i++)
{
if (maxslow < MarketSeries.High[index - i])
{
maxslow = MarketSeries.High[index - i];
}
if (minslow > MarketSeries.Low[index - i])
{
minslow = MarketSeries.Low[index - i];
}
}
TenkanSen[index] = (maxfast + minfast) / 2;
KijunSen[index] = (maxmedium + minmedium) / 2;
ChikouSpan[index - DisplacementChikou] = MarketSeries.Close[index];
SenkouSpanA[index + DisplacementCloud] = (TenkanSen[index] + KijunSen[index]) / 2;
SenkouSpanB[index + DisplacementCloud] = (maxslow + minslow) / 2;
qualityline[index + Displacementkijunsen] = (maxmedium + minmedium) / 2;
qualityline103[index + Displacementkijunsen] = (maxbig + minbig) / 2;
var dt1 = DateTime.Now.AddHours(-40);
/* if(TenkanSen[index] == KijunSen[index] && ShowAlarm)
{
Notifications.PlaySound(alarmFile)
}
*/
if (TenkanSen[index] == KijunSen[index])
{
ChartObjects.DrawVerticalLine("vLine", dt1, Colors.Red, 5, LineStyle.Solid);
}
}
private void DisplaySpreadOnChart()
{
var spread = Math.Round(Symbol.Spread / Symbol.PipSize, 2);
string text = string.Format("{0}", spread);
ChartObjects.DrawText("Label", "Spread:", StaticPosition.TopLeft, Colors.Yellow);
ChartObjects.DrawText("spread", "\t" + text, StaticPosition.TopLeft, Colors.White);
}
}
}
@hamidreza.taali@gmail.com
hamidreza.taali@gmail.com
06 Sep 2017, 01:30
MY EDIT CODE TOP AND ADD CODE IS:
if (TenkanSen[index] == KijunSen[index])
{
ChartObjects.DrawVerticalLine("vLine", dt1, Colors.Red, 5, LineStyle.Solid);
}
BUT NOT SHOW DrawVerticalLine MY CHART?why?
@hamidreza.taali@gmail.com
hamidreza.taali@gmail.com
07 Sep 2017, 20:49
RE:
Spotware said:
Dear Trader,
You can find examples on how to use the functions in the links above. HasCrossedAbove and HasCrossedBelow functions can be used for all indicators. See also below a small example checking if the simple moving average indicator has crossed above the exponential moving average indicator
var sma = Indicators.SimpleMovingAverage(MarketSeries.Close, 5); var ema = Indicators.ExponentialMovingAverage(MarketSeries.Close, 5); var crossedAbove = sma.Result.HasCrossedAbove(ema.Result, 5);Let us know if you need any further explanation.
Best Regards,cTrader Team
var kijunsen = Indicators.IchimokuKinkoHyo.kijunsen(MarketSeries.close, 26);
var TenkanSen = Indicators.IchimokuKinkoHyo.TenkanSen(MarketSeries.close, 9);
var CrossedAbove = KijunSen.HasCrossedAbove(TenkanSen.result, 9);
my code is but eror for build.
help me.please.
@hamidreza.taali@gmail.com
hamidreza.taali@gmail.com
08 Sep 2017, 13:51
RE:
Spotware said:
Dear Trader,
Can you please provide the full cBot or Indicator that does not build so that we can advise what the problem is?
Best Regards,
cTrader Team
yes . i can.
but my problem for cross kijen an tenkan in my code...
@hamidreza.taali@gmail.com
hamidreza.taali@gmail.com
09 Sep 2017, 21:23
thankyou.
im do it.
i need help for me chartobjext.
my code is:
ChartObjects.DrawVerticalLine("cross.T&k", index, Colors.Red, 2, LineStyle.Solid);
i need index & time Simultaneous for my chart.
for example:
index for 3 days ago?
what is code for index and time?
@hamidreza.taali@gmail.com
hamidreza.taali@gmail.com
11 Sep 2017, 21:42
RE:
Spotware said:
Dear Trader,
See an example below on how to draw a vertical line on a specific date e.g. 3 days ago
ChartObjects.DrawVerticalLine("cross.T&k", Server.Time.AddDays(-3), Colors.Red, 2, LineStyle.Solid);Best Regards,
cTrader Team
thanks.
but i want all verticalline for 3days ago.
your cod just show one verticalline.
my code:
if (KijunSen[index] == TenkanSen[index]) { ChartObjects.DrawVerticalLine("cross.T&k", index, Colors.Red, 2, LineStyle.Solid);
@hamidreza.taali@gmail.com
Spotware
12 Sep 2017, 14:34
Dear Trader,
If we understood well what you are trying to do, then the following code sample should be helpful for you
if (TenkanSen[index] == KijunSen[index]) { ChartObjects.DrawVerticalLine(index.ToString(), MarketSeries.OpenTime[index].AddDays(-3), Colors.Red, 5, LineStyle.Solid); }
Best Regards,
cTrader Team
@Spotware
hamidreza.taali@gmail.com
12 Sep 2017, 19:40
RE:
Spotware said:
Dear Trader,
If we understood well what you are trying to do, then the following code sample should be helpful for you
if (TenkanSen[index] == KijunSen[index]) { ChartObjects.DrawVerticalLine(index.ToString(), MarketSeries.OpenTime[index].AddDays(-3), Colors.Red, 5, LineStyle.Solid); }Best Regards,
cTrader Team
thankyou but i can't get my result.
i want to draw vertical line for example 3 days ago and draw it for all.
@hamidreza.taali@gmail.com
hamidreza.taali@gmail.com
12 Sep 2017, 19:47
( Updated at: 21 Dec 2023, 09:20 )
@hamidreza.taali@gmail.com
hamidreza.taali@gmail.com
12 Sep 2017, 19:49
i want show verticalline at arrows in chart.
@hamidreza.taali@gmail.com
Spotware
13 Sep 2017, 09:07
Dear Trader,
If want your vertical lines to show whenever the red line crosses the blue line, you could try the following code instead
if (TenkanSen.HasCrossedAbove(KijunSen, 0) || TenkanSen.HasCrossedBelow(KijunSen, 0)) { ChartObjects.DrawVerticalLine(index.ToString(), MarketSeries.OpenTime[index], Colors.Red, 1, LineStyle.Solid); }
Best Regards,
cTrader Team
@Spotware
hamidreza.taali@gmail.com
14 Sep 2017, 13:39
RE:
Spotware said:
Dear Trader,
If want your vertical lines to show whenever the red line crosses the blue line, you could try the following code instead
if (TenkanSen.HasCrossedAbove(KijunSen, 0) || TenkanSen.HasCrossedBelow(KijunSen, 0)) { ChartObjects.DrawVerticalLine(index.ToString(), MarketSeries.OpenTime[index], Colors.Red, 1, LineStyle.Solid); }Best Regards,
cTrader Team
thanks.
but i want just when tankensen=kijansen .
i have not cross.
@hamidreza.taali@gmail.com
nguyendan81985
11 Apr 2020, 04:18
RE:
Spotware said:
Dear Trader,
If want your vertical lines to show whenever the red line crosses the blue line, you could try the following code instead
if (TenkanSen.HasCrossedAbove(KijunSen, 0) || TenkanSen.HasCrossedBelow(KijunSen, 0)) { ChartObjects.DrawVerticalLine(index.ToString(), MarketSeries.OpenTime[index], Colors.Red, 1, LineStyle.Solid); }Best Regards,
cTrader Team
hi. can you help me to make a Text (Excample: "Cross") at position when Tenkan cross Kijun?
@nguyendan81985
PanagiotisCharalampous
13 Apr 2020, 08:38
Hi nguyendan81985,
You can use DrawText() method to draw text on a place on the chart.
Best Regards,
Panagiotis
@PanagiotisCharalampous
Spotware
04 Sep 2017, 09:20
Dear Trader,
Thanks for posting in our forum. You might find the following functions useful.
HasCrossedAbove and HasCrossedBelow can be used for checking if two dataseries have crossed each other in the respective direction. ChartObjects class contains functions to draw different objects on your charts. SendEmail function can be used to send emails and notifications when some events occur.
Let us know if the above information is helpful for you.
Best Regards,
cTrader Team
@Spotware