Multi time frame Ichimoku indicator
Multi time frame Ichimoku indicator
14 Nov 2013, 08:57
I am trying to create an indicator that will show where the price is in respect to the cloud for various timeframes. I am having a problem getting the current values of spanA and spanB, instead I am geting the values of future kumo. Any help would be appreciated.
This is what I have so far...
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
namespace cAlgo.Indicators
{
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC)]
public class mTFCloudRadar : Indicator
{
private MarketSeries seriesM1;
private MarketSeries seriesM5;
private MarketSeries seriesM15;
private MarketSeries seriesM30;
private MarketSeries seriesH1;
private MarketSeries seriesH4;
private MarketSeries seriesH12;
private MarketSeries seriesD1;
private IchimokuKinkoHyo cloudM1;
private IchimokuKinkoHyo cloudM5;
private IchimokuKinkoHyo cloudM15;
private IchimokuKinkoHyo cloudM30;
private IchimokuKinkoHyo cloudH1;
private IchimokuKinkoHyo cloudH4;
private IchimokuKinkoHyo cloudH12;
private IchimokuKinkoHyo cloudD1;
private string resM1;
private string resM5;
private string resM15;
private string resM30;
private string resH1;
private string resH4;
private string resH12;
private string resD1;
MarketDepth MySymbol;
protected override void Initialize()
{
seriesM1 = MarketData.GetSeries(TimeFrame.Minute);
seriesM5 = MarketData.GetSeries(TimeFrame.Minute5);
seriesM15 = MarketData.GetSeries(TimeFrame.Minute15);
seriesM30 = MarketData.GetSeries(TimeFrame.Minute30);
seriesH1 = MarketData.GetSeries(TimeFrame.Hour);
seriesH4 = MarketData.GetSeries(TimeFrame.Hour4);
seriesH12 = MarketData.GetSeries(TimeFrame.Hour12);
seriesD1 = MarketData.GetSeries(TimeFrame.Daily);
cloudM1 = Indicators.IchimokuKinkoHyo(seriesM1,9,26,52);
cloudM5 = Indicators.IchimokuKinkoHyo(seriesM5,9,26,52);
cloudM15 = Indicators.IchimokuKinkoHyo(seriesM15,9,26,52);
cloudM30 = Indicators.IchimokuKinkoHyo(seriesM30,9,26,52);
cloudH1 = Indicators.IchimokuKinkoHyo(seriesH1,9,26,52);
cloudH4 = Indicators.IchimokuKinkoHyo(seriesH4,9,26,52);
cloudH12 = Indicators.IchimokuKinkoHyo(seriesH12,9,26,52);
cloudD1 = Indicators.IchimokuKinkoHyo(seriesD1,9,26,52);
MySymbol = MarketData.GetMarketDepth(Symbol);
MySymbol.Updated += doCalculate;
}
void doCalculate ()
{
string LABm1 = string.Format("{0,-180}","m1");
string LABm5 = string.Format("{0,-120}","m5");
string LABm15 = string.Format("{0,-60}","m15");
string LABm30 = string.Format("{0,0}","m30");
string LABh1 = string.Format("{0,60}","H1");
string LABh4 = string.Format("{0,120}","H4");
string LABh12 = string.Format("{0,180}","H12");
string LABd1 = string.Format("{0,240}","D1");
ChartObjects.DrawText("LABELm1", LABm1, StaticPosition.TopCenter, Colors.White);
ChartObjects.DrawText("LABELm5", LABm5, StaticPosition.TopCenter, Colors.White);
ChartObjects.DrawText("LABELm15", LABm15, StaticPosition.TopCenter, Colors.White);
ChartObjects.DrawText("LABELm30", LABm30, StaticPosition.TopCenter, Colors.White);
ChartObjects.DrawText("LABELh1", LABh1, StaticPosition.TopCenter, Colors.White);
ChartObjects.DrawText("LABELh4", LABh4, StaticPosition.TopCenter, Colors.White);
ChartObjects.DrawText("LABELh12", LABh12, StaticPosition.TopCenter, Colors.White);
ChartObjects.DrawText("LABELd1", LABd1, StaticPosition.TopCenter, Colors.White);
Colors m1Color = Colors.White;
Colors m5Color = Colors.White;
Colors m15Color = Colors.White;
Colors m30Color = Colors.White;
Colors h1Color = Colors.White;
Colors h4Color = Colors.White;
Colors h12Color = Colors.White;
Colors d1Color = Colors.White;
if(seriesM1.Close.LastValue<cloudM1.SenkouSpanA.LastValue && seriesM1.Close.LastValue<cloudM1.SenkouSpanB.LastValue){resM1= string.Format("\n{0,-180}","BEAR"); m1Color = Colors.Red;}
else if(seriesM1.Close.LastValue>cloudM1.SenkouSpanA.LastValue && seriesM1.Close.LastValue>cloudM1.SenkouSpanB.LastValue){resM1 = string.Format("\n{0,-180}","BULL"); m1Color = Colors.DodgerBlue;}
else {resM1 = string.Format("\n{0,-180}","NEUTRAL"); m1Color = Colors.Yellow;}
if(seriesM5.Close.LastValue<cloudM5.SenkouSpanA.LastValue && seriesM5.Close.LastValue<cloudM5.SenkouSpanB.LastValue){resM5 = string.Format("\n{0,-120}","BEAR"); m5Color = Colors.Red;}
else if(seriesM5.Close.LastValue>cloudM5.SenkouSpanA.LastValue && seriesM5.Close.LastValue>cloudM5.SenkouSpanB.LastValue){resM5 = string.Format("\n{0,-120}","BULL"); m5Color = Colors.DodgerBlue;}
else {resM5 = string.Format("\n{0,-120}","NEUTRAL"); m5Color = Colors.Yellow;}
if(seriesM15.Close.LastValue<cloudM15.SenkouSpanA.LastValue && seriesM15.Close.LastValue<cloudM15.SenkouSpanB.LastValue){resM15 = string.Format("\n{0,-60}","BEAR"); m15Color = Colors.Red;}
else if(seriesM15.Close.LastValue>cloudM15.SenkouSpanA.LastValue && seriesM15.Close.LastValue>cloudM15.SenkouSpanB.LastValue){resM15 = string.Format("\n{0,-60}","BULL"); m15Color = Colors.DodgerBlue;}
else {resM15 = string.Format("\n{0,-60}","NEUTRAL"); m15Color = Colors.Yellow;}
if(seriesM30.Close.LastValue<cloudM30.SenkouSpanA.LastValue && seriesM30.Close.LastValue<cloudM30.SenkouSpanB.LastValue){resM30 = string.Format("\n{0,0}","BEAR"); m30Color = Colors.Red;}
else if(seriesM30.Close.LastValue>cloudM30.SenkouSpanA.LastValue && seriesM30.Close.LastValue>cloudM30.SenkouSpanB.LastValue){resM30 = string.Format("\n{0,0}","BULL"); m30Color = Colors.DodgerBlue;}
else {resM30 = string.Format("\n{0,0}","NEUTRAL"); m30Color = Colors.Yellow;}
if(seriesH1.Close.LastValue<cloudH1.SenkouSpanA.LastValue && seriesH1.Close.LastValue<cloudH1.SenkouSpanB.LastValue){resH1 = string.Format("\n{0,60}","BEAR"); h1Color = Colors.Red;}
else if(seriesH1.Close.LastValue>cloudH1.SenkouSpanA.LastValue && seriesH1.Close.LastValue>cloudH1.SenkouSpanB.LastValue){resH1 = string.Format("\n{0,60}","BULL"); h1Color = Colors.DodgerBlue;}
else {resH1 = string.Format("\n{0,60}","NEUTRAL"); h1Color = Colors.Yellow;}
if(seriesH4.Close.LastValue<cloudH4.SenkouSpanA.LastValue && seriesH4.Close.LastValue<cloudH4.SenkouSpanB.LastValue){resH4 = string.Format("\n{0,120}","BEAR"); h4Color = Colors.Red;}
else if(seriesH4.Close.LastValue>cloudH4.SenkouSpanA.LastValue && seriesH4.Close.LastValue>cloudH4.SenkouSpanB.LastValue){resH4 = string.Format("\n{0,120}","BULL"); h4Color = Colors.DodgerBlue;}
else {resH4 = string.Format("\n{0,120}","NEUTRAL"); h4Color = Colors.Yellow;}
if(seriesH12.Close.LastValue<cloudH12.SenkouSpanA.LastValue && seriesH12.Close.LastValue<cloudH12.SenkouSpanB.LastValue){resH12 = string.Format("\n{0,180}","BEAR"); h12Color = Colors.Red;}
else if(seriesH12.Close.LastValue>cloudH12.SenkouSpanA.LastValue && seriesH12.Close.LastValue>cloudH12.SenkouSpanB.LastValue){resH12 = string.Format("\n{0,180}","BULL"); h12Color = Colors.DodgerBlue;}
else {resH12 = string.Format("\n{0,180}","NEUTRAL"); h12Color = Colors.Yellow;}
if(seriesD1.Close.LastValue<cloudD1.SenkouSpanA.LastValue && seriesD1.Close.LastValue<cloudD1.SenkouSpanB.LastValue){resD1 = string.Format("\n{0,240}","BEAR"); d1Color = Colors.Red;}
else if(seriesD1.Close.LastValue>cloudD1.SenkouSpanA.LastValue && seriesD1.Close.LastValue>cloudD1.SenkouSpanB.LastValue){resD1 = string.Format("\n{0,240}","BEAR"); d1Color = Colors.DodgerBlue;}
else {resD1 = string.Format("\n{0,240}","BEAR"); d1Color = Colors.Yellow;}
ChartObjects.DrawText("m1", resM1, StaticPosition.TopCenter, m1Color);
ChartObjects.DrawText("m5", resM5, StaticPosition.TopCenter, m5Color);
ChartObjects.DrawText("m15", resM15, StaticPosition.TopCenter, m15Color);
ChartObjects.DrawText("m30", resM30, StaticPosition.TopCenter, m30Color);
ChartObjects.DrawText("H1", resH1, StaticPosition.TopCenter, h1Color);
ChartObjects.DrawText("H4", resH4, StaticPosition.TopCenter, h4Color);
ChartObjects.DrawText("H12", resH12, StaticPosition.TopCenter, h12Color);
ChartObjects.DrawText("D1", resD1, StaticPosition.TopCenter, d1Color);
}
public override void Calculate (int index){}
}
}
Replies
gedet
20 Nov 2013, 14:57
Thanks for the response I really appreciate the help. You are right about DOM I added the code in the calculate method, however the problem is that the indicator compares the current price with the future spanA and spanB (26 periods in the future) I cannot find a way to compare the current price to the current spanA and spanB values.
@gedet
atrader
21 Nov 2013, 09:59
RE:
gedet said:
Thanks for the response I really appreciate the help. You are right about DOM I added the code in the calculate method, however the problem is that the indicator compares the current price with the future spanA and spanB (26 periods in the future) I cannot find a way to compare the current price to the current spanA and spanB values.
Instead of cloudM1.SenkouSpanA.LastValue you would need cloudM1.SenkouSpanA[ indexM1], where indexM1 = seriesM1.Close.Count - 1 (the last index for the seriesM1 )
Also, see the examples here for translating indexes between different series: /forum/whats-new/1463#3
@atrader
gedet
21 Nov 2013, 14:27
That sorted it out, it works great thanks!
Here is the revised code:
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
namespace cAlgo.Indicators
{
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC)]
public class mTFCloudRadar : Indicator
{
private MarketSeries seriesM1;
private MarketSeries seriesM5;
private MarketSeries seriesM15;
private MarketSeries seriesM30;
private MarketSeries seriesH1;
private MarketSeries seriesH4;
private MarketSeries seriesH12;
private MarketSeries seriesD1;
private IchimokuKinkoHyo cloudM1;
private IchimokuKinkoHyo cloudM5;
private IchimokuKinkoHyo cloudM15;
private IchimokuKinkoHyo cloudM30;
private IchimokuKinkoHyo cloudH1;
private IchimokuKinkoHyo cloudH4;
private IchimokuKinkoHyo cloudH12;
private IchimokuKinkoHyo cloudD1;
public int ind=1;
private string resM1;
private string resM5;
private string resM15;
private string resM30;
private string resH1;
private string resH4;
private string resH12;
private string resD1;
//MarketDepth MySymbol;
protected override void Initialize()
{
seriesM1 = MarketData.GetSeries(TimeFrame.Minute);
seriesM5 = MarketData.GetSeries(TimeFrame.Minute5);
seriesM15 = MarketData.GetSeries(TimeFrame.Minute15);
seriesM30 = MarketData.GetSeries(TimeFrame.Minute30);
seriesH1 = MarketData.GetSeries(TimeFrame.Hour);
seriesH4 = MarketData.GetSeries(TimeFrame.Hour4);
seriesH12 = MarketData.GetSeries(TimeFrame.Hour12);
seriesD1 = MarketData.GetSeries(TimeFrame.Daily);
cloudM1 = Indicators.IchimokuKinkoHyo(seriesM1,9,26,52);
cloudM5 = Indicators.IchimokuKinkoHyo(seriesM5,9,26,52);
cloudM15 = Indicators.IchimokuKinkoHyo(seriesM15,9,26,52);
cloudM30 = Indicators.IchimokuKinkoHyo(seriesM30,9,26,52);
cloudH1 = Indicators.IchimokuKinkoHyo(seriesH1,9,26,52);
cloudH4 = Indicators.IchimokuKinkoHyo(seriesH4,9,26,52);
cloudH12 = Indicators.IchimokuKinkoHyo(seriesH12,9,26,52);
cloudD1 = Indicators.IchimokuKinkoHyo(seriesD1,9,26,52);
//MySymbol = MarketData.GetMarketDepth(Symbol);
//MySymbol.Updated += doCalculate;
}
public override void Calculate (int index)
{
string LABm1 = string.Format("{0,-180}","m1");
string LABm5 = string.Format("{0,-120}","m5");
string LABm15 = string.Format("{0,-60}","m15");
string LABm30 = string.Format("{0,0}","m30");
string LABh1 = string.Format("{0,60}","H1");
string LABh4 = string.Format("{0,120}","H4");
string LABh12 = string.Format("{0,180}","H12");
string LABd1 = string.Format("{0,240}","D1");
ChartObjects.DrawText("LABELm1", LABm1, StaticPosition.TopCenter, Colors.White);
ChartObjects.DrawText("LABELm5", LABm5, StaticPosition.TopCenter, Colors.White);
ChartObjects.DrawText("LABELm15", LABm15, StaticPosition.TopCenter, Colors.White);
ChartObjects.DrawText("LABELm30", LABm30, StaticPosition.TopCenter, Colors.White);
ChartObjects.DrawText("LABELh1", LABh1, StaticPosition.TopCenter, Colors.White);
ChartObjects.DrawText("LABELh4", LABh4, StaticPosition.TopCenter, Colors.White);
ChartObjects.DrawText("LABELh12", LABh12, StaticPosition.TopCenter, Colors.White);
ChartObjects.DrawText("LABELd1", LABd1, StaticPosition.TopCenter, Colors.White);
Colors m1Color = Colors.White;
Colors m5Color = Colors.White;
Colors m15Color = Colors.White;
Colors m30Color = Colors.White;
Colors h1Color = Colors.White;
Colors h4Color = Colors.White;
Colors h12Color = Colors.White;
Colors d1Color = Colors.White;
if(seriesM1.Close.LastValue<cloudM1.SenkouSpanA[seriesM1.Close.Count - ind] && seriesM1.Close.LastValue<cloudM1.SenkouSpanB[seriesM1.Close.Count - ind]){resM1= string.Format("\n{0,-180}","BEAR"); m1Color = Colors.Red;}
else if(seriesM1.Close.LastValue>cloudM1.SenkouSpanA[seriesM1.Close.Count - ind] && seriesM1.Close.LastValue>cloudM1.SenkouSpanB[seriesM1.Close.Count - ind]){resM1 = string.Format("\n{0,-180}","BULL"); m1Color = Colors.DodgerBlue;}
else {resM1 = string.Format("\n{0,-180}","NEUTRAL"); m1Color = Colors.Yellow;}
if(seriesM5.Close.LastValue<cloudM5.SenkouSpanA[seriesM5.Close.Count - ind] && seriesM5.Close.LastValue<cloudM5.SenkouSpanB[seriesM5.Close.Count - ind]){resM5 = string.Format("\n{0,-120}","BEAR"); m5Color = Colors.Red;}
else if(seriesM5.Close.LastValue>cloudM5.SenkouSpanA[seriesM5.Close.Count - ind] && seriesM5.Close.LastValue>cloudM5.SenkouSpanB[seriesM5.Close.Count - ind]){resM5 = string.Format("\n{0,-120}","BULL"); m5Color = Colors.DodgerBlue;}
else {resM5 = string.Format("\n{0,-120}","NEUTRAL"); m5Color = Colors.Yellow;}
if(seriesM15.Close.LastValue<cloudM15.SenkouSpanA[seriesM15.Close.Count - ind] && seriesM15.Close.LastValue<cloudM15.SenkouSpanB[seriesM15.Close.Count - ind]){resM15 = string.Format("\n{0,-60}","BEAR"); m15Color = Colors.Red;}
else if(seriesM15.Close.LastValue>cloudM15.SenkouSpanA[seriesM15.Close.Count - ind] && seriesM15.Close.LastValue>cloudM15.SenkouSpanB[seriesM15.Close.Count - ind]){resM15 = string.Format("\n{0,-60}","BULL"); m15Color = Colors.DodgerBlue;}
else {resM15 = string.Format("\n{0,-60}","NEUTRAL"); m15Color = Colors.Yellow;}
if(seriesM30.Close.LastValue<cloudM30.SenkouSpanA[seriesM30.Close.Count - ind] && seriesM30.Close.LastValue<cloudM30.SenkouSpanB[seriesM30.Close.Count - ind]){resM30 = string.Format("\n{0,0}","BEAR"); m30Color = Colors.Red;}
else if(seriesM30.Close.LastValue>cloudM30.SenkouSpanA[seriesM30.Close.Count - ind] && seriesM30.Close.LastValue>cloudM30.SenkouSpanB[seriesM30.Close.Count - ind]){resM30 = string.Format("\n{0,0}","BULL"); m30Color = Colors.DodgerBlue;}
else {resM30 = string.Format("\n{0,0}","NEUTRAL"); m30Color = Colors.Yellow;}
if(seriesH1.Close.LastValue<cloudH1.SenkouSpanA[seriesH1.Close.Count - ind] && seriesH1.Close.LastValue<cloudH1.SenkouSpanB[seriesH1.Close.Count - ind]){resH1 = string.Format("\n{0,60}","BEAR"); h1Color = Colors.Red;}
else if(seriesH1.Close.LastValue>cloudH1.SenkouSpanA[seriesH1.Close.Count - ind] && seriesH1.Close.LastValue>cloudH1.SenkouSpanB[seriesH1.Close.Count - ind]){resH1 = string.Format("\n{0,60}","BULL"); h1Color = Colors.DodgerBlue;}
else {resH1 = string.Format("\n{0,60}","NEUTRAL"); h1Color = Colors.Yellow;}
if(seriesH4.Close.LastValue<cloudH4.SenkouSpanA[seriesH4.Close.Count - ind] && seriesH4.Close.LastValue<cloudH4.SenkouSpanB[seriesH4.Close.Count - ind]){resH4 = string.Format("\n{0,120}","BEAR"); h4Color = Colors.Red;}
else if(seriesH4.Close.LastValue>cloudH4.SenkouSpanA[seriesH4.Close.Count - ind] && seriesH4.Close.LastValue>cloudH4.SenkouSpanB[seriesH4.Close.Count - ind]){resH4 = string.Format("\n{0,120}","BULL"); h4Color = Colors.DodgerBlue;}
else {resH4 = string.Format("\n{0,120}","NEUTRAL"); h4Color = Colors.Yellow;}
if(seriesH12.Close.LastValue<cloudH12.SenkouSpanA[seriesH12.Close.Count - ind] && seriesH12.Close.LastValue<cloudH12.SenkouSpanB[seriesH12.Close.Count - ind]){resH12 = string.Format("\n{0,180}","BEAR"); h12Color = Colors.Red;}
else if(seriesH12.Close.LastValue>cloudH12.SenkouSpanA[seriesH12.Close.Count - ind] && seriesH12.Close.LastValue>cloudH12.SenkouSpanB[seriesH12.Close.Count - ind]){resH12 = string.Format("\n{0,180}","BULL"); h12Color = Colors.DodgerBlue;}
else {resH12 = string.Format("\n{0,180}","NEUTRAL"); h12Color = Colors.Yellow;}
if(seriesD1.Close.LastValue<cloudD1.SenkouSpanA[seriesD1.Close.Count - ind] && seriesD1.Close.LastValue<cloudD1.SenkouSpanB[seriesD1.Close.Count - ind]){resD1 = string.Format("\n{0,240}","BEAR"); d1Color = Colors.Red;}
else if(seriesD1.Close.LastValue>cloudD1.SenkouSpanA[seriesD1.Close.Count - ind] && seriesD1.Close.LastValue>cloudD1.SenkouSpanB[seriesD1.Close.Count - ind]){resD1 = string.Format("\n{0,240}","BEAR"); d1Color = Colors.DodgerBlue;}
else {resD1 = string.Format("\n{0,240}","BEAR"); d1Color = Colors.Yellow;}
ChartObjects.DrawText("m1", resM1, StaticPosition.TopCenter, m1Color);
ChartObjects.DrawText("m5", resM5, StaticPosition.TopCenter, m5Color);
ChartObjects.DrawText("m15", resM15, StaticPosition.TopCenter, m15Color);
ChartObjects.DrawText("m30", resM30, StaticPosition.TopCenter, m30Color);
ChartObjects.DrawText("H1", resH1, StaticPosition.TopCenter, h1Color);
ChartObjects.DrawText("H4", resH4, StaticPosition.TopCenter, h4Color);
ChartObjects.DrawText("H12", resH12, StaticPosition.TopCenter, h12Color);
ChartObjects.DrawText("D1", resD1, StaticPosition.TopCenter, d1Color);
}
}
}
@gedet
jumpsolid
16 Oct 2016, 19:35
Hello ,
this is an outstanding job,
but is there a way to scan for crosses, devide those crosses in 8 different types ?
that would be more powerfull
@jumpsolid
atrader
20 Nov 2013, 10:44 ( Updated at: 21 Dec 2023, 09:20 )
You don't need DOM for this. Just use Symbol instead of MySymbol. Remove this:
You can add the code from doCalculate in the Calculate method.
I get this result
@atrader