Question
Determine if SMA is in uptrend or downtrend and if the Closing Price has recently crossed from below the SMA to above the SMA. We
Determine if SMA is in uptrend or downtrend and if the Closing Price has recently crossed from below the SMA to above the SMA. We are defining recently as in 3 weeks ago vs. today. (Note: Today is actually the end of the data set, which is 11/20/2020. a. This is where your (possibly newly developed) coding skills will be put to the test. b. The basic structure of the For/Next loops and the If, Then, Else statements has been left intact for you. You have to interpret the If, Then, Else logic and write it out as coding statements. c. The comments (instructions) have also been left in the code. d. Syntax note: The results of If statements that result in TRUE or FALSE need to be put in double quotes, as in TRUE or FALSE.
' Determine if SMA is moving up and if Closing Price has crossed from ' BELOW the SMA 3 weeks ago to ABOVE the SMA. ' Write output to Sheet3 '******************************************************************** jRow = 2 For jCo = 1 To numCos Sheets("Sheet3").Cells(jRow, 1) = jTicker(jCo) Sheets("Sheet3").Cells(jRow, 2) = jDate(jCo, numPrcs) Sheets("Sheet3").Cells(jRow, 3) = closePrc(jCo, numPrcs) Sheets("Sheet3").Cells(jRow, 4) = closePrc(jCo, numPrcs - jLag) Sheets("Sheet3").Cells(jRow, 5) = SMA(jCo, numPrcs) Sheets("Sheet3").Cells(jRow, 6) = SMA(jCo, numPrcs - jLag) Sheets("Sheet3").Cells(jRow, 9) = jMoat(jCo) 'Test if SMA is higher than it was jLag weeks ago. ' If Yes, then write "TRUE" in column 7 of Sheet3 ' If No, then write "FALSE" in column 7 of Sheet3 If ( ) Then Else End If 'Next, test IF Price jLag weeks ago < SMA jLag wks ago AND IF Price now > SMA now. 'This is called a "compound IF" statement. It takes the form as follows: 'If(Condition 1 And Condition 2) Then ' Write "TRUE" in column 8 of Sheet3 'Else ' Write "FALSE" in column 8 of Sheet3 'End If 'Note that Condition 1 compares closePrc numPrcs - jLag weeks ago with SMA numPrcs - jLag weeks ago 'Condition 2 compares closePrc at date numPrcs with SMA at date numPrcs If ( ) Then Else End If jRow = jRow + 1 Next jCo '******************************************************************** End Sub
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started