Below is a array sample:
Array:ABC[2];
ABC[0]=close[0];
ABC[1]=close[1];
ABC[2]=close[2];
May I use Array to get close price from close[0] to close[100]?
Should I type 100 times ABC[x]=close[x];?
Is there a easier way? Thanks.
Charles
Use Array to get close price from Close[0] to Close[100]
- TJ
- Posts: 7739
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1032 times
- Been thanked: 2221 times
Re: Use Array to get close price from Close[0] to Close[100]
Make a loop.Below is a array sample:
Array:ABC[2];
ABC[0]=close[0];
ABC[1]=close[1];
ABC[2]=close[2];
May I use Array to get close price from close[0] to close[100]?
Should I type 100 times ABC[x]=close[x];?
Is there a easier way? Thanks.
Charles
- TJ
- Posts: 7739
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1032 times
- Been thanked: 2221 times
-
- Posts: 401
- Joined: 19 Jan 2011
- Location: Netherlands
- Has thanked: 85 times
- Been thanked: 123 times
Re: Use Array to get close price from Close[0] to Close[100]
Maybe this code of an dynamic array can work for you. To get the amount of bars you want, set the chart on 100 bars back. Or use any other amount of bars you want.
In the PL editor you can see the result if you use the print_close_prices option.
In the PL editor you can see the result if you use the print_close_prices option.
Code: Select all
Inputs:// inputs print
Print_Close_prices(1);
Vars: // variabels
Close_of_bar(0),
Close_count(0),
Highest_Close(0),
Average_Close(0);
Arrays:// Bar price range array
Intrabarpersist Close_price_array[](0); // Dynamic array
If (barstatus(1) = 2) then begin
// price range array
If close <> close[1] then begin
Close_count = Close_count + 1;
end;
// expand the array by one
array_setmaxindex(Close_price_array, close_count);
// post data to array
Close_price_array[Close_count] = Close;
// send array data to variabels
Highest_Close = Highestarray(Close_price_array,Close_count); // use to get the highest close price.
Average_Close = AverageArray(Close_price_array,Close_count); // use to get the average bar range.
Close_of_bar = Close_price_array[Close_count]; // use to get the close of the bar
end;
// print statements
If Print_Close_prices = 1 then begin
If (barstatus(1)= 2) then begin
print("Date: ",formatdate("dd-MM-yyyy ",eldatetodatetime(date))," Time: ", FormatTime("HH:mm:ss", el_timetodatetime_s(time_s)),
" Close_price:",Close_of_bar," Highest:",Highest_Close," Average:",Average_Close);
end;
end;