0

I know it sounds weird, as a trade cannot be decided to be a win or a loss until it has been executed, but can we have our original strategy in the form of an indicator in the chart, and after having a win trade by the indicator, only our strategy script should run, and when we lose a trade on the strategy script, our new position will not open until another winning trade is encountered by the indicator script?

Is it possible to do so in TradingView Pinescript code?

Sewatech
  • 13
  • 3

2 Answers2

0

To do what you are looking, you must use a strategy in Pinescript.
In your strategy, you can include the code of your favorite indicator and then wait for the result to take a decision.
In pinescript, you cannot 'win a trade' with an indicator.

G.Lebret
  • 2,826
  • 2
  • 16
  • 27
0

Yes you can do that in pine script.

You'll have to code your indicator/strategy yourself. It may be helpful to check out the source code of the indicator you're using to have an idea/quick start.
I'll demonstrate with the strategy boilerplate of TradingView how can could achieve that fairly simply:

//@version=5
strategy("My strategy", overlay=true, margin_long=100, margin_short=100)

longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
if (longCondition)
    strategy.entry("My Long Entry Id", strategy.long)

shortCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))
if (shortCondition)
    strategy.entry("My Short Entry Id", strategy.short)

////////////////////////////////
// Here is the key part for you
////////////////////////////////
if 0 < strategy.closedtrades.profit(strategy.closedtrades - 1) // profit of the last closed trade is positive
    strategy.entry("My new profit dependent strategy", strategy.long) // entry new trade
elod008
  • 1,227
  • 1
  • 5
  • 15