Page 1 of 1
what is the best way to parse a textfile or from Tmemo
Posted: Mon May 29, 2023 12:57 pm
by 16595372
Hi!
What is the best way to parse fields (for example) 2,3,4,5 for showing a candle chart.
The lines are originally in a Tmemo
Thanks for helping!
Re: what is the best way to parse a textfile or from Tmemo
Posted: Mon May 29, 2023 1:31 pm
by 16595372
1685311200, 4239,75, 4243,25, 4231,5, 4235,5, 4236,75, 6617, 2197
1685311500, 4235,75, 4237,5, 4232, 4233,25, 4234,6, 2521, 890
1685311800, 4233,25, 4234,5, 4231,5, 4232, 4233,3, 1517, 526
1685312100, 4232, 4233, 4230,25, 4232, 4231,5, 1568, 566
1685312400, 4232, 4235, 4231,5, 4233,5, 4233,525, 1154, 448
1685312700, 4233,75, 4234, 4232,25, 4233,5, 4233,1, 708, 294
1685313000, 4233,5, 4234,5, 4231,75, 4232, 4233,25, 808, 319
Re: what is the best way to parse a textfile or from Tmemo
Posted: Mon May 29, 2023 2:08 pm
by 16595372
SeriesTextSource?
Re: what is the best way to parse a textfile or from Tmemo
Posted: Mon May 29, 2023 3:59 pm
by 16595372
Import from memo.strings?
when using seriestext Tosource .. limitied to 2 fields"
When using TdbChart.. data is correct in text in Teechart but not in tdbchart.. see attached jpg
thanks ahead..
Re: what is the best way to parse a textfile or from Tmemo
Posted: Mon May 29, 2023 4:00 pm
by 16595372
I dont give input for name and data... only for pricefields
Re: what is the best way to parse a textfile or from Tmemo
Posted: Mon May 29, 2023 4:14 pm
by 16595372
Index Close High Low Open
0 0 0 0 0
1 0 4232 0 0
2 4232 0 0 0
3 4232 0 4233 4232
4 0 0 4235 4232
5 0 0 4234 0
6 4232 0 0 0
7 0 0 0 4232
8 4231 0 0 0
9 0 0 4231 4231
10 0 4
Re: what is the best way to parse a textfile or from Tmemo
Posted: Thu Jun 01, 2023 7:29 am
by yeray
Hello,
A couple of considerations:
- Those strings use the same character (comma
,
) both as
DecimalSeparator
and as
FieldSeparator
. You need to change one of them to be able to correctly identify values and fields.
I chose to modify the values from comma
,
to dot
.
:
Code: Select all
1685311200, 4239.75, 4243.25, 4231.5, 4235.5, 4236.75, 6617, 2197
1685311500, 4235.75, 4237.5, 4232, 4233.25, 4234.6, 2521, 890
1685311800, 4233.25, 4234.5, 4231.5, 4232, 4233.3, 1517, 526
1685312100, 4232, 4233, 4230.25, 4232, 4231.5, 1568, 566
1685312400, 4232, 4235, 4231.5, 4233.5, 4233.525, 1154, 448
1685312700, 4233.75, 4234, 4232.25, 4233.5, 4233.1, 708, 294
1685313000, 4233.5, 4234.5, 4231.75, 4232, 4233.25, 808, 319
- Those date values look strange. If I take one of them and I convert it to date I get 28605 as year:
Code: Select all
ShowMessage(DateTimeToStr(StrToFloat('1685311200'))); // -> 04/05/28605
After correcting those issues, you should be able to do something like this:
- Project3_2023-06-01_09-27-29.png (16.34 KiB) Viewed 27803 times
Code: Select all
var Series1: TCandleSeries;
procedure TForm1.FormCreate(Sender: TObject);
begin
Chart1.View3D:=False;
Chart1.Color:=clWhite;
Chart1.Gradient.Visible:=False;
Chart1.Walls.Back.Color:=clWhite;
Chart1.Walls.Back.Gradient.Visible:=False;
Memo1.WordWrap:=False;
FormatSettings.DecimalSeparator:='.';
Series1:=TCandleSeries(Chart1.AddSeries(TCandleSeries));
with Series1 do
begin
DownCloseColor:=1330417;
UpCloseColor:=6519581;
end;
With SeriesTextSource1 do
begin
Series:=Series1;
HeaderLines:=0;
FieldSeparator:=',';
Fields.Clear;
AddField('Date',1).OnGetValue:=DateGetValue;
AddField('High',2);
AddField('Low',3);
AddField('Open',4);
AddField('Close',5);
LoadFromStrings(Memo1.Lines);
end;
end;
procedure TForm1.DateGetValue(Field:TSeriesTextField; const Text:string; var Value:Double);
begin
//Value:=StrToFloat(Text); // -> Correct Date from text
Value:=IncDay(Today, Series1.Count); // I'm using this as alternative to the above
Series1.NotMandatoryValueList.TempValue:=Value;
end;