# Understanding of code

Hi, i recently paid someone to code me an EA. Can someone please assist me with understand the following lines.

Based on other indicators as well as the Moving Average, this function is used to work out how many of the current open positions should be closed based on how well the trade is currently meeting the TP criteria, eg 80 RSI would make it very overbought so (based on other indicators too) it would likely close most of the open positions.

I understand most of the code aside from the lines with ??? in the comments and how the tradeDirection  dynamic array is used. Bonus question is this the best use of the array ? surely there are simplier ways to make it work eg the same array with values 1 & -1 to clearly identify buying or selling.

I appreciate the help in advance!

```double getTP_Score()
{
bool a1= CopyBuffer(BB_handle1,0,0,2,BB1_Array);
bool a2= CopyBuffer(BB_handle2,0,0,2,BB2_Array);
bool a3= CopyBuffer(RSI_handle,0,0,2,RSI_Array);
bool a4= CopyBuffer(Stochastic_handle,0,0,2,Stochastic_Array);
bool a5= CopyBuffer(MFI_handle,0,0,2,MFI_Array);
bool a6= CopyBuffer(MA_handle,0,0,2,MA_Array);
bool a7= CopyBuffer(KAMA_handle,0,0,2,KAMA_Array);
bool a8= CopyBuffer(Aroon_handle,0,0,2,Aroon_Array);
bool a9= CopyBuffer(ER_handle,0,0,2,ER_Array);

double sum_of_indicator_risk_values=0;
int number_of_indicators=0;
double sum_of_indicator_risk_valuesTP=0;

int number_of_indicatorsTP=0;

if(MA_Entry_Requirement)                                                                    //if met, following of 4 conditions can be executed
{
double risk_value;
double X=MA_Array[1];

if(X>MA_Highest_ValueSell)
{
risk_value=1;                                                                          //Value > highest sell value

if(MA_Take_Profit_Requirement)
{
number_of_indicatorsTP++;                                                           //increase TP number of indicators
sum_of_indicator_risk_valuesTP+=risk_value;                                         //???????????????????????????????????????????
}
}
else
if(X<MA_Highest_ValueSell&&X>MA_Smallest_ValueSell)                                    //Value within Selling range
{
risk_value=(X-MA_Smallest_ValueSell)/(MA_Highest_ValueSell-MA_Smallest_ValueSell);  //Within range calculation

if(MA_Take_Profit_Requirement)
{
number_of_indicatorsTP++;
sum_of_indicator_risk_valuesTP+=risk_value;
}
}
else
{
risk_value=1;

if(MA_Take_Profit_Requirement)
{
number_of_indicatorsTP++;
sum_of_indicator_risk_valuesTP+=risk_value;
}
}
else
{

if(MA_Take_Profit_Requirement)
{
number_of_indicatorsTP++;
sum_of_indicator_risk_valuesTP+=risk_value;
}
}
else
{
}
}
}

```

luccc:

Hi, i recently paid someone to code me an EA. Can someone please assist me with understand the following lines.

Based on other indicators as well as the Moving Average, this function is used to work out how many of the current open positions should be closed based on how well the trade is currently meeting the TP criteria, eg 80 RSI would make it very overbought so (based on other indicators too) it would likely close most of the open positions.

I understand most of the code aside from the lines with ??? in the comments and how the tradeDirection  dynamic array is used. Bonus question is this the best use of the array ? surely there are simplier ways to make it work eg the same array with values 1 & -1 to clearly identify buying or selling.

I appreciate the help in advance!

This line
`      ArrayResize(tradeDirection,ArraySize(tradeDirection)+1,0);  `
will add an element to the array at the end, increasing the size by one.

This line
`sum_of_indicator_risk_valuesTP+=risk_value;     `
will add the value "risk_value" to the value in "sum_of_indicator_risk_valuesTP" and store the result in that variable.

It is rather unclear what this code is supposed to do, seems to me, there are some missing parts. The initial boolvaliables are obviously not checked.

It looks like, you are adding conditions up to meet or surpass a threshold to conclude a closing signal. - I know, you stated that, but it is overall rather hard to tell the whole logic just by one function.

Also the global variables are not present, it is very out of context.

Dominik Egert #:
This line
will add an element to the array at the end, increasing the size by one.

This line
will add the value "risk_value" to the value in "sum_of_indicator_risk_valuesTP" and store the result in that variable.

It is rather unclear what this code is supposed to do, seems to me, there are some missing parts. The initial boolvaliables are obviously not checked.

It looks like, you are adding conditions up to meet or surpass a threshold to conclude a closing signal. - I know, you stated that, but it is overall rather hard to tell the whole logic just by one function.

Also the global variables are not present, it is very out of context.