Using var
Posted: Wed Jan 20, 2021 3:22 am
Hello - how are you?
I need help with better understanding var and how to use it?
In a strategy script, I want to create a trade execution when two or more indicators give a trade signal, though the signal may come from different bars. Right now, my code is only executing trades when both indicators give the signal at the same time. Here is the script with the rules, which is no longer working that I added var:
Thank you.
I need help with better understanding var and how to use it?
In a strategy script, I want to create a trade execution when two or more indicators give a trade signal, though the signal may come from different bars. Right now, my code is only executing trades when both indicators give the signal at the same time. Here is the script with the rules, which is no longer working that I added var:
Code: Select all
// AROON INDICATOR
length = input(14, title="Aroon Length", minval=1, step=2)
upper = 100 * (highestbars(high, length+1) + length)/length
lower = 100 * (lowestbars(low, length+1) + length)/length
plot(upper, "Aroon Up", color=#FF6A00) //#FF6A00 is orange BUY
plot(lower, "Aroon Down", color=#0094FF) //#0094FF is blue Sell
aroonBuy = crossover(upper, lower)
aroonSell = crossover(lower, upper)
var aroonBuySig = 0.0
var aroonSellSig = 0.0
if aroonBuy
aroonBuySig := true
// VORTEX INDICATOR
period_ = input(14, title="Vortex Length", minval=3, step=2)
VMP = sum( abs( high - low[1]), period_ )
VMM = sum( abs( low - high[1]), period_ )
STR = sum( atr(1), period_ )
VIP = VMP / STR // blue buy
VIM = VMM / STR // red sell
// plot(VIP, title="VI +", color=color.blue) // #3BB3E4)
// plot(VIM, title="VI -", color=color.maroon) //
// Vortex Trade Signals
vortexBuy = crossover(VIP, VIM) // If vip > vip I want this to be saved true until not true anymore
vortexSell = crossover(VIM, VIP) // if vim > vip I want this to be saved true until not true anymore
var vortexBuySig = 0.0
var vortexSellSig = 0.0
if vortexBuy
vortexBuy := true // save Buy signal until Sell signal is given. Need to save until Aroon is also buy signal
// Execute trade when
avBuy = (aroonBuy and vortexBuy) // Buy trade when both Aroon and Vortex say buy, though they each may become true at different times
avSell = (aroonSell and vortexSell) // opposite for sell trade
// before adding var trades were only executing when both aroon and vortex both gave signal on the same bar.
//How do fix so that trade may execute when both are in agreement, which may happen on different bar, and only one trade at a time.