Mouseclick Event and mouseclickbarnumber

Questions about MultiCharts and user contributed studies.
KhaosTrader
Posts: 186
Joined: 10 May 2012
Has thanked: 14 times
Been thanked: 11 times

Mouseclick Event and mouseclickbarnumber

Postby KhaosTrader » 25 Oct 2012

Hi,

I am trying to get the high and low of a given bar that i click the mouse on. I understand using the ProcessMouseEvents and all that. But I have a hard time getting the values for the bar clicked...

I am trying various ways, but with no luck. .. Sometimes I am getting vBarsAgo as a number less than 0, so I am not sure what I am doing wrong, or how I should approach the problem..

Code: Select all


if MouseClickShiftPressed then begin

vClickBarNbr = MouseClickBarNumber;



[code] //vLastBar = currentbar;
vLastBar = barnumber;
vBarsAgo = vLastBar-vClickBarNbr ;
if vBarsAgo >= 0 then begin
vClickBarHigh = high[vBarsAgo];
vClickBarLow = low[vBarsAgo];
print ("high = " + NumToStr(vclickBarHigh,2) + " Low = " + NumToStr(vclickBarLow,2));
end
else begin
print ("bar= " + NumToStr(vBarsAgo,0) + " Low = " + NumToStr(vclickBarLow,2));
end;

User avatar
Henry MultiСharts
Posts: 9149
Joined: 25 Aug 2011
Has thanked: 1260 times
Been thanked: 2932 times

Re: Mouseclick Event and mouseclickbarnumber

Postby Henry MultiСharts » 26 Oct 2012

Hello KhaosTrader,

Please try this code:

Code: Select all

[ProcessMouseEvents = true]

vars: vClickBarNbr(0), vLastBar(0), vBarsAgo(0), vClickBarHigh(0), vClickBarLow(0);

if MouseClickShiftPressed then begin

vClickBarNbr = MouseClickBarNumber;

vLastBar = BarNumber + MaxBarsBack;
vBarsAgo = vLastBar-vClickBarNbr ;
if vBarsAgo >= 0 then begin
vClickBarHigh = high[vBarsAgo];
vClickBarLow = low[vBarsAgo];
print ("high = " + NumToStr(vclickBarHigh,2) + " Low = " + NumToStr(vclickBarLow,2));
end
else begin
print ("bar= " + NumToStr(vBarsAgo,0) + " Low = " + NumToStr(vclickBarLow,2));
end;

end;

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

Re: Mouseclick Event and mouseclickbarnumber

Postby arjfca » 26 Oct 2012

Hello KhaosTrader,

Please try this code:

Code: Select all

[ProcessMouseEvents = true]

vars: vClickBarNbr(0), vLastBar(0), vBarsAgo(0), vClickBarHigh(0), vClickBarLow(0);

if MouseClickShiftPressed then begin

vClickBarNbr = MouseClickBarNumber;

vLastBar = BarNumber + MaxBarsBack;
vBarsAgo = vLastBar-vClickBarNbr ;
if vBarsAgo >= 0 then begin
vClickBarHigh = high[vBarsAgo];
vClickBarLow = low[vBarsAgo];
print ("high = " + NumToStr(vclickBarHigh,2) + " Low = " + NumToStr(vclickBarLow,2));
end
else begin
print ("bar= " + NumToStr(vBarsAgo,0) + " Low = " + NumToStr(vclickBarLow,2));
end;

end;
Hello Henry

Anyway to remove the re-bounce on the reading. Many lecture done for one click. Value is kept in memory and re-use later ( re print on the output window)

Martin :)

User avatar
Henry MultiСharts
Posts: 9149
Joined: 25 Aug 2011
Has thanked: 1260 times
Been thanked: 2932 times

Re: Mouseclick Event and mouseclickbarnumber

Postby Henry MultiСharts » 26 Oct 2012

Hello Henry

Anyway to remove the re-bounce on the reading. Many lecture done for one click. Value is kept in memory and re-use later ( re print on the output window)

Martin :)
Hello Martin,

Please explain what do you mean exactly.

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

Re: Mouseclick Event and mouseclickbarnumber

Postby arjfca » 26 Oct 2012

Hello Henry

Anyway to remove the re-bounce on the reading. Many lecture done for one click. Value is kept in memory and re-use later ( re print on the output window)

Martin :)
Hello Martin,

Please explain what do you mean exactly.
Henry, Please see the snap picture of my output window. I clicked only once. many output
There is no fix value of the numbers of output that it may generate

Martin
Attachments
Click.png
(10.49 KiB) Downloaded 1163 times

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

Re: Mouseclick Event and mouseclickbarnumber

Postby TJ » 26 Oct 2012

Hello Henry

Anyway to remove the re-bounce on the reading. Many lecture done for one click. Value is kept in memory and re-use later ( re print on the output window)

Martin :)
Hello Martin,

Please explain what do you mean exactly.
Henry, Please see the snap picture of my output window. I clicked only once. many output
There is no fix value of the numbers of output that it may generate

Martin
use intrabarpersist

KhaosTrader
Posts: 186
Joined: 10 May 2012
Has thanked: 14 times
Been thanked: 11 times

Re: Mouseclick Event and mouseclickbarnumber

Postby KhaosTrader » 26 Oct 2012

intrabarpersist still causes same problem tried that.

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

Re: Mouseclick Event and mouseclickbarnumber

Postby arjfca » 26 Oct 2012

use intrabarpersist[/quote]

Same problem
Martin

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

Re: Mouseclick Event and mouseclickbarnumber

Postby arjfca » 28 Oct 2012

Hello Henry

Anyway to remove the re-bounce on the reading. Many lecture done for one click. Value is kept in memory and re-use later ( re print on the output window)

Martin :)
Hello Martin,

Please explain what do you mean exactly.
Henry, Please see the snap picture of my output window. I clicked only once. many output
There is no fix value of the numbers of output that it may generate

Martin
Henry or other MC staff,

Could you confirm that you are able to reproduce multiple click problem. Anyway to get over it?

Martin

User avatar
ABC
Posts: 636
Joined: 16 Dec 2006
Has thanked: 120 times
Been thanked: 359 times
Contact:

Re: Mouseclick Event and mouseclickbarnumber

Postby ABC » 28 Oct 2012

use intrabarpersist

Same problem
Martin
Martin,

a flag with intrabarpersist or recalcpersist will work fine, I am using it together with Mouseclickevents and it will only trigger once.

Regards,

ABC

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

Re: Mouseclick Event and mouseclickbarnumber

Postby arjfca » 28 Oct 2012

Good day sir

I did try with Intrabarpersist and problem do persist. Never tried RecalcPersist.
When you mention a flag, what do you mean?

Have a good day Christoph

Martin

User avatar
ABC
Posts: 636
Joined: 16 Dec 2006
Has thanked: 120 times
Been thanked: 359 times
Contact:

Re: Mouseclick Event and mouseclickbarnumber

Postby ABC » 28 Oct 2012

Good day sir

I did try with Intrabarpersist and problem do persist. Never tried RecalcPersist.
When you mention a flag, what do you mean?

Have a good day Christoph

Martin
I mean a variable you use to make sure that the clickevent will only be executed once (or how often you want it).
It would look something like this:

Code: Select all

Variable:
intrabarpersist HaveMouseClick (false); //that variable is what I'd call a flag

if MouseClickShiftPressed and HaveMouseClick = false then
begin
HaveMouseClick = true;

end;
I didn't test the code piece, but I use something similar to only use one click and ignore the other clicks (although I use recalcpersist there with the variable, the code looks similar).

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

Re: Mouseclick Event and mouseclickbarnumber

Postby arjfca » 28 Oct 2012

Good day sir

I did try with Intrabarpersist and problem do persist. Never tried RecalcPersist.
When you mention a flag, what do you mean?

Have a good day Christoph

Martin
I mean a variable you use to make sure that the clickevent will only be executed once (or how often you want it).
It would look something like this:

Code: Select all

Variable:
intrabarpersist HaveMouseClick (false); //that variable is what I'd call a flag

if MouseClickShiftPressed and HaveMouseClick = false then
begin
HaveMouseClick = true;

end;
I didn't test the code piece, but I use something similar to only use one click and ignore the other clicks (although I use recalcpersist there with the variable, the code looks similar).
Experience same problem, even with a flag. Read data are kept and out of nowhere, sometime 10 second later, same lecture will be print in the Output window. For the following code, I did try with and whitout IntrabarPersist.

Code: Select all

[ProcessMouseEvents = true]

vars:
Intrabarpersist vClickBarNbr(0),
Intrabarpersist vLastBar(0),
Intrabarpersist vBarsAgo(0),
Intrabarpersist vClickBarHigh(0),
Intrabarpersist vClickBarLow(0),
AmouseClick (false),
Intrabarpersist BarNumberTarget (0);

if MouseClickShiftPressed and amouseclick = false then begin
Amouseclick = True;
vClickBarNbr = MouseClickBarNumber;

vLastBar = BarNumber + MaxBarsBack;
vBarsAgo = vLastBar-vClickBarNbr ;
if vBarsAgo >= 0 then begin
vClickBarHigh = high[vBarsAgo];
vClickBarLow = low[vBarsAgo];
print ("high = " + NumToStr(vclickBarHigh,2) + " Low = " + NumToStr(vclickBarLow,2));
end
else begin
print ("bar= " + NumToStr(vBarsAgo,0) + " Low = " + NumToStr(vclickBarLow,2));
end;
AMOUSECLICK = FALSE;
end;
I will wait for MC to confirm or not that they could reproduce the problem.

Martin

SP
Posts: 455
Joined: 06 Feb 2006
Has thanked: 36 times
Been thanked: 283 times

Re: Mouseclick Event and mouseclickbarnumber

Postby SP » 29 Oct 2012

Martin,

as i learned from my codes with MouseClick events, it is the best solution to use lastbaronchart_S
and keep all calculations outside of the "if MouseClickShiftPressed then begin..." loop.

Take a look if this modification works for you:

Code: Select all

[ProcessMouseEvents = true]

vars:
Intrabarpersist vClickBarNbr(0),
Intrabarpersist vLastBar(0),
Intrabarpersist vBarsAgo(0),
Intrabarpersist vClickBarHigh(0),
Intrabarpersist vClickBarLow(0),
initialized(false),
Intrabarpersist AmouseClick (false),
Intrabarpersist BarNumberTarget (0);

Once begin
Amouseclick = false;
end; //Once


if initialized and LastBarOnChart_s then
begin

if MouseClickShiftPressed and amouseclick = false then
begin
Amouseclick = True;
vClickBarNbr = MouseClickBarNumber;
end; //if MouseClickShiftPressed and amouseclick = false then


if Amouseclick = True {and Amouseclick[1] = False} then
begin
//ClearPrintLog;
vLastBar = BarNumber + MaxBarsBack;
vBarsAgo = vLastBar-vClickBarNbr ;
if vBarsAgo >= 0 then
begin
vClickBarHigh = high[vBarsAgo];
vClickBarLow = low [vBarsAgo];
print ("high = " , NumToStr(vclickBarHigh,2) , " Low = " , NumToStr(vclickBarLow,2) ," Bars Ago = ",NumToStr(vBarsAgo ,2)," Init ",initialized," MaxBarsBack",MaxBarsBack);
end
else begin
print ("bar= " , NumToStr(vBarsAgo,0) , " Low = " , NumToStr(vclickBarLow,2));
end;
Amouseclick = FALSE;
end; //if Amouseclick = True

end; // if initialized and LastBarOnChart_s then

initialized = initialized or lastbaronchart_s and barstatus = 2;

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

Re: Mouseclick Event and mouseclickbarnumber

Postby arjfca » 29 Oct 2012

Thanks SP

Code does not detect any mouseclick for me. I will look deeper in it after my trading session and come back

I will keep the suggestion to not do calculation in the Mouseclick loop

A way to remove a re-bouce on a click is to induce a delay between lecture. A 15 ms delay between reading would be more than enough

If not working, I will create a function to read PC time, add 15ms, compare time with the nue value, If not achieved, skip the mouse reading. This way, only the fiest click should be read. All other should be filtered by de 15 ms delay

I had similar problem when designing a special keyboard switch

Have a good day

Martin

SP
Posts: 455
Joined: 06 Feb 2006
Has thanked: 36 times
Been thanked: 283 times

Re: Mouseclick Event and mouseclickbarnumber

Postby SP » 29 Oct 2012

Set the study to subchart #1 and uncheck
- Update on every tick
- Realtime-history matching
- Skip identical ticks

At least for me that works.

Edit: As i only tested it as the market was closed at the morning, there is indeed an error printing the lines again on a new bar at realtime charts.

User avatar
Henry MultiСharts
Posts: 9149
Joined: 25 Aug 2011
Has thanked: 1260 times
Been thanked: 2932 times

Re: Mouseclick Event and mouseclickbarnumber

Postby Henry MultiСharts » 29 Oct 2012

arjfca, I have sent you the fix for testing via email.


Return to “MultiCharts”