Question
Daily AM Return 3-Days MA 5-Days MA 11-Days MA -4.98% -4.52% 0.14% -3.44% 0.26% -1.52% -2.63% -5.22% -1.60% -3.06% -1.23% -2.06% -2.21% -1.83% -2.76% -1.58%
Daily AM Return | 3-Days MA | 5-Days MA | 11-Days MA |
-4.98% | -4.52% | ||
0.14% | -3.44% | ||
0.26% | -1.52% | -2.63% | |
-5.22% | -1.60% | -3.06% | |
-1.23% | -2.06% | -2.21% | |
-1.83% | -2.76% | -1.58% | |
-2.65% | -1.90% | -2.13% | |
-3.54% | -2.67% | -2.90% | |
3.40% | -0.93% | -1.17% | -2.20% |
-0.19% | -0.11% | -0.96% | -1.94% |
-2.36% | 0.29% | -1.07% | -1.65% |
5.65% | 1.03% | 0.59% | -0.69% |
2.49% | 1.93% | 1.80% | -0.47% |
-4.03% | 1.37% | 0.31% | -0.86% |
-4.06% | -1.87% | -0.46% | -0.76% |
0.27% | -2.60% | 0.07% | -0.62% |
-2.52% | -2.10% | -1.57% | -0.68% |
2.53% | 0.09% | -1.56% | -0.21% |
6.15% | 2.05% | 0.47% | 0.67% |
1.96% | 3.55% | 1.68% | 0.54% |
-0.38% | 2.58% | 1.55% | 0.52% |
-3.08% | -0.50% | 1.44% | 0.45% |
0.42% | -1.01% | 1.01% | -0.02% |
1.91% | -0.25% | 0.17% | -0.07% |
-2.05% | 0.09% | -0.64% | 0.10% |
TRADING STRATEGY 1 (subroutine): |
1. If 5-day MA > 11-day MA AND 3-Day MA > 5-Day MA, output BUY (case sensitive) |
2. If 5-day MA > 3-Day MA AND Current Return < 3-Day MA, output SELL (case sensitive) |
3. If there are consecutives buy/sell from conditions 1 and 2 then change them to HOLD; otherwise, output HOLD. |
Each row of data range is named after the title.
So we are given these data sets and asked to write a subroutine to output the signal of either buy or hold or sell depends on the given conditions. (The third condition means any future BUY (or SELL) statements should be changed to until you SELL (or BUY) the stock you have already bought. If you have already used your cash to BUY stocks, you cannot BUY again as you have no cash to do so.)
I have some idea on first two conditions, but have totally no idea how to incorporate condition 3.
Sub part3tradingstrategy1()
Dim variable As String Dim norows As Integer
norows = Range("daliyamreturn").Rows.count
For i = 1 To norows
If Range("threedaysma").Cells(i, 1) = 0 Or Range("fivedaysma").Cells(i, 1) = 0 Or Range("elevendaysma").Cells(i, 1) = 0 Then
variable = "HOLD"
ElseIf Range("threedaysma").Cells(i, 1) > Range("fivedaysma").Cells(i, 1) And Range("fivedaysma").Cells(i, 1) > Range("elevendaysma").Cells(i, 1) Then
variable = "BUY"
ElseIf Range("fivedaysma").Cells(i, 1) > Range("threedaysma").Cells(i, 1) And Range("fivedaysma").Cells(i, 1) > Range("daliyam").Cells(i, 1) Then
variable = "SELL"
Else: variable = "HOLD"
End If
Range("aa13").Cells(i, 1) = variable
variable = ""
Next i
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