0

I am trying to create a strategy that acts as the Moving up % / Moving down % function of the alerts, as shown in the image. The problem is that I can't find any function that allows me to replicate that behavior inside a strategy.enter image description here

I have tried to create a strategy so that every time a candle opens, I place a limit order X % away (so that the trade is opened before the candle closes in the strategy) and cancel the limit order (in case the price has not been reached) when the candle closes.

--- Edit:

What I had thought of for backtesting a strategy is the following:

1-Each time a candle opens, a Limit order is placed at X% of the price at which the candle opened. 2-Being a limit order, TV executes the strategy.entry even if the candle has not closed yet and would have the position to which to set a TP and a SL in the strategy.exit. 3-If the price did not reach the level of that limit order, the limit order is cancelled when the candle closes. 4-Repeat the process from step 1.

I tried to do it, but I have not succeeded, evidently my knowledge of Pine Script is not enough. That's why I asked this question, to see if someone knows how to do it?

1 Answers1

0

You can't really backtest that in a strategy.

By default, during both historical and real-time calculation, code is calculated on the bar’s close. Please see this.

What you can do is, check if the price closed x% away from its open price and place a market order if so. However, this won't exactly work as you want.

Another idea is to write your own "strategy" as an indicator. It will be a little more complicated but you can at least backtest it.

For the real-time execution, you can use calc_on_every_tick=true so your script will be calculated on every real-time tick.

vitruvius
  • 15,740
  • 3
  • 16
  • 26
  • What I had thought of for backtesting a strategy is the following: 1-Each time a candle opens, a Limit order is placed at X% of the price at which the candle opened. 2-Being a limit order, TV executes the strategy.entry even if the candle hasn't closed yet and would have the position to which to set a strategy.exit. 3-If the price did not reach the level of that limit order, the limit order is cancelled when the candle closes. 4-Repeat the process from step 1. I tried to do it, but I have not succeeded, evidently my knowledge of Pine Script is not enough. Someone knows how to do it? – Delta Trading Nov 16 '22 at 10:53
  • As I said, your limit orders will be placed on bar close. You cannot place it when a bar opens. – vitruvius Nov 16 '22 at 11:01
  • Yes you can, I already do it with another strategy and works perfectly. But in this case, I can't make it work – Delta Trading Nov 17 '22 at 09:20