I started by duplicating the CurrentDayOHL prebuilt and i added a custom function to send the data it works perfectly it sends the data with no problem, but the values it send are not the current values that are ploted on the screen.
I also noticed that it sends a lot of request to the api when i reload ninjaScript is it normal? doesn't need to only send the latest value?
And for the values i take them from the Values variable in the OnBarUpdate() function
I'm still new to coding indicators so it might be not the most efficient or the best way of doing this if you know another way i would be happy to hear the solution.
here is the function i use to send data:
static async Task sendDataAsync(Series<double> openV, Series<double> highV, Series<double> lowV)
{
var url = "https://link/to/my/server/api?";
if (openV[0] != 0 && highV[0] != 0 && lowV[0] != 0)
{
try
{
string postData = "open=" + Uri.EscapeDataString(openV[0].ToString().Replace(",", "."));
postData += "&high=" + Uri.EscapeDataString(highV[1].ToString().Replace(",", "."));
postData += "&low=" + Uri.EscapeDataString(lowV[2].ToString().Replace(",", "."));
var client = new HttpClient();
var content = await client.GetStringAsync(url + postData);
Console.WriteLine(content);
} catch (Exception ee) {
Console.WriteLine("Error: "+ee.ToString());
}
}
}
and here the OnBarUpdate where i use the function:
protected override void OnBarUpdate()
{
if (!Bars.BarsType.IsIntraday) return;
lastDate = currentDate;
currentDate = sessionIterator.GetTradingDay(Time[0]);
if (lastDate != currentDate || currentOpen == double.MinValue)
{
currentOpen = Open[0];
currentHigh = High[0];
currentLow = Low[0];
}
currentHigh = Math.Max(currentHigh, High[0]);
currentLow = Math.Min(currentLow, Low[0]);
if (ShowOpen)
CurrentOpen[0] = currentOpen;
if (ShowHigh)
CurrentHigh[0] = currentHigh;
if (ShowLow)
CurrentLow[0] = currentLow;
sendDataAsync(Values[0], Values[1], Values[2]); // here is where i call that function
}

Comment