Login Page - Create Account

Support Board


Date/Time: Fri, 29 Mar 2024 02:10:25 +0000



Can I plot data from file into the future on a chart?

View Count: 2031

[2014-01-08 20:56:01]
WarEagle - Posts: 67
I created a data file in another program that contains a neural net type of forecast which goes into the future. I would like to plot this data on a chart so that I can see the forecast line to the end of the file (or at least to the end of the right hand margin of the chart). I am able to create a historical chart with the data file no problem. I am then able to use the Overlay indicator to add it to a regular chart. When I do this, the forecast data stops at the current bar time, with no plot into the future. I can also overlay the price chart onto the historical chart I created of the forecast. When I do this, the future plot of the forecast is there but the bar chart does not update unless I manually refresh it. I suppose this is because the main data of the chart, the forecast line, is not updating. I'll attach a picture that hopefully makes it clear.

Is there a solution that I am missing?

Thanks


Date Time Of Last Edit: 2014-01-08 20:58:00
imageplot_into_future.png / V - Attached On 2014-01-08 20:47:59 UTC - Size: 10.01 KB - 522 views
[2014-01-10 10:21:19]
Sierra Chart Engineering - Posts: 104368
You can do this using ACSIL.

Refer to this sc.Subgraph [] member:
http://www.sierrachart.com/index.php?l=doc/doc_ACSIL_Members_scSubgraph.html#scExtendedArrayElementsToGraph
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2014-01-10 10:21:30
[2014-01-12 17:29:25]
WarEagle - Posts: 67
After reading through the example code given in scsf_ExtendedArraySample you pointed me to, I am still not sure how to get data from another chart or file to plot in the future part of the array. In the example, they are taking data points (in this case an RSI) from previous bars in the same chart and shifting them forward. Since all they need to do is call an older array location this is pretty simple and I understand it.

Since I already have the forecast line in a chart I thought it might be simplest to copy the Price Overlay (single line) indicator code and add the extended array functionality. The problem I run in to is that I don't know how to reference the future bars from the chart that is being overlayed. I tried using the following code by trying to simply reference bars past sc.ArraySize by the number of bars I want to plot ahead, but that did not produce any values past the current bar on the chart.


ForecastOverlay.ExtendedArrayElementsToGraph = 50; //This is done in the sc.SetDefaults section

SCFloatArray PriceArray;
sc.GetChartArray(-ChartNumberToOverlay.GetChartNumber(), InputData.GetInputDataIndex(), PriceArray);
// ^^ Gets data from the chart being overlayed, in this case its the price forecast ^^
  
int TheirIndex = sc.GetNearestMatchForDateTimeIndex(ChartNumberToOverlay.GetChartNumber(), sc.Index);
ForecastOverlay[sc.Index] = PriceArray[TheirIndex];
// ^^ The above code matches the overlay up to the current bar just fine ^^

int NumberOfBarsToForwardPlot = ForecastOverlay.ExtendedArrayElementsToGraph;
if(sc.Index >= sc.ArraySize)  
  {
    for (int i = sc.ArraySize;i < sc.ArraySize + NumberOfBarsToForwardPlot ;i++)
    {  
      ForecastOverlay[i] = PriceArray[i];  
    }
  }
// ^^ This is the code I am using adapted from the scsf_ExtendedArraySample that seems to do nothing. ^^

What am I doing wrong?

Thanks as always!
[2014-01-13 21:20:08]
Sierra Chart Engineering - Posts: 104368
In the chart you are referencing, do the arrays contain data at and after PriceArray.GetArraySize()?

Since PriceArray can have a different size than the chart the study is applied to, you need to make sure you are referencing the proper indexes.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2014-01-13 21:20:29
[2014-01-13 21:51:04]
WarEagle - Posts: 67
Yes, I believe so. I am matching up the two chart's indexes with the sc.GetNearestMatchForDateTimeIndex function. The chart being referenced that has the forecast line in it goes past the current date and time more bars than the ExtendElementsToGraph value that I am adjusting the base chart by. Everything lines up correctly up to the current bar in the base chart.
imageOverlayChart.png / V - Attached On 2014-01-13 21:50:22 UTC - Size: 18.72 KB - 434 views
[2014-01-14 07:16:25]
Sierra Chart Engineering - Posts: 104368
Here is an example of drawing bars into the forward projection area:

http://www.sierrachart.com/image.php?l=1389683535406.png



SCSFExport scsf_ForwardProjectionBars(SCStudyInterfaceRef sc)
{
  SCSubgraphRef Open = sc.Subgraph[0];
  SCSubgraphRef High = sc.Subgraph[1];
  SCSubgraphRef Low = sc.Subgraph[2];
  SCSubgraphRef Last = sc.Subgraph[3];


  if (sc.SetDefaults)
  {
    // Set the configuration and defaults
    sc.FreeDLL = 0;

    sc.GraphName = "Forward Projection Bars";

    sc.AutoLoop = 1;
    sc.GraphRegion = 1;
    sc.GraphDrawType=GDT_OHLCBAR;

    Open.Name = "Open";
    Open.DrawStyle = DRAWSTYLE_LINE;
    Open.PrimaryColor = RGB(0,255,0);
    Open.DrawZeros = false;
     Open.ExtendedArrayElementsToGraph= 100;

    High.Name = "High";
    High.DrawStyle = DRAWSTYLE_LINE;
    High.PrimaryColor = RGB(0,255,0);
    High.DrawZeros = false;
    High.ExtendedArrayElementsToGraph= 100;

    Low.Name = "Low";
    Low.DrawStyle = DRAWSTYLE_LINE;
    Low.PrimaryColor = RGB(0,255,0);
    Low.DrawZeros = false;
    Low.ExtendedArrayElementsToGraph= 100;

    Last.Name = "Last";
    Last.DrawStyle = DRAWSTYLE_LINE;
    Last.PrimaryColor = RGB(0,255,0);
    Last.DrawZeros = false;
    Last.ExtendedArrayElementsToGraph= 100;


    return;
  }

  // Do data processing

  //Repeat last bar into forward projection area.
  if(sc.Index+1 >= sc.ArraySize)  
  {
    for (int Index = sc.ArraySize ; Index < sc.ArraySize + Open.ExtendedArrayElementsToGraph ; Index++)
    {  
      Open[Index] = sc.Open[sc.Index];
      High[Index] = sc. High[sc.Index];
      Low[Index] = sc. Low[sc.Index];
      Last[Index] = sc. Close[sc.Index];
    }
  }

  return;
}


The below code makes no consideration to the indexes to use for PriceArray [] that correspond with ForecastOverlay []. You will need to work out these details. We recommend looking at this page:
http://www.sierrachart.com/index.php?l=doc/doc_ACSILRefOtherTimeFrames.php

int NumberOfBarsToForwardPlot = ForecastOverlay.ExtendedArrayElementsToGraph;
if(sc.Index >= sc.ArraySize)
{
for (int i = sc.ArraySize;i < sc.ArraySize + NumberOfBarsToForwardPlot ;i++)
{
ForecastOverlay[i] = PriceArray[i];
}
}

Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2014-01-14 07:17:06
[2014-01-14 17:13:49]
WarEagle - Posts: 67
I just wanted to update this thread for users in the future facing a similar issue. I found my mistake thanks to your help.

First of all I was not even running the for loop at the end because I used

if(sc.Index >= sc.ArraySize)

instead of

if(sc.Index+1 >= sc.ArraySize)

so the loop was never entered. Once I fixed that, I still had the problem of not accessing the correct PriceArray value from the second chart. It was simply a matter of getting the correct index value from PriceArray[]. After several different ideas I figured it out:

if(sc.Index+1 >= sc.ArraySize)  
  {
    for (int i = sc.ArraySize;i < sc.ArraySize + NumberOfBarsToForwardShift ;i++)
    {  
      int PriceArrayShift = i - sc.ArraySize +1;
      ForecastOverlay[i] = PriceArray[TheirIndex + PriceArrayShift];
    }
  }

I just needed to start with the last known index value for PriceArray[] (when it was equal to sc.Index) and then add PriceArrayShift for each iteration of the plot forward to keep the indexes aligned.

Hope that helps in the future.

Thanks again SC!

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account