I'm lost on this one.
I'm experimenting with plotting a line from where my system gets into a trade, to where the current close price is, through concatenating a date and time string that I have pulled from a csv file.
I'm doing this;
start = StrToDateTime("12/22/2024 11:00:00");
finish = StrToDateTime("12/20/2024 10:00:00");
xo = Lookup(BarIndex(),start,0);
x1 = Lookup(BarIndex(), finish,0);
yo = 1;
y1 = 100;
line = LineArray(xo,yo,x1,y1,0,True);
Plot(line,"Line", colorBlack, styleLine|styleThick);
But I am not getting a line.
Can StrToDateTime take the format I have typed above? Can it take more than 1 date time string format and if so, will it automaticlaly recognise the date time string format I have used or will I need to specify it?
To create the line and then plot it, am I using the correct functions?
For LineArray() you are building a real Array with values in it. Is that required?
IF its just drawing a line, use gfx, like you only have 2 DateTime values and 2 price points.
First you need to check (_TRACE or debug) what values you get from StrToDateTime.
Officially supported format is ISO (YYYY-MM-DD HH:MM:SS), other formats might work IF and ONLY IF your Windows is set to recognize given region format.
Secondly, check for what Lookup returns (again _TRACE). If it returns NULL the exact date cannot be found (then you might want mode -1 that uses nearest predecesor)
Thirdly as @nsm51 wrote you - it would be easier to use GfxMoveTo/GfxLineTo/GfxSetCoordsMode to achieve easier (without Lookup).
Secondly, check for what Lookup returns (again _TRACE). If it returns NULL the exact date cannot be found (then you might want mode -1 that uses nearest predecesor)
You would save yourself a lot of trouble if your code was using -1 mode:
From here, It is easy enough to parse date and time strings to suit the format regardless of what my local copy of windows is doing with datetime strings and feed them into the above as a function.