I'm working on 1 minute barcharts.
I would like to:
1. plot a first vertical line on the chart by left clicking on a certain date and time
2. plot a second vertical line on the chart by left clicking on a certain date and time
3. calculate the number of bars between the two lines
4. dimension a dynamic array
5. store price data in the array
6. process and analyse the data
7. show results somewhere in some way.
Needless to say I'm stuck at point 1.
Please take a look at this code.
The original code, used to calculate % difference between two points, was found on the internet (thanks to maxmax68).
I tried to modify it as follow:
Code: Select all
Variables:
RecalcPersist Line1(0),
RecalcPersist Line2(0),
RecalcPersist LastBar(0),
RecalcPersist BarsAgo1(0),
RecalcPersist BarsAgo2(0),
RecalcPersist Date1(0),
RecalcPersist Date2(0),
RecalcPersist Time1(0),
RecalcPersist Time2(0),
RecalcPersist Price1(0),
RecalcPersist Price2(0),
RecalcPersist Price3(0),
RecalcPersist Price4(0),
RecalcPersist init(0),
RecalcPersist BarNumber1(0),
RecalcPersist BarNumber2(0);
if (LastBarOnChart) then begin
switch (GetAppInfo(aiCalcReason)) begin
// recalc for Left Mouse Click
case CalcReason_MouseLClick :
if (init = 0) and (BarNumber > 0) then begin
// Date1 = JulianToDate(MouseClickDateTime);
// Time1 = DateTime2elTime_s(MouseClickDateTime);
Price1 = GetAppInfo(aiLowestDispValue);
Price2 = GetAppInfo(aiHighestDispValue);
BarNumber1 = MouseClickBarNumber;
LastBar = BarNumber + MaxBarsBack;
BarsAgo1 = LastBar - BarNumber1;
Line1 = TL_New_BN(BarNumber1, Price1, BarNumber1, Price2);
TL_SetSize(Line1, 1);
TL_SetColor(Line1, RGB(051, 102, 255));
init = 1;
end
else if (init = 1) then begin
// Date2 = JulianToDate(MouseClickDateTime);
// Time2 = DateTime2elTime_s(MouseClickDateTime);
Price3 = GetAppInfo(aiLowestDispValue);
Price4 = GetAppInfo(aiHighestDispValue);
BarNumber2 = MouseClickBarNumber;
LastBar = BarNumber + MaxBarsBack;
BarsAgo2 = LastBar - BarNumber2;
Line2 = TL_New_BN(BarNumber2, Price3, BarNumber2, Price4);
TL_SetSize(Line2, 1);
TL_SetColor(Line2, RGB(051, 102, 255));
init = 0;
end;
end;
// The following code not modified yet:
// recalc for new tick arrived
{Case CalcReason_Default :
TL_Delete(value15);
value15 = Tl_New_s(date3, time3, price1, date4, time4, price2);
TL_SetSize(value15, 1);
TL_SetColor(value15, RGB(051, 102, 255));
end;}
end;
Code: Select all
a) with a bar spacing large enough (for me 3 or 5 pixels) I realize that if I click on a bar then the trend line is plotted six bars right;
b) if I want to plot a second trend line the first disappears. But I want them to stay there both, to delimit the area to analyse.
c) if I add the following code before the last end;
Code: Select all
Code: Select all
Any suggestion is sincerely appreciated.
Thanks in advance for your time.
Louis88