Simple Tradingview Pinescript strategy
Budget: $30 – $250 USD
Hi, thanks for looking at my project. What I need is extremely simple and will take a skilled Pine Script programmer only about 5 minutes. Ideally you could have it done today. I need a Tradingview strategy that will buy a stock when a specific price value is reached (for example, $100.00), with a stop to sell it if another price is reached (for example, $99.00). These prices are to be entered in through the strategy input box.
There will be 3 inputs: Buy price, sell stop, and initial position size.
Buy price is the price that will trigger a buy order. For example, if the buy price is 100, if the stock is at 99.5, then 99.9, then 100, when it touches 100 the strategy buy order is sent. This should be immediate, not at the end of the bar.
The sell stop is the price at which a sell order is sent. For example, if the sell stop is 99, if the stock is at 99.5, then 99.1, then 99, when it touches 99 the strategy sell order is sent. This should be immediate, not at the end of the bar.
The third input is the initial position size, which will be set to either 0 or 1. This tells the strategy whether a position already exists at the time the strategy is activated.
So for example:
If it's set to 1 (because I already hold the shares) then if the price goes down to the sell stop it will sell, because position size > 0.
if it's set to 1 and it goes up to the buy price, it won't buy because position size is already > 0.
If position size is set to 0 and it goes up to the buy price, it will buy, because position size is 0.
If position size is set to 0 and it goes down to the stop price, it won't sell, because position size is 0.
Of course, if position size is 0 and it buys, then position size becomes 1. If position size is 1 and it sells, then position size becomes 0. In this way, it can keep going forever.
The only other thing that's needed is that the prices (buy price and stop price) should be plotted as lines on the chart.
So, to give an example of how it would function when run:
The initial position is set to 1, the buy price is set to 100 and the stop price is set to 99.
The stock is at 99.5, then goes to 100. The strategy does not send a buy order because the position is already 1.
Then the stock goes to 99.5, then to 99. The strategy sends a sell order because 99 is the stop and position = 1.
The stock then goes to 99.7, then to 100. The strategy sends a buy order because the buy price is 100 and position = 0.
Another example: The initial position size is set to 0, the buy price is set to 100 and the stop price is set to 99.
The stock goes down to 99.5, then to 99. The strategy does not send a sell order because the position size is 0.
The stock then goes to 99.7, then to 100. The strategy sends a buy order because the buy price is 100 and position size = 0.
Please note: As it is written, the strategy will always lose money. That's okay. It's meant to be used as a tool for entering positions which I will close manually later.
Thanks, and please let me know if you have any questions.
There will be 3 inputs: Buy price, sell stop, and initial position size.
Buy price is the price that will trigger a buy order. For example, if the buy price is 100, if the stock is at 99.5, then 99.9, then 100, when it touches 100 the strategy buy order is sent. This should be immediate, not at the end of the bar.
The sell stop is the price at which a sell order is sent. For example, if the sell stop is 99, if the stock is at 99.5, then 99.1, then 99, when it touches 99 the strategy sell order is sent. This should be immediate, not at the end of the bar.
The third input is the initial position size, which will be set to either 0 or 1. This tells the strategy whether a position already exists at the time the strategy is activated.
So for example:
If it's set to 1 (because I already hold the shares) then if the price goes down to the sell stop it will sell, because position size > 0.
if it's set to 1 and it goes up to the buy price, it won't buy because position size is already > 0.
If position size is set to 0 and it goes up to the buy price, it will buy, because position size is 0.
If position size is set to 0 and it goes down to the stop price, it won't sell, because position size is 0.
Of course, if position size is 0 and it buys, then position size becomes 1. If position size is 1 and it sells, then position size becomes 0. In this way, it can keep going forever.
The only other thing that's needed is that the prices (buy price and stop price) should be plotted as lines on the chart.
So, to give an example of how it would function when run:
The initial position is set to 1, the buy price is set to 100 and the stop price is set to 99.
The stock is at 99.5, then goes to 100. The strategy does not send a buy order because the position is already 1.
Then the stock goes to 99.5, then to 99. The strategy sends a sell order because 99 is the stop and position = 1.
The stock then goes to 99.7, then to 100. The strategy sends a buy order because the buy price is 100 and position = 0.
Another example: The initial position size is set to 0, the buy price is set to 100 and the stop price is set to 99.
The stock goes down to 99.5, then to 99. The strategy does not send a sell order because the position size is 0.
The stock then goes to 99.7, then to 100. The strategy sends a buy order because the buy price is 100 and position size = 0.
Please note: As it is written, the strategy will always lose money. That's okay. It's meant to be used as a tool for entering positions which I will close manually later.
Thanks, and please let me know if you have any questions.
Related categories:
Pine Script