Skip to content

Instantly share code, notes, and snippets.

@flare9x
Last active August 17, 2018 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flare9x/067ee4b0abd43db780794557a0732628 to your computer and use it in GitHub Desktop.
Save flare9x/067ee4b0abd43db780794557a0732628 to your computer and use it in GitHub Desktop.
Set Exit On Close
# Updated to Julia 0.7 - Fixed depreciation warnings
# Passed on v1.0
# Dummy Data
test_entry = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0]
test_data1_day = [5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10]
index = collect(1:1:length(test_entry))
# initialize output
test_n_bar = zero(test_entry)
let trade_counter = 0
# set exit on close for loop
for i = 2:length(test_entry)
# reset trade counter
if test_data1_day[i] != test_data1_day[i-1]
trade_counter = 0
end
if (test_entry[i] == 1)
trade_counter = trade_counter + 1 # keep track of number of trades per day
end
# If repeat signals, ignore so that we do not go into a while loop each time saving computation time
if trade_counter == 1 & test_entry[i] == 1
test_n_bar[i] = 1
j = 0 # set j counter
n = i
while(test_data1_day[n] == test_data1_day[n+1]) # while day is the same day
n = i + j # carry over index position
# print(",",n) # print to make sure are not while looping repeat signals = test pass
if n >= length(test_entry) # Check if n is bigger than the length of signal, if true break
break
end
test_n_bar[n] = 1
j = j + 1
end
end
end
end
# Validate code is working as intended
test = hcat(index,test_data1_day,test_n_bar,test_entry)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment