Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Continue Drawing Line Until Indicator Crosses Above

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

    #31
    Originally posted by 2fr33d0m View Post
    I understand. Now I see a ray of hope.
    I'll check back from time to time.
    Thanks.
    It would certainly be easier if I just posted a complete indicator. However, due to the returns (insults or lack of requested feedback), that I have received from at least 3 ingrates on this forum, I decided and published, on this very forum, my decision that I would never provide any complete indicator to anybody ever again for free. That means that while, I may post the entire code for an indicator, that code will be posted as text, not as a complete importable indicator, ready for use. While that may violate the spirit of my decision, it certainly holds to the text of it.

    What that means is that I will provide the code that you want for the Long side; the Short side will follow the same ideas. You will have to copy and paste the code into the correct places in a new indicator that you write (or modify your current one, as required).

    Code:
    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Gui.Chart;
    using System.Collections; //must be added
    #endregion
    Code:
            #region Variables
            private int        RayCount = 0;
            private ArrayList    RaysToBeDeleted = new ArrayList();
            private ArrayList    RaysToBeDeletedTags = new ArrayList();
            #endregion
    Code:
            protected override void Initialize()
            {
                Overlay                = true;
                DrawOnPricePanel    = false;
            }
    Code:
            protected override void OnBarUpdate()
            {
                if (CurrentBar < 2) return;
                
                bool LongSetup = false;
                LongSetup = High[0] <= Low[2] && Low[1] < Low[2];
                if (LongSetup) 
                {
                    RayCount++; //increase count, to use in creating unique ID
                    DrawRay("ray"+RayCount.ToString(), false, 2, Low[2], 0, Low[2], Color.Lime, DashStyle.Solid, 2);
                }
                
                //find rays to be handled
                foreach (IDrawObject draw in DrawObjects)
                {
                    if (draw.UserDrawn) continue;
                    if (draw is IRay && draw.Tag.StartsWith("ray")) //most likely one that the script drew
                    {
                        IRay tempRay = (IRay)draw;
                        if (High[0] > tempRay.Anchor1Y) //ray to be converted by overwriting and deletion
                        {
                            this.RaysToBeDeleted.Add(tempRay); //add ray to list of rays to be deleted
                            this.RaysToBeDeletedTags.Add(tempRay.Tag); //add tag to list of rays to be deleted
                        }
                    }
                
                }
                
                //process rays - draw line where there was a ray. Stop one bar ahead of CurrentBar.
                foreach (IRay tempRay in this.RaysToBeDeleted)
                {
                    string rayNumber = tempRay.Tag.Substring(3); //extract ray number
                    int startBarsAgo = tempRay.Anchor1BarsAgo;
                    int endBarsAgo = 1;
                    double lineLevel = tempRay.Anchor1Y;
                    DrawLine("line"+rayNumber, false, startBarsAgo, lineLevel, endBarsAgo, lineLevel, Color. Cyan, DashStyle.Solid, 2);
                }
                
                
                //delete rays
                foreach (string str in this.RaysToBeDeletedTags)
                {
                    RemoveDrawObject(str);
                }
                
                this.RaysToBeDeleted.Clear(); //reset the ArrayList
                this.RaysToBeDeletedTags.Clear(); //reset the ArrayList
                
            }
        }
    Last edited by koganam; 12-14-2013, 03:55 PM.

    Comment


      #32
      Originally posted by koganam View Post
      It would certainly be easier if I just posted a complete indicator. However, due to the returns (insults or lack of requested feedback), that I have received from at least 3 ingrates on this forum, I decided and published, on this very forum, my decision that I would never provide any complete indicator to anybody ever again for free. That means that while, I may post the entire code for an indicator, that code will be posted as text, not as a complete importable indicator, ready for use. While that may violate the spirit of my decision, it certainly holds to the text of it.

      What that means is that I will provide the code that you want for the Long side; the Short side will follow the same ideas. You will have to copy and paste the code into the correct places in a new indicator that you write (or modify your current one, as required).
      Wow!
      The Long side works just as I asked.
      Thank you so much for this. I could never have come up with this by myself
      copying and pasting. You saved me so much time.
      You are the best!

      Comment


        #33
        "It would certainly be easier if I just posted a complete indicator. However, due to the returns (insults or lack of requested feedback), that I have received from at least 3 ingrates on this forum, I decided and published, on this very forum, my decision that I would never provide any complete indicator to anybody ever again for free. That means that while, I may post the entire code for an indicator, that code will be posted as text, not as a complete importable indicator, ready for use. While that may violate the spirit of my decision, it certainly holds to the text of it.

        What that means is that I will provide the code that you want for the Long side; the Short side will follow the same ideas. You will have to copy and paste the code into the correct places in a new indicator that you write (or modify your current one, as required)."


        You are going to ask them to think and learn rather than hand it to them. What an awesome idea.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by mmckinnm, Today, 01:34 PM
        0 responses
        1 view
        0 likes
        Last Post mmckinnm  
        Started by f.saeidi, Today, 01:32 PM
        0 responses
        1 view
        0 likes
        Last Post f.saeidi  
        Started by traderqz, Today, 12:06 AM
        9 responses
        16 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by kevinenergy, 02-17-2023, 12:42 PM
        117 responses
        2,766 views
        1 like
        Last Post jculp
        by jculp
         
        Started by Mongo, Today, 11:05 AM
        5 responses
        15 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X