# How to get contraction period of the stocks

My Needed logic is a below
Calculation the contraction Period of the stocks.
contraction Period is the period in which current stock price oscillate.
Example if I selected the Price Difference is 100 then I should get a period in which the price of high and low difference oscillate in 100.
I tried to code below. I only get lasted period.

How can I get array based period. So that I can get the historical value of contraction period.

Please provide some coding guidance in this regard.

Thanks
Ashok Meheta

``````//Simple Chart
Plot(C,"",colorDefault, GetPriceStyle());

High_Value = High[BarCount-1];
Low_Value = Low[BarCount-1];

Needed_Difference = Param("Price Difference", 100, 1, 500, 1);
Cal_Difference = High_Value - Low_Value;
Get_Period = 0;
Get_period_array = High_Value_Array = Low_Value_Array = Null;
In_Calculation =0;
for( i = BarCount-1; i >= 0; i--)
{

if(In_Calculation ==0 AND Cal_Difference[i] <= Needed_Difference)
{
In_Calculation = 1;

}

if(In_Calculation ==1)
{

if(High[i] > High_Value)
{
High_Value = High[i];
}

if(Low[i]  < Low_Value)
{
Low_Value = Low[i];
}

Cal_Difference = High_Value - Low_Value;

Get_Period++;

}

if(In_Calculation==1)
{
Get_period_array = Get_Period;
}

if(Cal_Difference[i] >= Needed_Difference)
{
In_Calculation = 0;

}
}

Get_High_Value = LastValue(HHV(High, Get_period_array-1));
Get_Low_Value = LastValue(LLV(Low, Get_period_array-1));

Get_High_Value = IIf(BarIndex()>=BarCount - Get_period_array, Get_High_Value, Null);
Get_Low_Value =IIf(BarIndex()>=BarCount - Get_period_array, Get_Low_Value, Null);

Plot(Get_High_Value,"\nHighest",colorGreen,styleDots);
Plot(Get_Low_Value,"\nLowlest",colorRed,styleDots);

Plot( Get_period_array-1, "\nGet_period_array", colorGreen, styleNoDraw|styleOwnScale|styleNoLabel|styleNoLine);

Filter_PriceColor = IIf(Close > Ref(Close, -1), colorGreen,
IIf(Close < Ref(Close, -1),colorRed,  colorDefault));

Filter=1 AND Get_period_array-1 > 23;
SetOption("Nodefaultcolumns", True );
AddTextColumn( Name(), "Name", 1.2,colorDefault, colorDefault, 90);
AddColumn( DateTime(), "Date", formatDateTime, colorDefault, colorDefault, 90);