This code generates a signal and makes an order request to an exchange. After the order request has been made, the in_position variable that is marked as false should turn true and no more order requests should be made. However, order requests are still being made. Can someone please suggest a solution. The get_buy_or_sell_signals function is placed within a while loop.
Blockquote }
in_position = FALSE  
get_buy_or_sell_signals <- function(data){
  in_position
  print("looking for signals")
  print(tail(data))
  if(data$class[nrow(data)] == "UP" & data$trend[nrow(data)] == TRUE){
    print("will make an order if not in position")
    if(in_position == FALSE){
       send_signal_buy <- BOTS_signal(symbol = "ETHUSDT",side = 
       "buy",bot_name = bot_name, bot_key = bot_key,limitPrice = 
       as.character(data$close[nrow(data)]*1.12))
       in_position = TRUE
       print(in_position)
    }  else{
       print("Already in position")
    }  
  }
  if(data$class[nrow(data)] == "DOWN" && data$trend[nrow(data)] == FALSE){
    print("time to close")
    if(in_position == TRUE){
      send_signal_sell <- BOTS_signal(symbol = "ETHUSDT",side = 
      "buy",bot_name = bot_name, bot_key = bot_key,limitPrice = 
       as.character(data$close[nrow(data)]*0.86))
      in_position = FALSE
  
    } else{
      print("not in position, nothing to do")
    }
  }
}
 
    