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.GreenoRay.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(chartControlchartPanelChartScale);
    /*^^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(chartControlchartPanelChartScale);
    /*^^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.pStart.Y)/(pEnd.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.- (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(intNowXintNowY);
                        
    oRay.EndAnchor.MoveAnchor(pEndpNowchartControlchartScale);
    /*^^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 CortexZenUSA, Today, 12:53 AM
    0 responses
    1 view
    0 likes
    Last Post CortexZenUSA  
    Started by CortexZenUSA, Today, 12:46 AM
    0 responses
    1 view
    0 likes
    Last Post CortexZenUSA  
    Started by usazencortex, Today, 12:43 AM
    0 responses
    5 views
    0 likes
    Last Post usazencortex  
    Started by sidlercom80, 10-28-2023, 08:49 AM
    168 responses
    2,266 views
    0 likes
    Last Post sidlercom80  
    Started by Barry Milan, Yesterday, 10:35 PM
    3 responses
    13 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Working...
    X