When you run this you see that it doesn't go and check the previous barsBack. Is there any efficient way to do this? Thanks
#region Variables
// Wizard generated variables
private int totalBars = 100; // Total Bars to consider
private int barsBack = 3; // Number of bars back to compare to the actual bar
private int color = 1; // Not used for now
private bool considerBodypips = false; // Not used for now
int firstbar;
#endregion
/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
// Add(new Plot(Color.FromKnownColor(KnownColor.SkyBlue), PlotStyle.Line, "IndicatorLine"));
Overlay = true;
BarsRequired = barsBack;
}
protected override void OnBarUpdate()
{
if (CurrentBar < totalBars) return; // Check if Chart has enough bars.
int array = barsBack; //Create a variable for running thru previous bars to consider.
//Declaring the arrays
double[] opendata;
opendata = new double[array];
double[] bodysize ;
bodysize = new double[array];
double[] closedata;
closedata = new double[array];
//Calculate actual open - close
Print(CurrentBar);
double actualbodysize = Close[0] - Open[0];
Print(actualbodysize);
//Loop to go thru the previous barsBack
for (int y = 0; y < array; y++)
{
opendata[y] = Open[y];
closedata[y]= Close[y];
bodysize[y] = opendata[y] - closedata[y];
Print("");
Print(bodysize);
Print(opendata[y]);
Print(closedata[y]);
Print(bodysize[y]);
Print("");
}
Print("Fuera del loop");
IndicatorLine.Set(Close[0]);
}
Comment