I will be the first to tell you that OCD and writing code do not mix. So the very first step is to reduce your code to the minimum number of elements that achieves the same result.
def isUp = close > open;
def isDown = close < open;
plot buy = isUp and high[1] < close; buy.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); buy.SetDefaultColor(GetColor(6));
plot sell = isDown and low[1] > close;
sell.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
sell.SetDefaultColor(GetColor(5));
And in case you don't believe that this cut down and minimized version of your code produces the same results, see the first screenshot below. On the left is your code and on right is this minimized version.
If you struggle to understand how this produces the same results as yours then post a separate question asking for the explanation. At this point I will proceed with the minimized version of the code and remove those repeating up and down arrows.
We must use recursion in order to keep track of the most recent signal. Recursion means the code assigns a value to a variable using its own value from a previous bar on the chart. Using recursion is pretty common. But it's a bit complex to implement. This is going to be much more complex because we need to keep track of both signals within the same variable.
Here is your new code, adapted to prevent the same signal repeating until an opposing signal presents. I added a couple of comment lines to explain the changes.
def isUp = close > open;
def isDown = close < open;
# create variables to hold the values previously used for plotting arrows
def buySignal = isUp and high[1] < close; def sellSignal = isDown and low[1] > close;
# use recursive variable to keep track of the most recent raw signal
rec trackLastSignal = if buySignal then 1 else if sellSignal then -1 else trackLastSignal[1];
# next, check the value of the tracking variable to filter buy and sell signals
plot buy = trackLastSignal[1] == -1 and buySignal;
buy.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
buy.SetDefaultColor(GetColor(6));
plot sell = trackLastSignal[1] == 1 and sellSignal;
sell.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
sell.SetDefaultColor(GetColor(5));
Second screenshot below shows the results.