First off, I need to let you know there was a problem with your AddOrder statement that would report the entry price at the low of the bar instead of the close. In practice we all know it's impossible to enter a trade at the dead low of a candle. If it were, we all would be rich beyond our wildest dreams.
So the first step is to correct your entry price to the close of the signal bar. That is certainly possible. However in practice you will find there is some slippage because you can't be the last person to place a trade on a consistent basis. When constructing chart strategies we must always ensure the entry and exit prices are achievable in live trading.
Here's how we do that for your particular strategy:
AddOrder(OrderType.BUY_TO_OPEN, buySignal[-1], close[-1], 100, Color.YELLOW, Color.YELLOW);
Be very careful here. Because we are telling the strategy engine to read one bar into the future. If we are not careful here we can create what is referred to as a "future leak". Which is when the strategy must know what takes place in the future in order to make a trade. In this case we are entering the trade at the close. So that is the end of the bar and does not create a future leak.
If we had chosen the open instead "open[-1]". Well that would be impossible to trade in a live market because we would not now this signal bar is valid until it closes. So we can either enter on the close of the signal bar or the open on the bar that follows the signal bar.
But you want to exit the trade on the following bar so we enter on the close of the signal bar so we can keep the following bar free and clear for closing the trade. How do we do that?
AddOrder(OrderType.SELL_TO_CLOSE, buySignal, close[-1], 100, Color.WHITE, Color.WHITE);
Here we are checking if the current bar is a buy signal. Then exit at the close of the bar that follows.
Screenshot below shows the result. Here is the full code that includes your original:
def buySignal = open is less than close from 1 bars ago and close from 1 bars ago is less than close from 2 bars ago and close from 2 bars ago is less than close from 3 bars ago;
AddOrder(OrderType.BUY_TO_OPEN, buySignal[-1], close[-1], 100, Color.YELLOW, Color.YELLOW);
AddOrder(OrderType.SELL_TO_CLOSE, buySignal, close[-1], 100, Color.WHITE, Color.WHITE);
Notice we are no longer using "x" as a variable name. Your variable names should fully describe what they contain. Single character variable names are nonsense. Avoid them like the plague they truly are. Just because you see other people using them does not mean it's safe.