1 # Create simple moving average 2 # using Indicators 3 Close = convert(Array, df[:Close]) 4 sma_200 = sma(Close,n=200) 5 df[:Close_200sma] = sma_200 6 # Create Signals 7 # Stay long over 200sma 8 # Exit positions below 200sma 9 # use ifelse() function see - #https://en.wikibooks.org/wiki/Introducing_Julia/Controlling_the_flow 10 # remember . in front of the (.>) for vectorization! 11 df[:Signal_Long] = ifelse(df[:Close] .> df[:Close_200sma],1,0) 12 # Lag data +1 forward 13 # Avoid look ahead bias 14 df[:Signal_Long] = [0; df[1:end-1,:Signal_Long]]