Pinescript how to short at 0.90 level of a stock?

  Kiến thức lập trình

i am trying to write a pinescript that does the following.

if the stock’s cent value is at 90 cents, for example 172.90 170.90 175.90 etc, a short position is opened, with a 15 cent stop loss, and a 30 cent take profit.

So for 172.90 the take profit is 172.60, and the stop loss is 173.05

I have the following written, but it is not taking any trades when imported into the trading view back tester.

strategy("Short Position Entry", overlay=true)

// Define entry conditions
price = close
whole_dollars = int(close)
cents = (close - whole_dollars) * 100
stop_loss = price + 0.15
take_profit = price - 0.30

// Entry condition
if math.abs(cents - 0.90) < 0.01
    strategy.entry("Short", strategy.short)

// Stop loss condition
if price >= stop_loss
    strategy.close("Short")

// Take profit condition
if price <= take_profit
    strategy.close("Short")

plot(cents, title="Cents Value", color=color.blue, style=plot.style_histogram)

any ideas?

LEAVE A COMMENT