I have tried whatever I can but cannot figure out how to do this. I have no experience in coding but I am decently proficient in excel and know VBA to some extent, so somehow I manage to wiggle my way with different coding languages for different requirements. I can say that I am good at Googling, so I just google what I exactly want and get the answers for the task in any language that I am working on. And then simply copy paste the solutions with the adjustments that are specific to my task. But can't figure this one out, and I have googled different questions and searched for solutions on all the result pages. Didn't get lucky as usual. Just started with Pine Code last week.
I have the following query.
So I have an indicator that runs from 0 - 100. It can stay at 100 or 0 for multiple bars. I want to do the following -
When the indicator reaches 100, I want to find the closing price of the bar. Then until it stays at 100, this condition should be open (this is the first condition). Then once the indicator value goes below 98, I want to find the closing price of the bar (this is the second condition). If the closing price of the bar when the indicator went below 98 was higher than the closing price when the indicator reached 100 the first time, then a strategy.long will execute.
If the above two conditions are met but the closing price on condition1 was higher than the closing price on condition 2, then a strategy.short will execute.
When the indicator reaches 0, I want to find the closing price of the bar. Then until it stays at 0, this condition should be open (this is the first condition). Then once the indicator value goes above 2, I want to find the the closing price of the bar (this is the second condition). If the closing price of the bar when the indicator went above 2 was higher than the closing price when the indicator reached 0 the first time, then a strategy.long will execute.
If the above two conditions are met but the closing price on condition1 was higher than the closing price on condition 2, then a strategy.short will execute.
Also, I want to add a limit of 0.8% on the price when the startegy is long/short.
If you read all of this, thank you for your time.
Hoping you can help me with a solution.
Thank You once again, Cheers! :)
This is my code (it currently is an indicator but I want a strategy).-
mom = ta.mom(close,100)
percentile = (ta.percentrank(mom, 100))
x = false
if percentile == 100
x:=true
if percentile < 99 and percentile >98
x:=false
plotshape(percentile, title = "Buy", style = shape.arrowup, location = location.belowbar, color = color.green, text = "Buy", textcolor = color.green, size = size.large)
It resulted in multiple buy signals.