Reputation: 550
I want to write a code in pine script that enables me to calculate the number of pips between the high and low of only the First candle of the day. I also want to use this value in the form of a variable to set stop losses and targets.
I got this on the web but don't know how it works. Can we modify this to meet the above criteria?
getHighLowNumPips() => (high - low) / syminfo.mintick
plot(getHighLowNumPips())
I am a newbie in pine script and I am not able to write the code. Any help will be greatly appreciated :)
Thanks,
Upvotes: 0
Views: 2788
Reputation: 3828
In the example below the script will calculate the number of pips according to your getHighLowNumPips
function on the first candle of the day and ignore other candles.
getHighLowNumPips() => (high - low) / syminfo.mintick
bool isNewDay = dayofmonth != dayofmonth[1]
var float highLowPips = na
if isNewDay
highLowPips := getHighLowNumPips()
plot(highLowPips)
Note that built-in dayofmonth
use the exchange's timezone.
Upvotes: 2