Welcome to the BEST forum for traders

Did you know we're sharing tons of exclusive content here?
Our community is growing quickly. Take a look around and say "Hello".

Undeclared variables... already declared

Nov 9, 2021 - 10:05 AM

Viewed 537 times

https://best-trading-indicator.com/community/bti/forums/3953/topics/38568 COPY
  • 1

    0
  • 1

    0
  • 1

    0
  • 1

    0
  • 1

    0
  • 1

    0
  • 1

    0
  • 1

    0
  • 1

    0
  • 1

    0
  • 1

    0
  • 1

    0
  • 1

    0
  • 1

    0
  • 1

    0
  • Hi

    That's because longCondition_0 and longCondition_1 need to be declared above the first if

    Should be

    type = input(0)
    
    var bool longCondition_0 = false
    var bool longCondition_1 = false
    
    if type == 0
        longCondition_0 := (ta.crossover(EMA5,EMA20) and (DI_Up > DI_Down))
        longCondition_1 := ((EMA5 > EMA20) and ta.crossover(DI_Up,DI_Down))
    else
        longCondition_0 := (ta.crossover(EMA5,EMA20) and tsi_condition)
        longCondition_1 := ((EMA5 > EMA20) and tsi_condition)
    
    if ((longCondition_0 or longCondition_1))
        strategy.entry("Buy", strategy.long)
    
    0
  • Hi I'm trying to script an option (variable entitled type) to quickly change conditions of entry of a strategy. Even though I use the input() function, the script keeps telling me Undeclared variable longCondition_0 and same for longCondition_1.

    Why is that ?

    type = input(0)
    
    if type == 0
        longCondition_0 = (ta.crossover(EMA5,EMA20) and (DI_Up > DI_Down))
        longCondition_1 = ((EMA5 > EMA20) and ta.crossover(DI_Up,DI_Down))
    else
        longCondition_0 = (ta.crossover(EMA5,EMA20) and tsi_condition)
        longCondition_1 = ((EMA5 > EMA20) and tsi_condition)
    
    if ((longCondition_0 or longCondition_1))
        strategy.entry("Buy", strategy.long)
    

    Thanks

    0
CONTENTS