I have a nested if statement within a for loop but the first if statement seems not to be progressing onto the rest of the for loop.
for i, x in enumerate(S[start:-1], start):
if i > max(sma_period1, sma_period2, sma_period3):
j = i-start
if ma1[i] == x:
w[j+1] = w[j]
cash[j+1] = cash[j]
if ma1[i] < x:
w[j+1] = cash[j]/x + w[j]
cash[j+1] = 0
if ma1[i] > x:
cash[j+1] = w[j]*x + cash[j]
w[j+1] = 0
tf_strategy_ma1 = [a*b for a,b in zip(w,S[start:])]+ cash
Sorry if this is a very basic question, I am new to coding and completely stuck. Thanks for your help.
-
if its not getting in you need to get an idea of what the test is seeing. the max() statement as currently show in in your post does not vary each time through the loop and can be calculated and assigned a variable before entering the loop. I would do that, print that value then print the I value on each iteration. that will give you an idea how the loop is behaving.LhasaDad– LhasaDad2021年02月27日 16:37:38 +00:00Commented Feb 27, 2021 at 16:37
-
Why have used S[start:-1] in enumerate. Never seen something like that?Priyanshu Jangra– Priyanshu Jangra2021年02月27日 16:40:08 +00:00Commented Feb 27, 2021 at 16:40
1 Answer 1
Some debug pointers for a situation like this:
- you need to get an idea of what the test is seeing.
- the max() statement as currently show in in your post does not vary each time through the loop and can be calculated and assigned a variable before entering the loop.
- I would do that, print that value then print the I value on each iteration. that will give you an idea how the loop is behaving.
answered Feb 27, 2021 at 16:39
LhasaDad
2,2022 gold badges16 silver badges24 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
user13017275
Sorry for the very late reply. Thank you very much. I did in fact follow your advice.
lang-py