Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

GetPoint & MoveAnchor

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    GetPoint & MoveAnchor

    Trying to code an indicator that plots where previously-drawn rays intersect with the current moment so I can attach orders to them.

    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:

    PHP Code:
    //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++;
                    }             
                } 
            }
        }
    } 
    

    #2
    Hello pesudoalias,

    Currently you are using chartControl with a lower case 'c' at the beginning.

    ChartControl with a capital 'C' is the object provided by NinjaTrader to the scope of the class. The lower case 'c' is provided by the OnRender() override.
    http://ninjatrader.com/support/helpG...artcontrol.htm

    ChartPanel (also with a capital 'c') is the panel object the indicator is added to for the scope of the class.
    http://ninjatrader.com/support/helpG...chartpanel.htm

    chartScale would come from OnRender.
    http://ninjatrader.com/support/helpG...chartscale.htm
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by argusthome, Yesterday, 10:06 AM
    0 responses
    17 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    16 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    14 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    9 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    36 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X