"We do not need to be shoemakers to know if our shoes fit and just as little have we any need to be professionals to acquire knowledge of matters of universal interest." - Wilhelm Friedrich Hegel
Thursday, 12 January 2023
Wednesday, 21 December 2022
Macro to compare two data sets
1. Object of the macro
a)The data is populated as follows:
2. Code
Sub Comparedatasets()
Application.ScreenUpdating = False
lr1 = Range("A" & Rows.Count).End(xlUp).Row
lr2 = Range("D" & Rows.Count).End(xlUp).Row
Sheets(1).Range("A2", "B2").Copy
Sheets(2).Range("A1").PasteSpecial Paste:=xlPasteValues
Sheets(3).Range("A1").PasteSpecial Paste:=xlPasteValues
check = False
For r = 3 To lr1
Set compare1 = Cells(r, 1)
For q = 3 To lr2
Set Compare2 = Cells(q, 4)
If compare1 = Compare2 Then Compare2.Interior.Color = vbYellow: check = True
Next q
If check = False Then
Range(compare1, compare1.End(xlToRight)).Copy
Sheets(3).Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial _Paste:=xlPasteValues
End If
check = False
Next r
check = False
For r = 3 To lr2
Set compare1 = Cells(r, 4)
For q = 3 To lr1
Set Compare2 = Cells(q, 1)
If compare1 = Compare2 Then Compare2.Interior.Color = vbYellow: check = True
Next q
If check = False Then
Range(compare1, compare1.End(xlToRight)).Copy
Sheets(2).Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial _Paste:=xlPasteValues
End If
check = False
Next r
Application.ScreenUpdating = True
End Sub
3) Result
Wednesday, 14 December 2022
Diaries on VBA- Scripting Dictionary
ii) Add items to the dictionary Gowtham
For Eg. I want to assign 1 to a, 2 to b
gowtham. add(a,1)
gowtham. add(a,2)
c) When a key is not already declared and is called later, it will get created in dictionary
For Eg,
Sub usedictionary()
Dim dict As New Dictionary
dict.Add "a", 1
dict.Add "b", 2
dict.Add "c", 3
dict("d") = dict("d") + 100
Debug.Print dict("d")
End Sub
..., the above code will print 100
Tuesday, 6 December 2022
Macro to count the number of characters in cells and populate the data set sperately
- Object of the Macro
I want to:
- count the number of HSN digits in Column A,
- get them populated in Column C,
- filter the items with HSN less than 6 digits and
- get the dataset pasted at the cell H1.
2. The Code
Sub countcharactersincell()
Dim a As String
Dim b As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
j = Cells.End(xlDown).Row
For i = 2 To j
a = Cells(i, 1)
b = Len(a)
Cells(i, 3) = b
Next i
Range("A1").AutoFilter Field:=3, Criteria1:="<6"
Range("a1:c" & Range("a1").End(xlDown).Row).SpecialCells(xlCellTypeVisible).Copy
Cells(1, 8).PasteSpecial
End Sub
3. Output
Funfact:
The same output could be achieved with a simple "Sorting" option of Excel.
But, I'm crazy about those "Mootai poochiyai kollum navina machine"
Monday, 28 November 2022
Tech Hack Tit-Bits
Sunday, 7 August 2022
Trade Strategies
1. MACD Trend Following Strategy
A general MACD
https://tradingstrategyguides.com/macd-trend-following-strategy/
2. Using Moving Averages Perfectly
a. For cross over purpose, use both 20 days and 50 days moving average
b. Some stocks might not react to cross over. Hence backtest before you use
c. Use ATR trailing stoploss indicator to fix the exit point
d. Use stochaistics indicator too in addition to the moving average
e. Combining the PSAR or Supertrend with moving average cross-over would giver better results
Technical Indicators
- Williams %R
- This is basically a momentum indicator.
- The value of the indicator oscillates between 0 and -100.
- %R reading above -50 means the price is moving upward. A reading near -100 means oversold levels.
- The MACD displays a MACD line (blue), signal line (red) and a histogram (green) - showing the difference between the MACD line and the signal line.
- When the MACD line crosses ABOVE the zero line, this signals an UPTREND
- When the MACD line crosses BELOW the zero line, this signals an DOWNTREND
- When the MACD line crosses ABOVE the signal line, traders use this as a BUY indication
- When the MACD line crosses BELOW the signal line, traders use this as a SELL indication
- When the MACD line is above the signal line, then the histogram will be positive.
- The opposite is true when the MACD line sits below the signal, whereby the histogram will plot below the zero as a negative value.