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

Basic programming question

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

    Basic programming question

    Hello,
    I would like to have a line drawn on the price chart when, for instance, the Stoch goes from 20 to 80. Can someone give me a few pointers on how to code this?
    Thanks
    Last edited by CaptainAmericaXX; 10-24-2015, 08:35 PM. Reason: I felt this title better fit

    #2
    Hello CaptainAmericaXX,

    You could use compare a Stochastic value to an integer value. Below I have included an example of this. In the example, if the Stochastic value of the current bar is equal to or greater than 80, then draw a horizontal line

    if (Stochastics(3, 14, 7).D[0] >= 80);
    {
    DrawHorizontalLine("tag1", Close[0], Color.Black);
    }
    Shawn B.NinjaTrader Customer Service

    Comment


      #3
      Thank you for that information. Can you give me an additional suggestion for drawing an angled line from the closing price when the Stoch crossed above 20 to the closing price where the Stoch crossed above 80?
      Thanks.

      Comment


        #4
        Hello CaptainAmericaXX,

        Thanks for your reply.

        To draw a line from one bar to another you will need to identify a begin and then later an end bar. So this means you will need to create a variable to hold the bar number of the bar when the Stochastics (D? K?) crossed the 20 line. For this example I used the Stochastics K plotline and used an integer variable called beginBar. We will also need a logic variable so that we only plot when we have a successive crossabove 20 followed by cross above 80. For this example I created a bool variable called doItOnce.

        Determine when the stochastics K line crosses above the 20:

        Code:
        			if (CrossAbove(Stochastics(7, 14, 3).K, 20, 1))
        			{
        				beginBar = CurrentBar;  // save the bar number
        				doItOnce = true;     // set the logic true for the next check.
        			}
        Now that we have the first data point (beginBar) we need to make sure that the next crossabove is of the 80 line, so I used a crossbelow of the 20 line as a reset for when the stoch does not get to 80 and then reverses itself. You may or may not want this but here it is:

        Code:
        if (CrossBelow(Stochastics(7, 14, 3).K, 20, 1))
        			{
        				doItOnce = false;  // reset the condition till we cross above 20 again
        			}
        Finally we test for the crossabove the 80 line and then plot the line:

        Code:
        		if (CrossAbove(Stochastics(7, 14, 3).K, 80, 1) && doItOnce)
        			{				
        				DrawLine("test"+CurrentBar, CurrentBar - beginBar, Close[CurrentBar - beginBar], 0, Close[0], Color.Red);
        				doItOnce = false;  // reset logic to look for next 20 cross above
        			}
        In the crossabove statement we used the logic variable doItOnce to make sure we only proceeded when we had previously found the crossabove 20 line. Note that in the drawline statement we are using the current bar and subtracting the begin bar to arrive at the "barsago" value needed and then drawing to the current bar [0].
        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        4 views
        0 likes
        Last Post Javierw.ok  
        Started by timmbbo, Today, 08:59 AM
        2 responses
        10 views
        0 likes
        Last Post bltdavid  
        Started by alifarahani, Today, 09:40 AM
        6 responses
        40 views
        0 likes
        Last Post alifarahani  
        Started by Waxavi, Today, 02:10 AM
        1 response
        18 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by Kaledus, Today, 01:29 PM
        5 responses
        15 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X