Reputation: 31
I, I want to create a simple strategy in pinescript as below: Script is trading at 100. Now i want to buy after every fall of 1 point i.e. 99,98,97,96,95 and sell after where every 1 point rise. No need for stop loss. I am absolutely new to coding/programming. I have been trying something like this in pinescript.
strategy("My Strategy", overlay=true, default_qty_value =15)
start = timestamp (2021,7,1)
base = 3300
b1 = crossunder(close, base *0.99)
b2 = crossunder(close, base *0.98)
b3 = crossunder(close, base *0.97)
b4 = crossunder(close, base *0.96)
b5 = crossunder(close, base *0.95)
b6 = crossunder(close, base *0.94)
b7 = crossunder(close, base *0.93)
b8 = crossunder(close, base *0.92)
b9 = crossunder(close, base *0.91)
if time >= start
strategy.long("buy", true, when = b1)
strategy.exit("exit", "buy", profit = 1000)
strategy.entry("buy1",true, when = b2)
strategy.exit("exit", "buy1", profit = 1000)
I have two questions
please forgive me if my query is not clear. Just wondering if anyone could help me where i am going wrong in this.
Upvotes: 1
Views: 1968
Reputation: 31
i think i kinda managed it using "strategy.opentrades"
if strategy.opentrades ==0 and (b1) and time >= start
strategy.order("b1", true)
strategy.exit("exit", "b1", profit = XXX)
i am getting the results that i wanted. thanks
Upvotes: 2