Targets and stop with mouseclick

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
SP
Posts: 455
Joined: 06 Feb 2006
Has thanked: 36 times
Been thanked: 283 times

Targets and stop with mouseclick

Postby SP » 02 Mar 2012

This code shows how to use the new mouseclick function to plot lines on the chart.

- If you use "crtl + mouseclick" the indicator starts plotting the entry based on the last close,
2 long targets and 1 stop based on ticks.
- If you click above the last close it plots targets for short entry, below for long entry.
- If you use "shift + mouseclick" the indicator resets.

Code: Select all

{//*************************************
Version3 by SP
Make sure that you click on the chart and not at the subchart.
Limitations:
- Somtimes does not work if you reset multiple times on the same bar
- For MC 8 and above only.
***************************************//}
[ProcessMouseEvents = True];

input: StopTicks (10),
Target1Ticks (15),
Target2Ticks (25),
t1 ("Font and Text Size"),
SetFontName ("Consolas"),
TextSize (10),
RightSpace (3), //to adjust the right space
Target1Color (cyan),
Target2Color (blue),
StopColor (magenta),
UpColor (green),
DnColor (red);

variables:
mTickSize (0),
intrabarpersist mPosition (0),
intrabarpersist mstop (0),
intrabarpersist mentry (0),
intrabarpersist mtarget1 (0),
intrabarpersist mtarget2 (0),
intrabarpersist mclickprice (0),
intrabarpersist Starttime (0), //Startime of the mouseclick
intrabarpersist Startdate (0), //Startdate of the mouseclick
MyPlottime (0),
MyDecimalPlaces (0),
BarsSinceLastReset (0),
intrabarpersist isfirsttick (0),
intrabarpersist StartTracking (0);

Once
begin
mTickSize = minmove *reciprocal(priceScale);
MyDecimalPlaces = Log(PriceScale) / Log(10);
BarsSinceLastReset = 0;
Starttime = 0;
Startdate = 0;
mentry = 0;
StartTracking = 0;
isfirsttick = 0;
end;


if LastBarOnChart_s then
begin

If StartTracking = 0 then
begin
//Begin tracking after crtl + mouseclick
If MouseClickCtrlPressed then StartTracking = 1;
end;

// if we are in the middle of a bar, store the entry
if StartTracking[1] = 0 and StartTracking = 1 and isfirsttick = 0 then
begin
mclickprice = MouseClickPrice;
mentry = close;
isfirsttick = 1;
Starttime = time_s;
Startdate = date;
end;

if StartTracking = 1 then
begin

if StartTracking[1] = 0 and StartTracking = 1 then
begin
if mclickprice > mentry then mPosition = -1 else mPosition = 1;
//Calculate Stops and Targets
mstop = iff (mPosition =1, mentry - StopTicks *mTickSize , mentry + StopTicks *mTickSize );
mtarget1 = iff (mPosition =1, mentry + Target1Ticks*mTickSize , mentry - Target1Ticks*mTickSize );
mtarget2 = iff (mPosition =1, mentry + Target2Ticks*mTickSize , mentry - Target2Ticks*mTickSize );
end;
//Increase the Barcounter, for later use for high/low since
BarsSinceLastReset = BarsSinceLastReset + 1;
MyPlottime = intportion (MinutesToTime ((GetAppInfo (7))*1440)*100);

if BarsSinceLastReset = 1 then
begin
//Draw lines and text
value2 = text_new_s (date,time_S,c,"" );
text_setsize (value2,TextSize);text_setfontname (value2,SetFontName);
value4 = text_new_s (date,time_S,c,"" );
text_setsize (value4,TextSize);text_setfontname (value4,SetFontName);
value6 = text_new_s (date,time_S,c,"" );
text_setstyle( value6,1,1);text_setsize (value6,TextSize);text_setfontname (value6,SetFontName);
value8 = text_new_s (date,time_S,c,"" );
text_setstyle( value8,1,1);text_setsize (value8,TextSize);text_setfontname (value8,SetFontName);
end;

//Update textposition and colors
value1 = tl_new_s (Startdate ,Starttime ,mentry ,date,time_S,mentry );
tl_setextright (value1,true);
if mPosition = 1 then tl_setcolor (value1,green) else tl_setcolor (value1,red) ;

if mPosition = 1 then
text_setstring (value2, " LONG ENTRY.@ " +NumToStr(mentry,MyDecimalPlaces )+Spaces(RightSpace)) else
text_setstring (value2, " SHORT ENTRY..@ "+NumToStr(mentry,MyDecimalPlaces )+Spaces(RightSpace));
text_setlocation_s (value2,date,MyPlottime,mentry);
if mPosition = 1 then text_setcolor (value2,green) else text_setcolor (value2,red);
if mPosition = 1 then text_setstyle (value2,1,0) else text_setstyle( value2,1,1) ;

value3 = tl_new_s (Startdate ,Starttime ,mstop ,date,time_S,mstop );
tl_setextright (value3,true);
tl_setcolor (value3,StopColor);

text_setstring (value4, " STOP........@ "+NumToStr(mstop ,MyDecimalPlaces )+Spaces (RightSpace));
text_setlocation_s (value4,date,MyPlottime,mstop );
text_setcolor (value4,StopColor);
if mPosition = 1 then text_setstyle (value4,1,0) else text_setstyle( value4,1,1) ;

value5 = tl_new_s (Startdate ,Starttime ,mtarget1 ,date,time_S,mtarget1 );
tl_setextright (value5,true);
tl_setcolor (value5,Target1Color);

text_setstring (value6, " TARGET 1....@ "+NumToStr(mtarget1 ,MyDecimalPlaces )+Spaces (RightSpace));
text_setlocation_s (value6,date,MyPlottime,mtarget1 );
text_setcolor (value6,Target1Color);
if mPosition = 1 then text_setstyle (value6,1,1) else text_setstyle( value6,1,0) ;

value7 = tl_new_s (Startdate ,Starttime ,mtarget2 ,date,time_S,mtarget2 );
tl_setextright (value7,true);
tl_setcolor (value7,Target2Color);

text_setstring (value8, " TARGET 2....@ "+NumToStr(mtarget2 ,MyDecimalPlaces )+Spaces (RightSpace));
text_setlocation_s (value8,date,MyPlottime,mtarget2 );
text_setcolor (value8,Target2Color);
if mPosition = 1 then text_setstyle (value8,1,1) else text_setstyle( value8,1,0) ;

end; //StartTracking = 1

//Reset values back to initial values
If StartTracking = 1 and MouseClickShiftPressed then
begin
tl_delete (value1);tl_delete (value3);tl_delete (value5);tl_delete (value7);
text_delete (value2);text_delete (value4);text_delete (value6);text_delete (value8);
BarsSinceLastReset = 0;
Starttime = 0;
mentry = 0;
isfirsttick = 0;
StartTracking = 0;

end; //MouseClickShiftPressed

end; //Lastbaronchart
Attachments
MouseTS.jpg
(26.27 KiB) Downloaded 1584 times

User avatar
TJ
Posts: 7232
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2058 times

Re: Targets and stop with mouseclick

Postby TJ » 02 Mar 2012

This code shows how to use the new mouseclick function to plot lines on the chart....
Cool.

Thanks for sharing.

User avatar
JoshM
Posts: 2099
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1526 times
Been thanked: 1503 times
Contact:

Re: Targets and stop with mouseclick

Postby JoshM » 02 Mar 2012

Nice, innovative, and a good example of these new functions SP. Thanks for sharing! :)

arjfca
Posts: 1283
Joined: 23 Nov 2010
Has thanked: 724 times
Been thanked: 222 times

Re: Targets and stop with mouseclick: Function bug?

Postby arjfca » 22 May 2013

This code shows how to use the new mouseclick function to plot lines on the chart.

- If you use "crtl + mouseclick" the indicator starts plotting the entry based on the last close,
2 long targets and 1 stop based on ticks.
- If you click above the last close it plots targets for short entry, below for long entry.
- If you use "shift + mouseclick" the indicator resets.

Code: Select all

{//*************************************
Version3 by SP
Make sure that you click on the chart and not at the subchart.
Limitations:
- Somtimes does not work if you reset multiple times on the same bar
- For MC 8 and above only.
***************************************//}
[ProcessMouseEvents = True];

input: StopTicks (10),
Target1Ticks (15),
Target2Ticks (25),
t1 ("Font and Text Size"),
SetFontName ("Consolas"),
TextSize (10),
RightSpace (3), //to adjust the right space
Target1Color (cyan),
Target2Color (blue),
StopColor (magenta),
UpColor (green),
DnColor (red);

variables:
mTickSize (0),
intrabarpersist mPosition (0),
intrabarpersist mstop (0),
intrabarpersist mentry (0),
intrabarpersist mtarget1 (0),
intrabarpersist mtarget2 (0),
intrabarpersist mclickprice (0),
intrabarpersist Starttime (0), //Startime of the mouseclick
intrabarpersist Startdate (0), //Startdate of the mouseclick
MyPlottime (0),
MyDecimalPlaces (0),
BarsSinceLastReset (0),
intrabarpersist isfirsttick (0),
intrabarpersist StartTracking (0);

Once
begin
mTickSize = minmove *reciprocal(priceScale);
MyDecimalPlaces = Log(PriceScale) / Log(10);
BarsSinceLastReset = 0;
Starttime = 0;
Startdate = 0;
mentry = 0;
StartTracking = 0;
isfirsttick = 0;
end;


if LastBarOnChart_s then
begin

If StartTracking = 0 then
begin
//Begin tracking after crtl + mouseclick
If MouseClickCtrlPressed then StartTracking = 1;
end;

// if we are in the middle of a bar, store the entry
if StartTracking[1] = 0 and StartTracking = 1 and isfirsttick = 0 then
begin
mclickprice = MouseClickPrice;
mentry = close;
isfirsttick = 1;
Starttime = time_s;
Startdate = date;
end;

if StartTracking = 1 then
begin

if StartTracking[1] = 0 and StartTracking = 1 then
begin
if mclickprice > mentry then mPosition = -1 else mPosition = 1;
//Calculate Stops and Targets
mstop = iff (mPosition =1, mentry - StopTicks *mTickSize , mentry + StopTicks *mTickSize );
mtarget1 = iff (mPosition =1, mentry + Target1Ticks*mTickSize , mentry - Target1Ticks*mTickSize );
mtarget2 = iff (mPosition =1, mentry + Target2Ticks*mTickSize , mentry - Target2Ticks*mTickSize );
end;
//Increase the Barcounter, for later use for high/low since
BarsSinceLastReset = BarsSinceLastReset + 1;
MyPlottime = intportion (MinutesToTime ((GetAppInfo (7))*1440)*100);

if BarsSinceLastReset = 1 then
begin
//Draw lines and text
value2 = text_new_s (date,time_S,c,"" );
text_setsize (value2,TextSize);text_setfontname (value2,SetFontName);
value4 = text_new_s (date,time_S,c,"" );
text_setsize (value4,TextSize);text_setfontname (value4,SetFontName);
value6 = text_new_s (date,time_S,c,"" );
text_setstyle( value6,1,1);text_setsize (value6,TextSize);text_setfontname (value6,SetFontName);
value8 = text_new_s (date,time_S,c,"" );
text_setstyle( value8,1,1);text_setsize (value8,TextSize);text_setfontname (value8,SetFontName);
end;

//Update textposition and colors
value1 = tl_new_s (Startdate ,Starttime ,mentry ,date,time_S,mentry );
tl_setextright (value1,true);
if mPosition = 1 then tl_setcolor (value1,green) else tl_setcolor (value1,red) ;

if mPosition = 1 then
text_setstring (value2, " LONG ENTRY.@ " +NumToStr(mentry,MyDecimalPlaces )+Spaces(RightSpace)) else
text_setstring (value2, " SHORT ENTRY..@ "+NumToStr(mentry,MyDecimalPlaces )+Spaces(RightSpace));
text_setlocation_s (value2,date,MyPlottime,mentry);
if mPosition = 1 then text_setcolor (value2,green) else text_setcolor (value2,red);
if mPosition = 1 then text_setstyle (value2,1,0) else text_setstyle( value2,1,1) ;

value3 = tl_new_s (Startdate ,Starttime ,mstop ,date,time_S,mstop );
tl_setextright (value3,true);
tl_setcolor (value3,StopColor);

text_setstring (value4, " STOP........@ "+NumToStr(mstop ,MyDecimalPlaces )+Spaces (RightSpace));
text_setlocation_s (value4,date,MyPlottime,mstop );
text_setcolor (value4,StopColor);
if mPosition = 1 then text_setstyle (value4,1,0) else text_setstyle( value4,1,1) ;

value5 = tl_new_s (Startdate ,Starttime ,mtarget1 ,date,time_S,mtarget1 );
tl_setextright (value5,true);
tl_setcolor (value5,Target1Color);

text_setstring (value6, " TARGET 1....@ "+NumToStr(mtarget1 ,MyDecimalPlaces )+Spaces (RightSpace));
text_setlocation_s (value6,date,MyPlottime,mtarget1 );
text_setcolor (value6,Target1Color);
if mPosition = 1 then text_setstyle (value6,1,1) else text_setstyle( value6,1,0) ;

value7 = tl_new_s (Startdate ,Starttime ,mtarget2 ,date,time_S,mtarget2 );
tl_setextright (value7,true);
tl_setcolor (value7,Target2Color);

text_setstring (value8, " TARGET 2....@ "+NumToStr(mtarget2 ,MyDecimalPlaces )+Spaces (RightSpace));
text_setlocation_s (value8,date,MyPlottime,mtarget2 );
text_setcolor (value8,Target2Color);
if mPosition = 1 then text_setstyle (value8,1,1) else text_setstyle( value8,1,0) ;

end; //StartTracking = 1

//Reset values back to initial values
If StartTracking = 1 and MouseClickShiftPressed then
begin
tl_delete (value1);tl_delete (value3);tl_delete (value5);tl_delete (value7);
text_delete (value2);text_delete (value4);text_delete (value6);text_delete (value8);
BarsSinceLastReset = 0;
Starttime = 0;
mentry = 0;
isfirsttick = 0;
StartTracking = 0;

end; //MouseClickShiftPressed

end; //Lastbaronchart
Hello SP

Thanks for the code

I did try it and was not lucky to have it work yet

After the line 58 of your code, I added a print ("Mouse Click");. To my surprise, the print out is done even when no mouse click is done

Code: Select all

begin
//Begin tracking after crtl + mouseclick
If MouseClickCtrlPressed then StartTracking = 1;
//print( "MouseClick");
end;
Could you look if the same occur on your side. If so, I suspect that the function as some bug in it

Martin
Attachments
MouseClick.png
(44.14 KiB) Downloaded 1431 times

User avatar
TJ
Posts: 7232
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2058 times

Re: Targets and stop with mouseclick: Function bug?

Postby TJ » 22 May 2013

Hello SP

Thanks for the code

I did try it and was not lucky to have it work yet

After the line 58 of your code, I added a print ("Mouse Click");. To my surprise, the print out is done even when no mouse click is done

Code: Select all

begin
//Begin tracking after crtl + mouseclick
If MouseClickCtrlPressed then StartTracking = 1;
//print( "MouseClick");
end;
Could you look if the same occur on your side. If so, I suspect that the function as some bug in it

Martin
You will need to add a BEGIN and an END to your MouseClickCtrlPressed .

arjfca
Posts: 1283
Joined: 23 Nov 2010
Has thanked: 724 times
Been thanked: 222 times

Re: Targets and stop with mouseclick: Function bug?

Postby arjfca » 22 May 2013

Hello SP

Thanks for the code

I did try it and was not lucky to have it work yet

After the line 58 of your code, I added a print ("Mouse Click");. To my surprise, the print out is done even when no mouse click is done

Code: Select all

begin
//Begin tracking after crtl + mouseclick
If MouseClickCtrlPressed then StartTracking = 1;
//print( "MouseClick");
end;
Could you look if the same occur on your side. If so, I suspect that the function as some bug in it

Martin
You will need to add a BEGIN and an END to your MouseClickCtrlPressed .
Hello TJ

From SP code, there is a Begin // End before and after the mouse click event. Where else should it be put?

Martin :)

Code: Select all

begin
//Begin tracking after crtl + mouseclick
If MouseClickCtrlPressed then StartTracking = 1;
//print( "MouseClick");
end;

User avatar
TJ
Posts: 7232
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2058 times

Re: Targets and stop with mouseclick

Postby TJ » 22 May 2013

Code: Select all

begin
//Begin tracking after crtl + mouseclick
If MouseClickCtrlPressed then
BEGIN
StartTracking = 1;
print( "MouseClick");
END;
end;

arjfca
Posts: 1283
Joined: 23 Nov 2010
Has thanked: 724 times
Been thanked: 222 times

Re: Targets and stop with mouseclick

Postby arjfca » 22 May 2013

Code: Select all

begin
//Begin tracking after crtl + mouseclick
If MouseClickCtrlPressed then
BEGIN
StartTracking = 1;
print( "MouseClick");
END;
end;
OK OK . I see said the blind men

:)


Return to “User Contributed Studies and Indicator Library”