Announcement

Collapse
No announcement yet.

Magnet for Horz line mouse click

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

  • Magnet for Horz line mouse click

    This is some bits of code from other EFS by Garth Doverspike and Steve Hare. I'm trying to draw a horizontal line at the High or Low of a bar without hitting it right on with the mouse click. I couldn't find any documentation on how the CheckNear function works..
    The line draws but the magnet part does not work..

    TXs to anyone who has a suggestion! Don

    function preMain()
    {
    setPriceStudy(true);
    }
    function main() {
    }
    function onLButtonDblClk(barIndex, yValue)
    {
    // CheckNear function - return the OHLC value closest to the mouse click
    function CheckNear(yValue, nOpen,nClose,nHigh,nLow)
    {
    // Is click closer to High or Low?
    if (Math.abs(yValue-nHigh) <= Math.abs(yValue-nLow))
    // High Wins!
    yValue==nHigh;
    else // Low Wins!
    yValue==nLow;
    }
    drawLineRelative( barIndex, yValue, 10, yValue, PS_SOLID, 2, Color.blue, "Testline");


    }

  • #2
    Hi Don,

    try this...

    PHP Code:
    function preMain(){
     
    setPriceStudy(true);
    }

    function 
    main() {


    function 
    onLButtonDblClk(barIndexyValue
    {
     
    yValue checkNear(barIndexyValue); // calls checkNear Function and assigns yValue the return value
     
    drawLineRelativebarIndexyValue10yValuePS_SOLID2Color.blue"Testline");
    }

    // checkNear function - return the HL value closest to the mouse click
    function checkNear(barIndexyValue){ 
     var 
    tmp null;
     
    // Is click closer to High or Low?
     
    if (Math.abs(yValue-high(barIndex)) <= Math.abs(yValue-low(barIndex))){ // High Wins!
      
    tmp high(barIndex);
     }
     else{ 
    // Low Wins!
      
    tmp low(barIndex);
     }
     return 
    tmp;

    Comment

    Working...
    X