Alerts at specific levels marked with mouse clicks

Hi,
I would like my code to generate alert (and sounds) when a specific price level is crossed. This price level is set by me dynamically by using mouse click + ctrl button. I have used getcursormousebuttons and getcursoryposition for this purpose. But the problem is that alert is removed after the mouse click + ctrl is done. And also I am not able to mark the price level (Y) using the plotshapes. Below is the code. any help will be appreciated.

b = GetCursorMouseButtons();
ctrlkeydown = GetAsyncKeyState(17) < 0;
// retrieve co-ordinates in date/value units
x = GetCursorXPosition(0);
y = GetCursorYPosition(0);

if( b & 8 ) // flag = 8 is set when window just received mouse click
{
   // not-null means clicked in THIS (current) window
   if( b & 1  AND ctrlkeydown) 
   {
   Plotshapes( shapeSmallSquare, colorBlue, 0,y );
   AlertIf( Cross(C,y), "SOUND C:\\Windows\\Media\\Alarm02.wav", "Audio alert", 1 ,2);
   }
   
}

Hi
you need to read static variable to store the Y price

i add few lines of code to give you a nice start.

Plot( C, "Price", colorDefault, styleCandle );

SVAlertLine= Nz(StaticVarGet("SVAlertĪ„"));  

b = GetCursorMouseButtons();
ctrlkeydown = GetAsyncKeyState(17) < 0;
// retrieve co-ordinates in date/value units
x = GetCursorXPosition(0);
y = GetCursorYPosition(0);		//y - value gives PRICE


if( b & 8 ) // flag = 8 is set when window just received mouse click
{
   // not-null means clicked in THIS (current) window
   if( b & 1  AND ctrlkeydown) 
   {
   // Store the Y value to the staticVariable and then use it later
	StaticVarset("SVAlertĪ„",Y);   
   }
   
}

// do something if statickVar has a value > 0
if( SVAlertLine > 0 )
{
    //Plotshapes( shapeSmallSquare, colorBlue, 0, SVAlertLine );   //please  DONOT USE Plotshapes
    Plot(SVAlertLine,"",ParamColor("Horizontal Line Color",colorBlue),1 | styleNoLabel);
    AlertIf( Cross( C, SVAlertLine ), "SOUND C:\\Windows\\Media\\Alarm02.wav", "Audio alert", 1 , 2 );
}

P.S
Just remember use GFX to plot the lines instead of plotshape

function GfxPlotLines(  x1,y1,x2,y2, color)
{
GfxSelectPen( color, 1 );
GfxMoveTo( x1, y1 );   GfxLineTo( x2, y2 );
}
1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.