get the high / low price for a period
get the high / low price for a period
22 Oct 2021, 11:30
Dear support team,
I came across the following question which I need to be pointed in the right direction:
I have a cBot running on Renko. After a trade is closed, I would like to know the maxHigh and minLow pips of that instrument during the lifetime of that trade.
The startdate/time and the closure date/time are known, but how do I get the both values for that period of time in Renko? And if its not solveable with Renko, can I implement something with multitimeframe which checks the desired values on m1 or something like that?
Kindest regards and have a great weekend,
Replies
firemyst
25 Oct 2021, 13:27
RE:
xabbu said:
thanl you very much, @firemyst, for your kind reply.
can you or the cTrader support team help me to understand, how I can implement this or a similar logic for m1 into a Renko cBot?
Kindest regards and a great and successful week,
I do not use Renko charts, so won't be able to help you there.
@firemyst
amusleh
26 Oct 2021, 09:22
( Updated at: 26 Oct 2021, 09:23 )
Hi,
Try this:
private double GetMax(DateTime startTime, DateTime endTime)
{
var startBarIndex = Bars.OpenTimes.GetIndexByTime(startTime);
var endBarIndex = Bars.OpenTimes.GetIndexByTime(endTime);
var max = double.MinValue;
for (var barIndex = startBarIndex; barIndex <= endBarIndex; barIndex++)
{
max = Math.Max(Bars.HighPrices[barIndex], max);
}
return max;
}
private double GetMin(DateTime startTime, DateTime endTime)
{
var startBarIndex = Bars.OpenTimes.GetIndexByTime(startTime);
var endBarIndex = Bars.OpenTimes.GetIndexByTime(endTime);
var min = double.MaxValue;
for (var barIndex = startBarIndex; barIndex <= endBarIndex; barIndex++)
{
min = Math.Min(Bars.LowPrices[barIndex], min);
}
return min;
}
This should work on all chart types as long as the data is available on your chart in between start and end time.
@amusleh
xabbu
26 Oct 2021, 11:25
Dear amusleh,
thank you for your kind support with my question and the code you have provided!
I have implemented it into my cBot and will run it - in my test it works as wanted.
Again, great support and great community here - appreciate it a lot!
Kindest regards to you and Panagiotis
@xabbu
firemyst
23 Oct 2021, 17:59
The following business logic should help with finding it on say a M1 chart:
1) get the index of the open time of the bar when the position was opened. Ex: Bars.OpenTimes.GetIndexByTime(position open time);
2) get the index of the bar in which the position was closed. Ex: Bars.OpenTimes.GetIndexByTime(position close time);
3) loop from start to finish, checking the high and low of every bar in between the open and close time indexes you obtained in steps 1 and 2 above
@firemyst