Argument types problem ('float', 'const int') in array - arrays

I've been trying my first codes in pine script. The question is this. I have created few array.new_float to use as buffers in the 'for' statement. The thing is that I need to do some math over the data. Now, once the 'for' is done, an error pops: 'Cannot call 'operator -' with argument 'expr0' = 'High'.An argument of 'float[]' type was used but a 'const int' is expected'.
Please, if anyone knows what am I doing wrong, I will thank you.
Edit: I will leave the script of what I'm trying to do here
//#version=5
// Indicator name
indicator("DAF_Swing_Index", shorttitle= 'DAF_SwInd', overlay=false)
// Input
T = input.int(30000, title = 'Ratio de escala', minval = 1000, maxval = 150000)
Shift = input.int(0, title = 'Desplazamiento horizontal', minval = 0, maxval = 100)
// Array
SWINGINDEX = array.new_float(200)
Open = array.new_float(200)
Open1 = array.new_float(200)
Close = array.new_float(200)
Close1 = array.new_float(200)
High = array.new_float(200)
Low = array.new_float(200)
// Other variable
var float SwingIndex = 0
var int StartBars = 1
Prev_calculated = bar_index
Rates_total = bar_index + 1
var float SH1 = 0
var float SI = 0
var float R = 0
// Initial bar verification
if Rates_total < StartBars
SwingIndex := 0
Primero = 1
if Prev_calculated > Rates_total or Prev_calculated <= 0
Primero := 1
else
Primero := Prev_calculated-1
// Main process
for bar = Primero to Rates_total
array.push(Open, high[bar])
array.push(Open1, open[bar-1])
array.push(Close, close[bar])
array.push(Close1, close[bar-1])
array.push(High, high[bar])
array.push(Low, low[bar])
K = math.max(math.abs(High - Close1), math.abs(Low - Close1))
TR = math.max(math.max(math.abs(High-Close1), math.abs(Low-Close1)), math.abs(High-Low))
ER = 0.0
if Close1 > High
ER := math.abs(High - Close1)
if Close1 < Low
ER := math.abs(Low - Close1)
SH1 := math.abs(Close1 - Open1)
R := TR - 0.5 * ER + 0.25 * SH1
SI := 0.0
if R != 0
SI := 50 * ((Close - Close1) + 0.5 * (Close - Open1)) * (K / T) / R
SwingIndex := SI
// ploting result
plot(SwingIndex, title = 'Swing Index', style = plot.style_line, color = color.rgb(193, 255, 51, 10))

So, what the error message tells you is, your are passing an array, where it expects a const value.
Like here:
K = math.max(math.abs(High - Close1), math.abs(Low - Close1))
All those variables (High, Close1, Low) are arrays. It simply can not subtract one array from another. You can however, subtract one element from another element.
So for that line, I believe you want something like this:
K = math.max(math.abs(array.get(High, bar) - array.get(Close1, bar)), math.abs(array.get(Low, bar) - array.get(Close1, bar)))
With array.get(), you can get value the of the element at the specified index.
You should fix this in all other occurences.

Related

Make strategy with arrays in Pine

I'm trying to make a strategy of an indicator, but I get the error: Line 73: Cannot call 'operator >' with argument 'expr0'='call 'alertcondition' (void)'. An argument of 'void' type was used but a 'const float' is expected. How can I change the code to get a correct boolean if statement for the trade entry? I'm very new to pine, hopefully someone can help me.
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo
//#version=5
// Umgeschrieben von JSt
strategy("Watson Strategie Nadaraya-Watson Envelope [JSt]",overlay=true,max_bars_back=1000,max_lines_count=500,max_labels_count=500)
length = input.float(500,'Window Size',maxval=500,minval=0)
h = input.float(8.,'Bandwidth')
mult = input.float(3.)
src = input.source(close,'Source')
up_col = input.color(#39ff14,'Colors',inline='col')
dn_col = input.color(#ff1100,'',inline='col')
//----
n = bar_index
var k = 2
var upper = array.new_line(0)
var lower = array.new_line(0)
lset(l,x1,y1,x2,y2,col)=>
line.set_xy1(l,x1,y1)
line.set_xy2(l,x2,y2)
line.set_color(l,col)
line.set_width(l,2)
if barstate.isfirst
for i = 0 to length/k-1
array.push(upper,line.new(na,na,na,na))
array.push(lower,line.new(na,na,na,na))
//----
line up = na
line dn = na
//----
cross_up = 0.
cross_dn = 0.
if barstate.islast
y = array.new_float(0)
sum_e = 0.
for i = 0 to length-1
sum = 0.
sumw = 0.
for j = 0 to length-1
w = math.exp(-(math.pow(i-j,2)/(h*h*2)))
sum += src[j]*w
sumw += w
y2 = sum/sumw
sum_e += math.abs(src[i] - y2)
array.push(y,y2)
mae = sum_e/length*mult
for i = 1 to length-1
y2 = array.get(y,i)
y1 = array.get(y,i-1)
up := array.get(upper,i/k)
dn := array.get(lower,i/k)
lset(up,n-i+1,y1 + mae,n-i,y2 + mae,up_col)
lset(dn,n-i+1,y1 - mae,n-i,y2 - mae,dn_col)
if src[i] > y1 + mae and src[i+1] < y1 + mae
label.new(n-i,src[i],'▼',color=#00000000,style=label.style_label_down,textcolor=dn_col,textalign=text.align_center)
if src[i] < y1 - mae and src[i+1] > y1 - mae
label.new(n-i,src[i],'▲',color=#00000000,style=label.style_label_up,textcolor=up_col,textalign=text.align_center)
cross_up := array.get(y,0) + mae
cross_dn := array.get(y,0) - mae
// TestUP = ta.crossover(src,cross_up) > 0
alertcondition(ta.crossover(src,cross_up),'Down','Down')
alertcondition(ta.crossunder(src,cross_dn),'Up','Up')
//---- Alarm für Webhook -----
plot(cross_up, color=#000000, transp=100) //Für den Alert, jedoch Darstellungsfehler → Transparent
plot(cross_dn, color=#000000, transp=100)
plotchar(cross_up, title="cross_up%", char="", location=location.top, color = color.green) // Damit der Wert in der Statusleiste dargestellt wird
plotchar(cross_dn, title="cross_dn%", char="", location=location.top, color = color.red)
//-------------------
// Start Date
// STEP 1. Create inputs that configure the backtest's date range
useDateFilter = input.bool(true, title="Begin Backtest at Start Date",
group="Backtest Time Period")
backtestStartDate = input.time(timestamp("1 Jan 2021"),
title="Start Date", group="Backtest Time Period",
tooltip="This start date is in the time zone of the exchange " +
"where the chart's instrument trades. It doesn't use the time " +
"zone of the chart or of your computer.")
// STEP 2. See if current bar happens on, or later than, the start date
inTradeWindow = not useDateFilter or time >= backtestStartDate
// ---------------
// Enter a long position when the entry rule is triggered
if inTradeWindow and ta.crossover(src,cross_up) > 0
strategy.entry('Long', strategy.long)
// Exit the Long position when the exit rule is triggered
if close > strategy.position_avg_price + 50
strategy.close("Long", comment = "TP")
else if close < strategy.position_avg_price - 50
strategy.close("Long", comment = "SL")
I tried the ta.crossover(src,cross_up) to compare it to zero, but it doesn't work.
ta.crossover() returns a bool value.
ta.crossover(source1, source2) → series bool
So, comparing its return value with some number does not make any sense and the compiler will complain: ta.crossover(src,cross_up) > 0.
You should just do:
if inTradeWindow and ta.crossover(src,cross_up)
strategy.entry('Long', strategy.long)

how to debug arrays values in pinescript?

I have this script:
strategy("My strategy")
var float start_price = na
var float end_price = na
var float[] start_prices = array.new_float(0)
var float[] end_prices = array.new_float(0)
var float p = na
f(x) => math.round(x / 500) * 500
lo = (high + close) / 2
var i = 0
if bar_index == 1
start_price := f(lo)
end_price := f(start_price * 1.015)
else
if close <= start_price
strategy.entry(str.format("Long {0}",i), strategy.long)
array.push(end_prices, end_price)
array.push(start_prices, end_price)
i := i + 1
start_price := start_price - 500
end_price := f(start_price * 1.015)
for j = 0 to (array.size(end_prices) == 0 ? na : array.size(end_prices) - 1)
p := array.get(end_prices, j)
if close >= p
strategy.exit(str.format("Long {0}",j), limit=end_price)
I want to console/debug/display the values in start_prices array
But I can't figure out for the life of me how to do that, there's no console.log or anything like that. I'm a somewhat competent python programmer, but I always use the print()... Anyway, how do people debug in this language?
You can use the tostring() function (str.tostring() in v5) to generate a string of your array. You can then output it into a label or table.
eg.
start_prices_string = str.tostring(start_prices)
debug = label.new(x = bar_index, y = close, style = label.style_label_left, text = start_prices_string)
label.delete(debug[1])

Matlab : How to highlight GLYCINE residues in my Ramachandran plot? [duplicate]

This question already has an answer here:
MATLAB : What is the mistake in my Ramachandran plot?
(1 answer)
Closed 8 years ago.
I am trying matlab to plot ramachandran plot, without using built in command. I have succeeded too. Now I wanted to spot the GLYCINEs alone in the scatter array. Any ideas how to do this? (link to 1UBQ.pdb file : http://www.rcsb.org/pdb/download/downloadFile.do?fileFormat=pdb&compression=NO&structureId=1UBQ)
% Program to plot Ramanchandran plot of Ubiquitin
close all; clear ; clc; % close all figure windows, clear variables, clear screen
pdb1 ='/home/devanandt/Documents/VMD/1UBQ.pdb';
p=pdbread(pdb1); % read pdb file corresponding to ubiquitin protein
atom={p.Model.Atom.AtomName};
n_i=find(strcmp(atom,'N')); % Find indices of atoms
ca_i=find(strcmp(atom,'CA'));
c_i=find(strcmp(atom,'C'));
X = [p.Model.Atom.X];
Y = [p.Model.Atom.Y];
Z = [p.Model.Atom.Z];
X_n = X(n_i(2:end)); % X Y Z coordinates of atoms
Y_n = Y(n_i(2:end));
Z_n = Z(n_i(2:end));
X_ca = X(ca_i(2:end));
Y_ca = Y(ca_i(2:end));
Z_ca = Z(ca_i(2:end));
X_c = X(c_i(2:end));
Y_c = Y(c_i(2:end));
Z_c = Z(c_i(2:end));
X_c_ = X(c_i(1:end-1)); % the n-1 th C (C of cabonyl)
Y_c_ = Y(c_i(1:end-1));
Z_c_ = Z(c_i(1:end-1));
V_c_ = [X_c_' Y_c_' Z_c_'];
V_n = [X_n' Y_n' Z_n'];
V_ca = [X_ca' Y_ca' Z_ca'];
V_c = [X_c' Y_c' Z_c'];
V_ab = V_n - V_c_;
V_bc = V_ca - V_n;
V_cd = V_c - V_ca;
phi=0;
for k=1:numel(X_c)
n1=cross(V_ab(k,:),V_bc(k,:))/norm(cross(V_ab(k,:),V_bc(k,:)));
n2=cross(V_bc(k,:),V_cd(k,:))/norm(cross(V_bc(k,:),V_cd(k,:)));
x=dot(n1,n2);
m1=cross(n1,(V_bc(k,:)/norm(V_bc(k,:))));
y=dot(m1,n2);
phi=cat(2,phi,-atan2d(y,x));
end
phi=phi(1,2:end);
X_n_ = X(n_i(2:end)); % (n+1) nitrogens
Y_n_ = Y(n_i(2:end));
Z_n_ = Z(n_i(2:end));
X_ca = X(ca_i(1:end-1));
Y_ca = Y(ca_i(1:end-1));
Z_ca = Z(ca_i(1:end-1));
X_n = X(n_i(1:end-1));
Y_n = Y(n_i(1:end-1));
Z_n = Z(n_i(1:end-1));
X_c = X(c_i(1:end-1));
Y_c = Y(c_i(1:end-1));
Z_c = Z(c_i(1:end-1));
V_n_ = [X_n_' Y_n_' Z_n_'];
V_n = [X_n' Y_n' Z_n'];
V_ca = [X_ca' Y_ca' Z_ca'];
V_c = [X_c' Y_c' Z_c'];
V_ab = V_ca - V_n;
V_bc = V_c - V_ca;
V_cd = V_n_ - V_c;
psi=0;
for k=1:numel(X_c)
n1=cross(V_ab(k,:),V_bc(k,:))/norm(cross(V_ab(k,:),V_bc(k,:)));
n2=cross(V_bc(k,:),V_cd(k,:))/norm(cross(V_bc(k,:),V_cd(k,:)));
x=dot(n1,n2);
m1=cross(n1,(V_bc(k,:)/norm(V_bc(k,:))));
y=dot(m1,n2);
psi=cat(2,psi,-atan2d(y,x));
end
psi=psi(1,2:end);
scatter(phi,psi)
box on
axis([-180 180 -180 180])
title('Ramachandran Plot for Ubiquitn Protein','FontSize',16)
xlabel('\Phi^o','FontSize',20)
ylabel('\Psi^o','FontSize',20)
grid
The output is :
EDIT : Is my plot correct? Biopython: How to avoid particular amino acid sequences from a protein so as to plot Ramachandran plot? has an answer which has slightly different plot.
The modified code is as below :
% Program to plot Ramanchandran plot of Ubiquitin with no glycines
close all; clear ; clc; % close all figure windows, clear variables, clear screen
pdb1 ='/home/devanandt/Documents/VMD/1UBQ.pdb';
p=pdbread(pdb1); % read pdb file corresponding to ubiquitin protein
atom={p.Model.Atom.AtomName};
n_i=find(strcmp(atom,'N')); % Find indices of atoms
ca_i=find(strcmp(atom,'CA'));
c_i=find(strcmp(atom,'C'));
X = [p.Model.Atom.X];
Y = [p.Model.Atom.Y];
Z = [p.Model.Atom.Z];
X_n = X(n_i(2:end)); % X Y Z coordinates of atoms
Y_n = Y(n_i(2:end));
Z_n = Z(n_i(2:end));
X_ca = X(ca_i(2:end));
Y_ca = Y(ca_i(2:end));
Z_ca = Z(ca_i(2:end));
X_c = X(c_i(2:end));
Y_c = Y(c_i(2:end));
Z_c = Z(c_i(2:end));
X_c_ = X(c_i(1:end-1)); % the n-1 th C (C of cabonyl)
Y_c_ = Y(c_i(1:end-1));
Z_c_ = Z(c_i(1:end-1));
V_c_ = [X_c_' Y_c_' Z_c_'];
V_n = [X_n' Y_n' Z_n'];
V_ca = [X_ca' Y_ca' Z_ca'];
V_c = [X_c' Y_c' Z_c'];
V_ab = V_n - V_c_;
V_bc = V_ca - V_n;
V_cd = V_c - V_ca;
phi=0;
for k=1:numel(X_c)
n1=cross(V_ab(k,:),V_bc(k,:))/norm(cross(V_ab(k,:),V_bc(k,:)));
n2=cross(V_bc(k,:),V_cd(k,:))/norm(cross(V_bc(k,:),V_cd(k,:)));
x=dot(n1,n2);
m1=cross(n1,(V_bc(k,:)/norm(V_bc(k,:))));
y=dot(m1,n2);
phi=cat(2,phi,-atan2d(y,x));
end
phi=phi(1,2:end);
X_n_ = X(n_i(2:end)); % (n+1) nitrogens
Y_n_ = Y(n_i(2:end));
Z_n_ = Z(n_i(2:end));
X_ca = X(ca_i(1:end-1));
Y_ca = Y(ca_i(1:end-1));
Z_ca = Z(ca_i(1:end-1));
X_n = X(n_i(1:end-1));
Y_n = Y(n_i(1:end-1));
Z_n = Z(n_i(1:end-1));
X_c = X(c_i(1:end-1));
Y_c = Y(c_i(1:end-1));
Z_c = Z(c_i(1:end-1));
V_n_ = [X_n_' Y_n_' Z_n_'];
V_n = [X_n' Y_n' Z_n'];
V_ca = [X_ca' Y_ca' Z_ca'];
V_c = [X_c' Y_c' Z_c'];
V_ab = V_ca - V_n;
V_bc = V_c - V_ca;
V_cd = V_n_ - V_c;
psi=0;
for k=1:numel(X_c)
n1=cross(V_ab(k,:),V_bc(k,:))/norm(cross(V_ab(k,:),V_bc(k,:)));
n2=cross(V_bc(k,:),V_cd(k,:))/norm(cross(V_bc(k,:),V_cd(k,:)));
x=dot(n1,n2);
m1=cross(n1,(V_bc(k,:)/norm(V_bc(k,:))));
y=dot(m1,n2);
psi=cat(2,psi,-atan2d(y,x));
end
psi=psi(1,2:end);
res=strsplit(p.Sequence.ResidueNames,' ');
angle =[phi;psi];
angle(:,find(strcmp(res,'GLY'))-1)=[];
scatter(angle(1,:),angle(2,:))
box on
axis([-180 180 -180 180])
title('Ramachandran Plot for Ubiquitn Protein','FontSize',16)
xlabel('\Phi^o','FontSize',20)
ylabel('\Psi^o','FontSize',20)
grid
which gives output (with no GLY) as below :
I would change this code block to use logical indexing
res=strsplit(p.Sequence.ResidueNames,' ');
angle =[phi;psi];
angle(:,find(strcmp(res,'GLY'))-1)=[];
Instead:
residues = strsplit(p.Sequency.ResidueNames,' ');
glycine = ismember(residues,'GLY');
angle = [phi;psi];
angleNoGLY= angle(:,~glycine);
Doing it this way, if you wanted to highlight glycine (or any other residue) you can easily call it out:
angleGLY = angle(:,glycine);
plot(angleNoGLY(1,:),angleNoGLY(2,:),'ob')
line(angleGLY(1,:),angleGLY(2,:),'Marker','o','Color','r','LineStyle','none')

Matlab: stepping through an array and incrementing from one value to the next

I have an array:
step1 = [0,0;
0,1;
1,1;
2,3;
3,4;
3,5;
3,6;
3,7;
4,7;
5,7;
6,7;
6,6;
6,5;
6,4;
6,3;
6,2;
5,1];
I want to step through this array and create new arrays for the row and column that increment by 0.1 from one row to another. This is what I did:
z=1;
u=length(step1);
step_b4X = zeros(u,1);
step_b4Y = zeros(u,1);
while z <= length(step1)
step_b4X = step_presentX;
step_presentX(z,1) = step1(z,1);
step_b4Y = step_presentX;
step_presentY(z,1) = step1(z,2);
pathX = step_b4X:0.1:step_presentX;
pathY = step_b4Y:0.1:step_presentY;
z = z+1;
end
I get zeros.
I want pathX = 0:0.1:0....pathY = 0:0.1:1
next pathX = 0:0.1:1....pathY = 1:0.1:1... and so on
If you do
start:increment:end
where start == end, you'll get a scalar equal to start (which is logical).
If you want pathX and pathY to have the same length at each iteration, you'll have to do this:
z = 1;
while z <= length(step1)
currentX = step(z,1); nextX = step(z+1,1);
currentY = step(z,2); nextY = step(z+1,2);
pathX = currentX : 0.1 : nextX;
pathY = currentY : 0.1 : nextY;
if numel(pathX) == 1
pathX = repmat(pathX, numel(pathY),1); end
if numel(pathY) == 1
pathY = repmat(pathY, numel(pathX),1); end
z = z+1;
end
Now you'll have the right arrays at each iteration, that you'll use directly or save in a cell-array for later. If you want everything in one big array, add this to the end of the loop:
pathX_final = [pathX_final; pathX];
pathY_final = [pathY_final; pathY];
and initialize them as empty before the loop, of course.
Alternatively (much cleaner and possibly a bit faster), ditch the whole loop and use interp1:
x = step1(:,1);
y = step1(:,2);
xx = interp1(1:numel(x), x, 1:0.1:numel(x));
yy = interp1(1:numel(y), y, 1:0.1:numel(y));

Array subscript out of bouds in an IF statement

Below is a section for my code.
The user inputs a value for Energy, if the value is on the array ARRDAT(1,x), then I want it to assign the related variables ARRDAT(2,x), ARRDAT(3,x), and ARRDAT(4,x).
If the data is not on the array, I will interpolate (note: only values between two of my given points will be inputted).
I am able to compile it with a warning
warning 179 - Comparning floating point quantities for equality may give misleading results
and as soon as I input any value, whether it's in the table or not I get
error 11, array subscript(s) out of bounds
The error occurs on the line
IF (ARRDAT(1,x) == Energy) THEN
I haven't been able to fix it.
IMPLICIT NONE
REAL :: Dose, Energy, Source, FeAtt, PbAtt, Resp, Distance, Mu, Thickness
INTEGER :: x, y, upp, low
CHARACTER(LEN=4) :: Material
REAL, PARAMETER :: PI = 3.1415926
real, dimension(1:4,1:25) :: ARRDAT
!Energy MeV
ARRDAT(1,1) = 0.01
ARRDAT(1,2) = 0.015
ARRDAT(1,3) = 0.02
ARRDAT(1,4) = 0.03
ARRDAT(1,5) = 0.04
ARRDAT(1,6) = 0.05
ARRDAT(1,7) = 0.06
ARRDAT(1,8) = 0.08
ARRDAT(1,9) = 0.10
ARRDAT(1,10) = 0.15
ARRDAT(1,11) = 0.20
ARRDAT(1,12) = 0.30
ARRDAT(1,13) = 0.40
ARRDAT(1,14) = 0.50
ARRDAT(1,15) = 0.60
ARRDAT(1,16) = 0.80
ARRDAT(1,17) = 1.0
ARRDAT(1,18) = 1.5
ARRDAT(1,19) = 2.0
ARRDAT(1,20) = 3.0
ARRDAT(1,21) = 4.0
ARRDAT(1,22) = 5.0
ARRDAT(1,23) = 6.0
ARRDAT(1,24) = 8.0
ARRDAT(1,25) = 10.0
!Response Function Sv*cm2
ARRDAT(2,1) = 0.062
ARRDAT(2,2) = 0.157
ARRDAT(2,3) = 0.238
ARRDAT(2,4) = 0.329
ARRDAT(2,5) = 0.365
ARRDAT(2,6) = 0.384
ARRDAT(2,7) = 0.400
ARRDAT(2,8) = 0.451
ARRDAT(2,9) = 0.533
ARRDAT(2,10) = 0.777
ARRDAT(2,11) = 1.03
ARRDAT(2,12) = 1.56
ARRDAT(2,13) = 2.06
ARRDAT(2,14) = 2.54
ARRDAT(2,15) = 2.99
ARRDAT(2,16) = 3.83
ARRDAT(2,17) = 4.60
ARRDAT(2,18) = 6.24
ARRDAT(2,19) = 7.66
ARRDAT(2,20) = 10.2
ARRDAT(2,21) = 12.5
ARRDAT(2,22) = 14.7
ARRDAT(2,23) = 16.7
ARRDAT(2,24) = 20.8
ARRDAT(2,25) = 24.7
!mu/rho for iron cm2/g
ARRDAT(3,1) = 169.4
ARRDAT(3,2) = 56.33
ARRDAT(3,3) = 25.16
ARRDAT(3,4) = 7.891
ARRDAT(3,5) = 3.450
ARRDAT(3,6) = 1.833
ARRDAT(3,7) = 1.113
ARRDAT(3,8) = 0.5391
ARRDAT(3,9) = 0.3340
ARRDAT(3,10) = 0.1786
ARRDAT(3,11) = 0.1357
ARRDAT(3,12) = 0.1051
ARRDAT(3,13) = 0.09131
ARRDAT(3,14) = 0.08241
ARRDAT(3,15) = 0.07583
ARRDAT(3,16) = 0.06631
ARRDAT(3,17) = 0.05951
ARRDAT(3,18) = 0.04863
ARRDAT(3,19) = 0.04254
ARRDAT(3,20) = 0.03616
ARRDAT(3,21) = 0.03309
ARRDAT(3,22) = 0.03144
ARRDAT(3,23) = 0.03056
ARRDAT(3,24) = 0.02991
ARRDAT(3,25) = 0.02994
!mu/rho for lead cm2/g
ARRDAT(4,1) = 125.7
ARRDAT(4,2) = 108.3
ARRDAT(4,3) = 84.02
ARRDAT(4,4) = 28.94
ARRDAT(4,5) = 13.44
ARRDAT(4,6) = 7.386
ARRDAT(4,7) = 4.531
ARRDAT(4,8) = 2.112
ARRDAT(4,9) = 5.337
ARRDAT(4,10) = 1.910
ARRDAT(4,11) = 0.9359
ARRDAT(4,12) = 0.3732
ARRDAT(4,13) = 0.2148
ARRDAT(4,14) = 0.1499
ARRDAT(4,15) = 0.1167
ARRDAT(4,16) = 0.08408
ARRDAT(4,17) = 0.06803
ARRDAT(4,18) = 0.05087
ARRDAT(4,19) = 0.04530
ARRDAT(4,20) = 0.04200
ARRDAT(4,21) = 0.04178
ARRDAT(4,22) = 0.04260
ARRDAT(4,23) = 0.04382
ARRDAT(4,24) = 0.04670
ARRDAT(4,25) = 0.04969
WRITE(*,*) 'Please input the particle energy in MeV'
READ(*,*) Energy
x=0
DO x = 0, 25, 1
IF (ARRDAT(1,x) == Energy) THEN !if the data is already on our table
ARRDAT(2,x) = Resp
ARRDAT(3,x) = FeAtt
ARRDAT(4,x) = PbAtt
WRITE(*,*) 'CHECK 1'
ELSE IF (ARRDAT(1,x) < Energy) THEN !if the data is between two points
upp = x
low = x - 1
Energy = ((ARRDAT(1,upp) + ARRDAT(1,low))/2)
WRITE(*,*) Energy
ELSE
WRITE(*,*) 'Invalid Entry'
END IF
END DO
You declare your array to be 1-indexed with real, dimension(1:4,1:25) :: ARRDAT, but your DO loop begins with x = 0, so the first iteration of the loop looks for ARRDAT(1,0) == Energy, which is out of bounds. Start your DO loop with x = 1 and you should be fine.
Side note: Fortran automatically indexes arrays beginning with 1, so you can declare your array as real, dimension(4,25) :: ARRDAT, and it will have the same effect.
EDIT: As mentioned by #user5713492 in the comments, this code will still crash if the input Energy is greater than ARRDAT(1,1). You will either have to fix the lower bound of the linear interpolation or skip the interpolation entirely in the first iteration of the loop. For example:
DO x = 1, 25
IF (ARRDAT(1,x) == Energy) THEN
! ...
ELSE IF (ARRDAT(1,x) < Energy) THEN
upp = x
low = x - 1
IF (low < 1) low = 1 ! <-- make sure we don't go out of bounds on the array
! ...
END IF
END DO
... or ...
DO x = 1, 25
IF (ARRDAT(1,x) == Energy) THEN
! ...
ELSE IF (x > 1 .AND. ARRDAT(1,x) < Energy) THEN ! <-- don't interpolate for the first iteration
! ...
END IF
END DO
Now, about that warning concerning comparison of floating point numbers for equality: please read this and try to avoid ==, >=, and <= operators when comparing reals.

Resources