Kaus
Kaus

Reputation: 31

strategy.entry for multiple buy orders

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

  1. if the price fell to 95 and then goes above 100, the backrest should show all 5 trades i.e buy trades at 99,98,97,96,95 and sell trades at 96,97,98,99,100. The back test results only in one order if i use strategy.entry
  2. i want to buy moment price touches 99 so i believe if i try this is any time-frame no of trades executes should remain same.. but that also changes with different time-frames.

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

Answers (1)

Kaus
Kaus

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

Related Questions