My logic is as follows. For each ray, grab the StartAnchor and the EndAnchor. Compute the slope of the EndAnchor and then the y-intercept for the current bar and move the EndAnchor to that point. Get the price of the newly-moved EndAnchor.
I think the logic is right, but I'm unable to compile.
Code is below with errors commented:
//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
public class Raycator : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "Raycator";
Calculate = Calculate.OnEachTick;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
IsSuspendedWhileInactive = true;
}
else if (State == State.Configure)
{
int i=0;
foreach (DrawingTools.Ray oRay in DrawObjects)
{
if (oRay.StartAnchor.Time < oRay.EndAnchor.Time)
{
AddPlot(Brushes.Green, oRay.Tag);
i++;
}
}
}
}
protected override void OnBarUpdate()
{
int i=0;
foreach (DrawingTools.Ray oRay in DrawObjects)
{
if (oRay.StartAnchor.Time < oRay.EndAnchor.Time)
{
Point pStart = oRay.StartAnchor.GetPoint(chartControl, chartPanel, ChartScale);
/*^^Errors: 'chartControl' does not exist in current context; 'chartPanel' does not exist in current context; 'NinjaTrader.Gui.Chart.ChartScale' is a 'type' but used like a variable.*/
/* I'm confused. I followed this syntax https://ninjatrader.com/support/helpGuides/nt8/en-us/?getpoint.htm*/
Point pEnd = oRay.EndAnchor.GetPoint(chartControl, chartPanel, ChartScale);
/*^^Errors: 'chartControl' does not exist in current context; 'chartPanel' does not exist in current context; 'NinjaTrader.Gui.Chart.ChartScale' is a 'type' but used like a variable.*/
/* I'm confused. I followed this syntax https://ninjatrader.com/support/helpGuides/nt8/en-us/?getpoint.htm*/
int intSlope = (pEnd.Y - pStart.Y)/(pEnd.X - pStart.X);
/*^^Error: Cannot implicitly convert type 'double' to 'int'*/
/* I'm confused all variables computed are ints, as should product be. */
int intB = pStart.Y - (intSlope * pStart.X);
/*^^Error: Cannot implicitly convert type 'double' to 'int'*/
/* I'm confused all variables computed are ints, as should product be. */
int intNowX = chartControl.GetXByBarIdx(BarsArray[0], CurrentBar);
*^^Errors: 'chartControl' does not exist in current context;*/
/* I'm confused. I followed this syntaxhttp://ninjatrader.com/support/forum/showthread.php?t=23979*/
int intNowY = (intSlope * intNowX) + intB;
Point pNow = new Point(intNowX, intNowY);
oRay.EndAnchor.MoveAnchor(pEnd, pNow, chartControl, chartScale);
/*^^Errors: 'chartControl' does not exist in current context; 'chartScale' does not exist in current context*/
/*I'm confused. I used this syntax: https://ninjatrader.com/support/helpGuides/nt8/en-us/?moveanchor.htm*/
Values[i][0] = oRay.EndAnchor.Price;
i++;
}
}
}
}
}
Comment