Mouse Clicks & Rectangles - Code Included - Please Help?  [SOLVED]

Questions about MultiCharts and user contributed studies.
svfutures24
Posts: 16
Joined: 19 Dec 2023
Has thanked: 1 time

Mouse Clicks & Rectangles - Code Included - Please Help?

Postby svfutures24 » 24 Mar 2024

I was hoping someone could help me.

I am trying to create a work around in PowerLanguage for a Fibonacci Tool.

The idea is to register mouse clicks of two points - Swing Point A and Swing Point B. Calculate a given retracement and plot a rectangle filled color in that zone.

Here is what I have so far:

Code: Select all

[ProcessMouseEvents = true]; Inputs: Color(White), Thickness(1), TextSz(8), // Size of text for retracement levels RetraceColor(Blue); // Color of the retracement rectangle Vars: recalcpersist price1(0), recalcpersist price2(0), recalcpersist init(0), recalcpersist rectID(-1), // ID for the retracement rectangle recalcpersist retracement618Price(0), recalcpersist retracement786Price(0), date1(0), time1(0), date2(0), time2(0); If (LastBarOnChart) then begin If MouseClickCtrlPressed then begin If init = 0 then begin // Capture first swing low price1 = MouseClickPrice; init = 1; end else If init = 1 then begin // Capture second swing low and calculate retracement levels price2 = MouseClickPrice; retracement618Price = price2 + (price1 - price2) * 0.618; retracement786Price = price2 + (price1 - price2) * 0.786; // Ensure we do not draw beyond the last bar If rectID > -1 Then RectangleDelete(rectID); // Draw the rectangle for retracement levels starting from the second swing low and extending forward by 20 bars If CurrentBar - MouseClickBarNumber + 20 < CurrentBar then begin rectID = RectangleNew_s(CurrentDate, CurrentTime_s, retracement786Price, CurrentDate, CurrentTime_s, retracement618Price); RectangleSetColor(rectID, RetraceColor); RectangleSetFillColor(rectID, RetraceColor); // Assuming RectangleSetSize or similar command here for Thickness if necessary end; init = 0; // Reset for next use end; end; end;
Here is my problem with this so far:
1. Though it calculates the retracement correctly, the rectangle is not showing. I want it to show from the vertical intersection of the swing point to the zone and extend out say 10-20 bars (user defined) - a manual example shown in Image attached.
2. The drawing does not remain on the chart. I would prefer to have it keep the history of drawings. At least 2 or three of the last ones (some user defined input).

Any help here would be amazing as I am at a road block here.

I have tried to add a Minus sign in front of the date and time but then it just shows a filled rectangle going back in time as opposed to what I want. E.g code:

Code: Select all

rectID = RectangleNew_s(CurrentDate, CurrentTime_s, retracement786Price, CurrentDate, CurrentTime_s, retracement618Price);
Thanks in advance for your help :)

Oh, screenshot for the image link is here: https://gyazo.com/6f29e94c24c46cded552e04f98ff078b (also attached file). And: https://gyazo.com/06ce2c5836fad973163631053a42c96e (second file attached).
MC_Post_FibTool_Ideal_Output.png
(29.32 KiB) Not downloaded yet
MC_Post_FibTool.png
(35.73 KiB) Not downloaded yet
MC_Post_FibTool.png
(35.73 KiB) Not downloaded yet
MC_Post_FibTool_Ideal_Output.png
(29.32 KiB) Not downloaded yet

svfutures24
Posts: 16
Joined: 19 Dec 2023
Has thanked: 1 time

Re: Mouse Clicks & Rectangles - Code Included - Please Help?  [SOLVED]

Postby svfutures24 » 15 Apr 2024

I am unsure how to mark this as resolved. I have managed to code my own tool for the purpose I was after. For anyone interested, using mouseclick events and drawing tools help. You can store data of the bar number, ohlc data, etc. and perform relevant calculations.


Return to “MultiCharts”