Announcement

Collapse
No announcement yet.

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);
    }

    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].

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        574 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        333 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        553 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        551 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X