Deleting Existing Arrow with new click

Questions about MultiCharts and user contributed studies.
olobay
Posts: 47
Joined: 28 Dec 2011
Has thanked: 17 times

Deleting Existing Arrow with new click

Postby olobay » 22 Sep 2019

Hi,

I have written a code that is almost doing what I want. The only thing I would like to do but can't figure out, is to remove all previously drawn arrows, 2 of them, when I click on a new bar, while drawing the first new arrow. Right now, all old arrows remain on the chart. I tried with Arw_Delete but I couldn't get it to work. I have removed some of the math calculations. Any help is appreciated.

Code: Select all

Inputs: Mins_Add(60), iSquare(2), TL_Colour(green), Txt_Colour(green), Arrow_Size(8);

[ProcessMouseEvents = true];
[RecoverDrawings = false];

switch (getappinfo(aicalcreason)) begin
case CalcReason_MouseLClick : if MouseClickCtrlPressed and not MouseClickShiftPressed then begin

var : recalcpersist iPrice(0),
recalcpersist iBar1(0),
recalcpersist iBar2(0),
recalcpersist dt1(0),
recalcpersist dt2(0),
recalcpersist dt3(0),
recalcpersist Step1(0),
recalcpersist Step2(0),
recalcpersist Step3(0),
recalcpersist Step4(0),
recalcpersist Step5(0),
recalcpersist Step6(0),
recalcpersist beginPrice(0),
recalcpersist arrowID1(0),
recalcpersist arrowID2(0);

repeat
if 0 = iBar1 then begin
iBar1 = MouseClickDateTime;
dt1 = MouseClickBarNumber;
arrowID1 = Arw_New_BN(dt1, MouseClickPrice, true);
Arw_SetSize(arrowID1, Arrow_Size);
Arw_SetColor(arrowID1, TL_Colour);
break;
end;

if 0 = iBar2 then begin
iBar2 = MouseClickDateTime;
dt2 = MouseClickBarNumber;
arrowID2 = Arw_New_BN(dt2, MouseClickPrice, true);
Arw_SetSize(arrowID2, Arrow_Size);
Arw_SetColor(arrowID2, TL_Colour);
break;
end;

if 0 = iPrice then begin
iPrice = MouseClickDateTime;
dt3 = MouseClickPrice;
break;
end;

until (False);

if 0 <> iPrice and 0 <> iBar1 and 0 <> iBar2 then begin

Step1 = ---------------------------------
Step2 = --------------------------------
Step3 = --------------------------------
Step4 = Step3 - Step2;
Step5 = --------------------------------
Step6 = Round(Step5, 2);

draw_hor_line(Step6, iPrice, TL_Colour, Txt_Colour, " Buy Projection ");

iBar1 = 0;
iBar2 = 0;
iPrice = 0;

end;
end;
end;
Attachments
multiple clicks.jpg
It creates 2 arrows after every 3 clicks so this is after 4 instances. 8 arrows.
(195.93 KiB) Downloaded 81 times
1st click.jpg
It should only have 2 arrows.
(123.27 KiB) Downloaded 81 times

olobay
Posts: 47
Joined: 28 Dec 2011
Has thanked: 17 times

Re: Deleting Existing Arrow with new click

Postby olobay » 23 Sep 2019

So here is what I have figured out so far but it's still not 100% perfect. This only deletes the earliest arrow plotted. Can anyone please help?

Code: Select all

Inputs: Mins_Add(60), iSquare(2), TL_Colour(green), Txt_Colour(green), Arrow_Size(8);

[ProcessMouseEvents = true];
[RecoverDrawings = false];

switch (getappinfo(aicalcreason)) begin
case CalcReason_MouseLClick : if MouseClickCtrlPressed and not MouseClickShiftPressed then begin

var : recalcpersist iPrice(0),
recalcpersist iBar1(0),
recalcpersist iBar2(0),
recalcpersist dt1(0),
recalcpersist dt2(0),
recalcpersist dt3(0),
recalcpersist Step1(0),
recalcpersist Step2(0),
recalcpersist Step3(0),
recalcpersist Step4(0),
recalcpersist Step5(0),
recalcpersist Step6(0),
recalcpersist beginPrice(0),
recalcpersist arrowID1(0),
recalcpersist arrowID2(0);

repeat
if 0 = iBar1 then begin
iBar1 = MouseClickDateTime;
dt1 = MouseClickBarNumber;
arrowID1 = Arw_New_BN(dt1, MouseClickPrice - .10, true);
Arw_SetSize(arrowID1, Arrow_Size);
Arw_SetColor(arrowID1, TL_Colour);
break;
end;

if 0 = iBar2 then begin
iBar2 = MouseClickDateTime;
dt2 = MouseClickBarNumber;
arrowID2 = Arw_New_BN(dt2, MouseClickPrice - .10, true);
Arw_SetSize(arrowID2, Arrow_Size);
Arw_SetColor(arrowID2, TL_Colour);
break;
end;

if 0 = iPrice then begin
iPrice = MouseClickDateTime;
dt3 = MouseClickPrice;
break;
end;

until (False);

if 0 <> iPrice and 0 <> iBar1 and 0 <> iBar2 then begin

Step1 = ---------------------------------
Step2 = --------------------------------
Step3 = --------------------------------
Step4 = Step3 - Step2;
Step5 = --------------------------------
Step6 = Round(Step5, 2);

draw_hor_line(Step6, iPrice, TL_Colour, Txt_Colour, " Buy Projection ");

iBar1 = 0;
iBar2 = 0;
iPrice = 0;

if MouseClickCtrlPressed then begin

arrowID1 = Arw_GetFirst(1);

if (ArrowID1 <> -2) then
Arw_Delete(arrowID1);

end;


end;
end;
end;


Return to “MultiCharts”