I found this bit of code, and seems useful and straight forward. arrows are drawn based on wether iSeekSignal leads them to be bullish or bearish.
// ArrowBrush color is for testing only, but it is also used to determine iSignalStrength
bArrowDn = (iSeekSignal % 2 != 0); // down signal = odd number
if(iSeekSignal==icSignal_KB_DN || iSeekSignal==icSignal_KB_UP)
ArrowBrush = (iSeekSignal==icSignal_KB_DN) ? Brushes.Red : Brushes.Green;
else
switch(iCloudStatus)
{
case icBelowCloud:
ArrowBrush = bArrowDn ? Brushes.Red : Brushes.DarkGray;
break;
case icInCloud:
ArrowBrush = Brushes.LightGray;
break;
case icAboveCloud:
ArrowBrush = bArrowDn ? Brushes.DarkGray : Brushes.Green;
break;
default:
break;
}
So I want to test for that in my own strategy as well. I've copied over all of the initializing parameters to my strategy, so that I can call the indicator class with the proper required variables.
My thought thus is to test IF:
(IchimokuSignal(Conversion, BBase, SpanB, Lag, Isignal_Strong, Isignal_Neutral, Isignal_Weak, Ilegend).iSeekSignal==icSignal_KB_DN --> test for others things and buy.
However, I get an exception that "iSeekSignal" is not identified anywhere in IchimokuSignal; and that's true, but I thought that was odd, that the indicator worked in first place, and then I couldn't find where it EVER got its value from the class... Here's the variables defined in "IchimokuSignal", can't share the entire code.
What should I call to test if it's bullish/bearish, as in buy or sell entry, anyone see what I'm missing? Greatly appreciated, still a novice in C#
#region Using declarations
#endregion
//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
public class IchimokuSignal : Indicator
{
// for Ichimoku Signals by kkc2015, see document from IchimokuTrader.com
private const int icTrendSpan = 4; // 4 previous trading days, used for avoiding whipsaw signals
private const int icNoSignal = 0;
private const int icBelowCloud = 1; // signal occurred below the cloud
private const int icInCloud = 2;
private const int icAboveCloud = 3;
private const int icSignal_Base = 11; // use for adjusting icSignal_ to start from 0
private const int icSignal_TK = icSignal_Base+0; // TK = signal for Tenkan / Kijun sen crossed up
private const int icSignal_PK = icSignal_Base+1; // do not change number sequence from _TK to _CP
private const int icSignal_KB = icSignal_Base+2;
private const int icSignal_SS = icSignal_Base+3;
private const int icSignal_CP = icSignal_Base+4; // do not change number sequence from _TK to _CP
private const int icSignal_LS = icSignal_Base+5; // trade record [Long/Short]
private const int icSignal_DU = icSignal_Base+6; // Alert [Down / Up trend]
private const int icSignalType = 5; // exclude icSignal_LS
private const int icReadTradeData = -2; // flag to show that ReadTradeData is completed, do not repeat
private const int icMACD_data = -3; // flag to show that MACD data is completed, do not repeat
private const int icMACD_Peak = 1; // check for MACD peaks
private const int icMACD_Valley = 2; // check for MACD valleys
private const bool bMACD_Completed = true; // used by MACD function
private static readonly int[] icSignals = {icSignal_TK,icSignal_PK,icSignal_KB,icSignal_SS,i cSignal_CP};
private static readonly string[] scSignals = {"TK", "PK", "KB", "SS", "CP", "LS", "DU"};
private const int icSignal_start = 100; // use for adjusting TK_DN to start from 1
private const int icSignal_TK_DN = 101; // _DN = odd number = signal for Tenkan / Kijun sen crossed down
private const int icSignal_TK_UP = 102; // _UP = even number = signal for Tenkan / Kijun sen crossed up
private const int icSignal_PK_DN = 103;
private const int icSignal_PK_UP = 104;
private const int icSignal_KB_DN = 105;
private const int icSignal_KB_UP = 106;
private const int icSignal_SS_DN = 107;
private const int icSignal_SS_UP = 108;
private const int icSignal_CP_DN = 109;
private const int icSignal_CP_UP = 110;
private const int icSignal_Weak = 1;
private const int icSignal_Neutral = 2;
private const int icSignal_Strong = 3;
private const int icSignal_Trade = 4;
// 5 Ichimoku signal types
private int iSignal = icNoSignal;
public string sSignalCode = " ";
private bool bArrowDn = false;
private int iSignalStrength = icSignal_Neutral;
private double dChart_Ymin = 90.0; // Y value (=Price) at the bottom of chart
private double dChart_Ymax = 134.0; // Y value (=Price) at the top of chart
private double dChart_Y = 0.0; // Y location for showing the arrow
private double dChart_Yspan = 100.0;
private static int iNbrSameBar = 0;
private string sLegend = "SignalColor: LightGray(weak), NoColor(Neutral), Green/Red(strong)\n" +
"Cross:\tTK - Tenkan / Kijun, PK - Price / Kijun, KB - Price / Kumo,\n\tSS - Senkou SpanA / SpanB, CP - Chikou / Price\n";
NinjaTrader.Gui.Tools.SimpleFont LegendFont = new NinjaTrader.Gui.Tools.SimpleFont("Courier New", 12);
private Brush ArrowBrush = Brushes.DarkGray; // use for debugging, do not remove
// for SharpDX drawing of Ichimoku cloud and Indicator ColorBar
private Brush upAreaBrush = Brushes.LightGreen;
private Brush dnAreaBrush = Brushes.Pink;
private Brush upLineBrush = Brushes.DarkGreen;
private Brush dnLineBrush = Brushes.Red;
private Brush textBrush = Brushes.Black;
int iareaOpacity = 55; // this provides reasonable cloud density, can be changed by user input
const float fontHeight = 12f;
int iX_barWidth = 10; // space for each bar, initialize at OnRender()
private SharpDX.Direct2D1.Brush upAreaBrushDx, dnAreaBrushDx, upLineBrushDx, dnLineBrushDx, textBrushDx;
private static int iSignalIdx = 0;
private bool bRendering = false;
private static bool bGetSignal = false;
private const int icSignalMax = 2000;
private const int icSignalSort = -999; // to indicate that stSignal_all[] requires sorting
public struct stSignal
{
public int iBar;
public int iSignal;
public bool bTrendDown;
public int iStrength;
public int iNbrSignal;
};
// [0].iBar = total number of signals. [0].iNbrSignal = icReadTradeData, [0].iStrength = icMACD_data
private stSignal[] stSignal_all = new stSignal[icSignalMax+1];
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Display Ichimoku cloud / indicators.";
Name = "IchimokuSignal_B0";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
Conversion = 9;
BBase = 26;
SpanB = 52;
Lag = 26;
Isignal_Strong = true;
Isignal_Neutral = false;
Isignal_Weak = false;
Ilegend = true;
upAreaBrush = Brushes.LightGreen;
dnAreaBrush = Brushes.Pink;
upLineBrush = Brushes.DarkGreen;
dnLineBrush = Brushes.Red;
iareaOpacity = 55;
AddPlot(Brushes.Purple, "ConversionLine"); // Plots[0]
AddPlot(Brushes.Teal, "BaseLine"); // Plots[1]
AddPlot(Brushes.Transparent, "SpanALine"); // Plots[2]
AddPlot(Brushes.Transparent, "SpanBLine"); // Plots[3]
AddPlot(Brushes.Transparent, "LagLine"); // Plots[5]
}
else if (State == State.Configure)
{
//AddDataSeries(Instrument.FullName, Data.BarsPeriodType.Day, 1, Data.MarketDataType.Last);
ZOrder = -1; // 2016.05.24, per ReusableBrushExample
}
else if (State == State.Historical)
{
// 2016.05.24 from Ninjascript ReuseDxBrushesExample.cs
if (upAreaBrush.IsFrozen)
upAreaBrush = upAreaBrush.Clone(); // this will ensure that previous drawing using this brush is not affected
upAreaBrush.Opacity = iareaOpacity / 100d; // .Opacity[0..1]
upAreaBrush.Freeze(); // freeze brush so that it can be changed later by other functions
upAreaBrushDx = upAreaBrush.ToDxBrush(RenderTarget);
if (dnAreaBrush.IsFrozen)
dnAreaBrush = dnAreaBrush.Clone();
dnAreaBrush.Opacity = iareaOpacity / 100d;
dnAreaBrush.Freeze();
dnAreaBrushDx = dnAreaBrush.ToDxBrush(RenderTarget);
// the following brushes are not to be changed
upLineBrushDx = upLineBrush.ToDxBrush(RenderTarget);
dnLineBrushDx = dnLineBrush.ToDxBrush(RenderTarget);
textBrushDx = textBrush.ToDxBrush(RenderTarget);
}
}
Comment