elastic
Pine Script Rookie
Pine Script Rookie
Posts: 5
Joined: August 11th, 2022

Offset issue....

Hi,

I've just made me first strategy script, super basic, got it just as I want it, but all entry and exit points need to be offset -1.
I worked out it needs to be done in the plot section but just cannot figure out how to do it.

Any help would really be appreciated,

Many thanks
E

Apologies if I have pasted the code the wrong way in here, couldn't see another way to share it?

Code: Select all

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © elasticc

//@version=5
strategy("S1", overlay=true,
         initial_capital=4000,
         default_qty_type=strategy.percent_of_equity, 
         default_qty_value=100) // 100% of balance invested on each trade)
         
//User inputs for settings

i_ema           = input.int(title="ema Length", defval=8, minval=1, maxval=500)
i_startTime     = input.time(title="Start Filter", defval=timestamp("01 Jan 1995 13:30 +0000"), group="Time Filter", tooltip="Start date & time to begin searching for setups")
i_endTime       = input.time(title="End Filter", defval=timestamp("1 Jan 2099 19:30 +0000"), group="Time Filter", tooltip="End date & time to stop searching for setups")

//Lets do buy on close above ema8 and sell on close under it

//Get our ema8
ema8=ta.ema(close, i_ema)

//Check filters
f_dateFilter = time >= i_startTime and time <= i_endTime

// Check buy/sell conditions
var float buyPrice = 0
buyCondition    = close > ema8 and strategy.position_size == 0 and f_dateFilter
sellCondition   = close < ema8 and strategy.position_size > 0 and f_dateFilter

// Enter positions
if buyCondition
    strategy.entry(id="Long", direction=strategy.long)


// Exit positions
if sellCondition
    strategy.close(id="Long", comment="Exit Trade")


//Plot ema8 plus color
plot(ema8, color=color.green)



Return to “Share Your Scripts”