Ahmad Obeid
Ahmad Obeid

Reputation: 1

Pine Script Strategy that records conditions from indicators on a frame of bars (a certain number of bars)

I have created a custom indicator that fuses 4 different indicators, each indictor has a buy and sell boolean signal. My indicator requires 3 out of the 4 buy signals to be true in order to send a buy signal and vise versa for sell. My problem is that pine script runs the script on every bar therefore checking the 4 indicators conditions on a single bar and returning a buy signal if 3 out of the 4 conditions are true on a single bar. What I want to accomplish is to send a buy signal if 3 out of 4 are true on a frame of bars. For example on a frame of 10 bars (ind1 true on bar1, ind2 true on bar 4, ind3 false on bar6, ind4 true on bar10)if 3 of the 4 are true in this frame a buy signal should be sent(or plotted). Is this possible in any way?

I have read the pine script documentation but couldnt find anything of use

Upvotes: 0

Views: 329

Answers (1)

i am different
i am different

Reputation: 183

Without providing the code, its hard to provide proper guidance that fits into your existing work.

I suggest looking into defining those four 'Indicators' (maybe "Case" or "Scenario" is a better phrase to use?") into UDT's and add an e.g. "status" field as bool you update on every bar.

Then count the status fields that are "true" and if the result is >= 3, execute your signal.

Upvotes: 0

Related Questions