Use hotkey to show or hide line

Hello,

The below code can plot line when press SHIFT + left mouse button. However, the line will be fast disappeared. What is the reason? How to solve it?

LButtonTrigger = GetCursorMouseButtons() == 9;
vk_Shift = 16; 
if (GetAsyncKeyState( vk_Shift ) < 0 AND LButtonTrigger )
{	    
    Plot(EMA(Close,200),"EMA_200",colorOrange,styleThick);
}

The line will obviously disappear as soon as you release the button because
the "if" part is no longer executed if button is not pressed.

You should use ParamToggle or static variable it you want to keep the on/off state.

thanks your reply.
How I use static variable to keep the state ?

Search this forum for "static".

thanks, I find it . Refer to others

LButtonTrigger = GetCursorMouseButtons() == 9;
vk_Space = 32; 	
vk_Shift = 16; 
vk_Control = 17;
vk_ALT  = 18;
vk_Tab = 9;

if (GetAsyncKeyState( vk_Shift ) < 0 AND LButtonTrigger )
{	    
	StaticVarSet ( "close_200_static" + GetChartID(), MouseX + MouseY );    
}
if(StaticVarGet ( "close_200_static" + GetChartID()) ){
	Plot(EMA(Close,slongMA),"EMA_" + slongMA,colorOrange,styleThick);
}
//CTRL  + left mouse click remove the ma line
if (GetAsyncKeyState( vk_Control ) < 0 AND LButtonTrigger){
  
    StaticVarRemove( "*" );			
}

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