MY EA is closing trades in losses i set it to take profits based on money, can you assist with what i need to correct as this is my first EA i have developed without a freelancer

 
#include <Trade\Trade.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\DealInfo.mqh>
CTrade trade;
CDealInfo deal;
CPositionInfo info;

enum types{ONLY_BUY,ONLY_SELL,BOTH};

input types      Types     = BOTH;    
input int      RSIPeriod     = 2;   // RSI Period     
input ENUM_APPLIED_PRICE RSIappliedPrice=PRICE_CLOSE;//RSI Applied Price
input double levelLow=30;// level Low
input double levelHigh=30;//level High
input int MagicNumber=4554;
input double Stoploss=10;//SL $
input double Takeprofit=10;//TP $
input int MaxTrades=10;

int copy;
int OnInit()
  {
//---
   trade.SetExpertMagicNumber(MagicNumber);
   copy=iRSI(Symbol(),PERIOD_CURRENT,RSIPeriod,RSIappliedPrice);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
bool canTrade()
{
   for(int i=PositionsTotal()+1;i>=0;i--)
      if(info.SelectByIndex(i)&&info.Magic()==MagicNumber&&info.Symbol()==Symbol())
         return false;
   return true;
}
void close(int types)
{
   for(int i=PositionsTotal()+1;i>=0;i--)
      if(info.SelectByIndex(i)&&info.Magic()==MagicNumber&&info.Symbol()==Symbol()&&info.PositionType()==types)
         trade.PositionClose(info.Ticket());
}
void closeOnMoney()
{
   double profits=1;
   for(int i=PositionsTotal()+1;i>=0;i--)
      if(info.SelectByIndex(i)&&info.Magic()==MagicNumber&&info.Symbol()==Symbol())
      {
         profits=info.Profit();
         if(profits<=-Stoploss||profits>=Takeprofit){close(0);close(1);}
      }
}
datetime expiration_=D'23.02.2023';
void OnTick()
  {
//---
   //if(TimeCurrent()>=expiration_)ExpertRemove();
   closeOnMoney();
   
   if(Period()<0){Comment("this EA trades above 1 minutes");return;}
   else Comment("                                            ");
   
   double tab[];
   CopyBuffer(copy,0,SignalCandle,2,tab);
   ArrayReverse(tab);
   
   bool buy=(tab[0]>levelLow&&tab[1]<levelLow);
   bool sell=(tab[0]<levelHigh&&tab[1]>levelHigh);
   
   if(tab[0]<levelLow)close(1);
   else if(tab[0]>levelHigh)close(0);
      
   if(canTrade()&&buy&&(Types==ONLY_BUY||Types==BOTH))for(int i=0;i<MaxTrades;i++)trade.Buy(lots());
   else if(canTrade()&&sell&&(Types==ONLY_SELL||Types==BOTH))for(int i=0;i<MaxTrades;i++)trade.Sell(lots());
  }
double lots()
{
   //HistorySelect(0,TimeCurrent());
   //for(int i=HistoryDealsTotal()-1;i>=0;i--)
   //   if(deal.SelectByIndex(i)&&deal.Symbol()==Symbol()&&deal.Magic()==MagicNumber)
   //   {
   //      if(deal.Profit()>0)return deal.Volume()*2;
   //      else return Lot;
   //   }
   return Lot;
}
input int SignalCandle=1;//Signal Candle
input double Lot=0.2;
//+------------------------------------------------------------------+

 
Amos Tsopotsa:

MY EA is closing trades in losses i set it to take profits based on money, can you assist with what i need to correct as this is my first EA i have developed without a freelancer

  1. The title should be brief. Put the full text in the post.

  2.          if(profits<=-Stoploss||profits>=Takeprofit){close(0);close(1);}
    
    Do not post code with will not even compile. What is the void close(int) function you call?
 
its based on rsi only standard indicator