My Podcasting Adventure: A Journey of Fumbles and Interview Insights

Recently, I had the unique opportunity to be interviewed on a podcast hosted by my friend and former colleague. As I stepped into this new role as the interviewee, I was excited yet anxious about sharing my journey into machine learning (ML) and my experiences with job interviews, particularly at Intel. Little did I know that this would turn into a delightful mix of insights and humorous blunders.

🎥 The Setup: Lights, Camera, Action!

As the podcast began, I felt a rush of adrenaline. I was ready to share my story—how I transitioned into data science and the skills necessary for ML roles. However, as soon as the camera rolled, I found myself fumbling over non-technical questions. It’s one thing to discuss algorithms and data sets, but when asked about my journey! It was like being asked to recite Shakespeare while juggling flaming torches—definitely not my forte.

🤦‍♂️ The Hiccups Were Real

Throughout the interview, there were plenty of hiccups. From awkward pauses to mispronouncing terms, I found myself in a comedy of errors. At one point, I accidentally mixed up technical jargon with everyday phrases, leaving both me and my friend chuckling. It was a reminder that even in professional settings, it’s okay to laugh at oneself. After all, who doesn’t love a good blooper reel?

📚 Sharing My Journey

Despite the stumbles, I managed to share key insights from my journey:

  • Educational Influence: I discussed how my academic background laid the foundation for my interest in machine learning. Exploring diverse subjects early on helped me discover my passion for data science.

  • Real-World Applications: My fascination with real-world applications—especially in computer vision—was a major driving force in my career. This curiosity led me to seek hands-on projects that bridged theory with practice.

  • Essential Skills: I emphasized that mastering mathematics and programming is critical for anyone looking to excel in ML roles. Whether you’re coding in Python or diving into C/C++, having a solid grasp of these skills is non-negotiable.

  • Interview Preparation: Sharing tips on preparing for job interviews was particularly important. Understanding the job requirements and practicing both technical and behavioral questions can make all the difference—trust me; I learned this the hard way!

  • Emergence of ML Compilers: We also touched on the rise of ML compilers and their significance in optimizing model efficiency. This niche area is becoming increasingly relevant as companies look to enhance their AI applications.

🌐 The Future Looks Bright

As we wrapped up our conversation, I highlighted the exciting future of AI and generative intelligence. These trends emphasize adaptability in the workforce—a lesson that resonated with me throughout my career journey. The ability to collaborate and continuously learn will be vital as technology evolves.

🤝 A Call to Action

So there you have it! My first podcast experience was filled with laughter, learning moments, and a generous dose of self-mockery. If you’re considering diving into podcasting or just want to hear about job interview experiences at Intel, I invite you to check out the full video. You’ll definitely gain valuable insights that could help you navigate your own career path.

Identifying Bullish and Bearish Patterns with EMA and Hammer Candles in Pine Script

In the world of technical analysis, understanding candlestick patterns and moving averages can give traders insights into potential market direction. Today, we’ll go through a Pine Script code that identifies key candlestick patterns, specifically Bullish Engulfing, Bearish Engulfing, Hammer, and Inverted Hammer candles, along with Exponential Moving Averages (EMAs) for additional trend confirmation. By the end, you’ll have a clear understanding of how each pattern is detected and how EMAs can be used to support these signals.

Table of Contents

  1. Introduction to Candlestick Patterns and EMAs
  2. Setting Up Bullish and Bearish Engulfing Patterns
  3. Adding Exponential Moving Averages (EMAs)
  4. Identifying Hammer and Inverted Hammer Candles
  5. Plotting and Alert Conditions
  6. Complete Code for the Indicator
  7. Conclusion

1. Introduction to Candlestick Patterns and EMAs

Candlestick patterns and Exponential Moving Averages (EMAs) are essential components of technical analysis. Candlestick patterns help traders spot possible reversals or continuations, while EMAs highlight the trend direction. In this article, we’ll use Pine Script to combine these elements and identify:

  • Bullish and Bearish Engulfing Candles
  • Bullish and Bearish Hammer Candles (and their inverted forms)
  • EMAs (5, 9, 15, 50, 100, and 200-period)

This script will help traders visualize these patterns and moving averages on the chart, providing potential buy or sell signals.


2. Setting Up Bullish and Bearish Engulfing Patterns

An engulfing candle pattern occurs when a candle “engulfs” the previous one, indicating a potential reversal. Here’s how we define the logic for Bullish and Bearish Engulfing patterns in Pine Script.

Bullish Engulfing Condition

A Bullish Engulfing candle forms when:

  • The previous candle is bearish (close[1] < open[1]).
  • The current candle is bullish (close > open).
  • The current candle’s close is higher than the previous close.
  • The current candle’s high is higher than the previous high, and its low is lower than the previous low.
  • Volume is higher than the previous candle.
1
bullish_engulfing = (close[1] < open[1]) and (close > open) and (close > close[1]) and (close > high[1]) and (low < low[1]) and (open < open[1]) and (high > high[1]) and (volume > volume[1])

Bearish Engulfing Condition

A Bearish Engulfing candle forms when:

  • The previous candle is bullish (close[1] > open[1]).
  • The current candle is bearish (close < open).
  • The current candle’s close is lower than the previous close.
  • Volume is higher than the previous candle.
1
bearish_engulfing = (close[1] > open[1]) and (close < open) and (close < open[1]) and (close < close[1]) and (low < low[1]) and (open > open[1]) and (high > high[1]) and (volume > volume[1])

These conditions are then used to plot signals on the chart when a Bullish or Bearish Engulfing candle is detected.


3. Adding Exponential Moving Averages (EMAs)

EMAs are calculated by giving more weight to recent prices, making them more responsive to price changes than Simple Moving Averages. Here, we include 5, 9, 15, 50, 100, and 200-period EMAs to provide different levels of trend indication.

1
2
3
4
5
6
ema_5 = ema(close, 5)
ema_9 = ema(close, 9)
ema_15 = ema(close, 15)
ema_50 = ema(close, 50)
ema_100 = ema(close, 100)
ema_200 = ema(close, 200)

These EMAs are then plotted on the chart to help traders identify trends and potential support or resistance levels.


4. Identifying Hammer and Inverted Hammer Candles

Hammer and Inverted Hammer candles indicate potential reversals. A Hammer candle has a small body and a long lower shadow, signaling buying pressure after a downtrend. Conversely, an Inverted Hammer has a long upper shadow and small body, often indicating a potential reversal in an uptrend.

Hammer and Inverted Hammer Conditions

We define specific conditions to identify Green (Bullish) and Red (Bearish) Hammers, as well as Green and Red Inverted Hammers. These conditions consider:

  • The body-to-shadow ratio.
  • The size of the body and shadows.
  • Volume.

Here’s how we define the conditions:

1
2
pure_hammer_condition = (close >= open and body_size <= hammer_body_to_total_ratio * (high - low)) and (body_size >= min_body_size) and (lower_shadow_size >= min_shadow_size * body_size) and (upper_shadow_size < open_high_error * body_size) and (lower_shadow_size > upper_shadow_size) and (volume > volume[1])
pure_inverted_hammer_condition = (close <= open and body_size <= hammer_body_to_total_ratio * (high - low)) and (body_size >= min_body_size) and (upper_shadow_size >= min_shadow_size * body_size) and (lower_shadow_size < open_high_error * body_size) and (upper_shadow_size > lower_shadow_size) and (volume > volume[1])

Reversal Hammer Conditions

These conditions capture Red Hammers and Green Inverted Hammers, which can indicate reversal patterns:

1
2
reversal_hammer_condition = (close < open and body_size <= hammer_body_to_total_ratio * (high - low)) and (body_size >= min_body_size) and (lower_shadow_size >= min_shadow_size * body_size) and (upper_shadow_size < open_high_error * body_size) and (lower_shadow_size > upper_shadow_size) and (volume > volume[1])
reversal_inverted_hammer_condition = (close > open and body_size <= hammer_body_to_total_ratio * (high - low)) and (body_size >= min_body_size) and (upper_shadow_size >= min_shadow_size * body_size) and (lower_shadow_size < open_high_error * body_size) and (upper_shadow_size > lower_shadow_size) and (volume > volume[1])

5. Plotting and Alert Conditions

Now that we’ve set up the conditions for each pattern, we can plot them on the chart and add alerts. We use plotshape() to visualize the signals on the chart and alertcondition() to trigger alerts when specific patterns appear.

Plotting the Signals

Here’s how we plot each pattern with different colors and shapes:

1
2
3
4
5
6
7
plotshape(signal, style=shape.labelup, location=location.belowbar, color=color.green, text="HVB", size=size.small)
plotshape(signal2, style=shape.labeldown, location=location.abovebar, color=color.red, text="HVB", size=size.small)

plotshape(pure_hammer_condition, style=shape.triangleup, location=location.belowbar, color=color.lime, size=size.small, title="Green Hammer")
plotshape(pure_inverted_hammer_condition, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="Red Hammer")
plotshape(reversal_hammer_condition, style=shape.triangleup, location=location.belowbar, color=color.yellow, size=size.small, title="Reversal Hammer")
plotshape(reversal_inverted_hammer_condition, style=shape.triangledown, location=location.abovebar, color=color.maroon, size=size.small, title="Reversal inverted Hammer")

Adding Alerts

Alerts notify you when the selected patterns are identified. In this example, we add an alert for high volume Bullish Engulfing patterns.

1
alertcondition(signal, title="High Volume Bullish Engulfing", message="A high volume bullish engulfing candle has been identified")

6. Complete Code for the Indicator

Here is the complete code that combines all the components discussed:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//@version=5
indicator("EMA and Candlestick Patterns", overlay=true)

// Input parameters for engulfing patterns
length = input.int(10, title="Length")
mult = input.float(1.5, title="Multiplier")
min_vol = input.int(1000, title="Minimum Volume")

// Calculate the bullish engulfing condition
bullish_engulfing = (close[1] < open[1]) and (close > open) and (close > close[1]) and (close > high[1]) and (low < low[1]) and (open < open[1]) and (high > high[1]) and (volume > volume[1])

// Calculate the bearish engulfing condition
bearish_engulfing = (close[1] > open[1]) and (close < open) and (close < open[1]) and (close < close[1]) and (low < low[1]) and (open > open[1]) and (high > high[1]) and (volume > volume[1])

// Calculate the high volume condition
high_volume = volume > mult * ta.sma(volume, length)

// Calculate the 9 EMA, 50 EMA, and other EMAs
ema_5 = ta.ema(close, 5)
ema_9 = ta.ema(close, 9)
ema_15 = ta.ema(close, 15)
ema_50 = ta.ema(close, 50)
ema_100 = ta.ema(close, 100)
ema_200 = ta.ema(close, 200)

// Combine the conditions to create the signal for engulfing patterns
signal_bullish_engulfing = bullish_engulfing
signal_bearish_engulfing = bearish_engulfing

// Plot the engulfing signals
plotshape(signal_bullish_engulfing, style=shape.labelup, location=location.belowbar, color=color.green, text="BE", size=size.small)
plotshape(signal_bearish_engulfing, style=shape.labeldown, location=location.abovebar, color=color.red, text="BE", size=size.small)

// Input parameters for hammer and inverted hammer
hammer_body_to_total_ratio = input.float(0.55, title="Hammer Body to Total Candle Ratio")
min_body_size = input.float(0.001, title="Minimum Body Size")
min_shadow_size = input.float(0.5, title="Minimum Shadow Size")
open_high_error = input.float(0.15, title="Open-High Margin of Error")

// Calculate body size and shadow size for hammer conditions
body_size = math.abs(close - open)
upper_shadow_size = high - math.max(open, close)
lower_shadow_size = math.min(open, close) - low

// Define conditions for green hammer and red inverted hammer
green_hammer_condition = (close >= open and body_size <= hammer_body_to_total_ratio * (high - low)) and (body_size >= min_body_size) and (lower_shadow_size >= min_shadow_size * body_size) and (upper_shadow_size < open_high_error * body_size) and (lower_shadow_size > upper_shadow_size) and (volume > volume[1])
red_inverted_hammer_condition = (close <= open and body_size <= hammer_body_to_total_ratio * (high - low)) and (body_size >= min_body_size) and (upper_shadow_size >= min_shadow_size * body_size) and (lower_shadow_size < open_high_error * body_size) and (upper_shadow_size > lower_shadow_size) and (volume > volume[1])

// Define conditions for red hammer and green inverted hammer
red_hammer_condition = (close < open and body_size <= hammer_body_to_total_ratio * (high - low)) and (body_size >= min_body_size) and (lower_shadow_size >= min_shadow_size * body_size) and (upper_shadow_size < open_high_error * body_size) and (lower_shadow_size > upper_shadow_size) and (volume > volume[1])
green_inverted_hammer_condition = (close > open and body_size <= hammer_body_to_total_ratio * (high - low)) and (body_size >= min_body_size) and (upper_shadow_size >= min_shadow_size * body_size) and (lower_shadow_size < open_high_error * body_size) and (upper_shadow_size > lower_shadow_size) and (volume > volume[1])

// Plot hammer and inverted hammer signals
plotshape(green_hammer_condition, style=shape.triangleup, location=location.belowbar, color=color.lime, size=size.small, title="Green Hammer")
plotshape(red_inverted_hammer_condition, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="Red Inverted Hammer")
plotshape(red_hammer_condition, style=shape.triangleup, location=location.belowbar, color=color.yellow, size=size.small, title="Red Hammer")
plotshape(green_inverted_hammer_condition, style=shape.triangledown, location=location.abovebar, color=color.maroon, size=size.small, title="Green Inverted Hammer")

// Add alert conditions for bullish engulfing pattern
alertcondition(signal_bullish_engulfing, title="High Volume Bullish Engulfing", message="A high volume bullish engulfing candle has been identified")

// Plot the EMAs on the chart
plot(ema_5, color=color.orange, linewidth=1, title="EMA-5", display = display.none)
plot(ema_9, color=color.purple, linewidth=1, title="EMA-9", display = display.none)
plot(ema_15, color=color.orange, linewidth=2, title="EMA-15")
plot(ema_50, color=color.purple, linewidth=2, title="EMA-50")
plot(ema_100, color=color.teal, linewidth=2, title="EMA-100", display = display.none)
plot(ema_200, color=color.rgb(230, 241, 75), linewidth=2, title="EMA-200", display = display.none)

Conclusion

With this Pine Script code, you can now identify key candlestick patterns like Bullish Engulfing, Bearish Engulfing, Hammer, and Inverted Hammer candles on your TradingView charts. By adding EMAs, you can confirm trends and make more informed trading decisions. This script helps visualize potential reversal and continuation signals, making it a valuable tool in any trader’s toolkit.

Happy trading!

Crafting a Singleton Class in C++ [Intel Interview Ques - 2024]

Ahoy, fellow coders! Today, let’s embark on a thrilling journey into the realm of singleton classes in C++. If you’re not familiar with the term, fear not! A singleton class is like that one legendary sword in a game—you can only wield one of its kind at a time. In other words, it ensures there’s only ever one instance of a class floating around in your code.

The Singleton Quest Begins…

Picture this: you’re building a mighty castle of code, and you stumble upon a need for a class that must exist in a single, glorious instance. That’s where the singleton pattern comes into play!

Step 1: Raise the Drawbridge with a Private Constructor

In the land of singletons, the first rule is simple yet crucial: make the constructor private! This prevents any mischievous outsider from creating instances of your class willy-nilly.

1
2
3
4
5
class Singleton {
private:
Singleton() {} // Private constructor to prevent instantiation
// Additional implementation goes here...
};

Method 1: Meyers’ Singleton - The Heroic Approach

Now, let’s dive into the magical realm of static member functions. Behold, the power of static! With this enchanting keyword, we can summon a single instance of our class.

1
2
3
4
5
6
7
8
9
class Singleton {
private:
Singleton() {} // Private constructor to prevent instantiation
public:
static Singleton& getInstance() {
static Singleton instance;
return instance;
}
};

Here’s how it works: whenever you call getInstance(), it conjures up a static instance if one doesn’t already exist. Otherwise, it simply returns the existing instance, ensuring there’s only one to rule them all! Meyers’ Singleton leverages the mystical properties of static local variables, ensuring that the instance is forged with utmost care and thread safety.

Method 2: The Static Pointer to Glory

But wait, our adventure isn’t over yet! There’s one more method to explore: the static pointer approach. Brace yourselves as we delve deeper into the arcane arts of C++!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Singleton {
private:
Singleton() {} // Private constructor to prevent instantiation
static Singleton* instancePtr; // Static pointer to the instance

public:
static Singleton* getInstance() {
if (!instancePtr) {
instancePtr = new Singleton();
}
return instancePtr;
}
};

Singleton* Singleton::instancePtr = nullptr; // Initializing the static pointer

This method employs a static pointer to the singleton instance, ensuring lazy initialization and a journey free of unnecessary overhead.

Final Step : Complete Code

Copy the below code in a .cpp file and compile the code below using

g++ -s ./c++/cpp_codes/singleton.cpp -o singleton.out

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include<iostream>
#include<bits/stdc++.h>

using namespace std;

class Singleton {
private:
Singleton() {} // Private constructor to prevent instantiation
public:
static Singleton& getInstance() {
static Singleton instance;
return instance;
}
void print(){
cout << "hello world" << endl;
}
};



int main(){
Singleton obj = Singleton::getInstance();
obj.print();
return 0;
}

Special Keyword and

In C++, the static keyword has special significance when applied to member variables and functions:

  • Static Member Variables: When a member variable is declared as static, it means there is only one instance of that variable shared among all instances of the class.
  • Static Member Functions: A static member function is a function that belongs to the class rather than instances of the class. It can be called without an object of the class.

Steps to Implement a Singleton Class:

  • Private Constructor: Ensure that the class has a private constructor to prevent external instantiation.
  • Static Member Function/Object: Provide a static member function or object that returns a reference to the singleton instance.
  • Lazy Initialization: The singleton instance should be created on-demand to conserve resources.
  • Thread Safety (Optional): If the singleton will be accessed by multiple threads, ensure thread safety during initialization. Meyers’ Singleton automatically handles thread safety.

Epilogue: The Singleton Legacy Lives On

And there you have it, intrepid adventurers! By mastering the arcane arts of singleton classes, you’ve unlocked the secrets of controlling class instantiation like a true coding wizard. Whether you choose the static sorcery, the mystical member object, Meyers’ elegance, or the static pointer to glory, remember to wield your singleton powers responsibly in your coding quests!