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:




b) I want to compare based on the Unique identifier List A and List B

c) Highlight the common items in List A and List B

d) Get populated in Sheet 2, items present in List A, but not in List B

e)Get populated in Sheet 3, items present in List B, but not in List A



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

 

1. Part 1- Basics of Dictionary


a) Dictionary is used to assign a value to a key/item

b)Syntax

i) If I want to create Gowtham as new dictionary

Dim Gowtham as Newdictionary

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

  1. 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

1. Convert YouTube Videos into Pdf pages using


2. Need a disposable mail for temporary use like signing up..? Here you go, 



3. Need to do content writing, without travail.. 




(will add more..)

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

  1. 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.





2.  MACD

  • 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.

3. Stochastic Indicator

The stochastic oscillator has 2 lines (%k) and (%d). 

%K = (C-L5close)/(H5-L5) * 100

%D = 3-day SMA of %K.

where,
C = the most recent closing price.
L5 = the low of the five previous trading sessions.
H5 = the highest price recorded within the same 5-day period.

However, the period can be changed.

The 2 lines cross each other and we consider this as the buy/sell signal. 

We call the %k line crossing the %d line above as the buy signal. Whereas we call the %k crossing the %d line below as the sell signal.

The traders consider a stochastics value close to 0 as oversold, i.e, market is enough sold and can bounce back any time. Whereas they consider the stochastics value close to 100 as overbought, i.e, the market is enough bought and can take a correction any time.