Popular:
Write a thinkScript® code to find stocks that have crossed the 20 period EMA.
# Cross above 20 period EMA Scan
input length = 20;
def price = close;
def ema20 = ExpAverage(price, length);
plot Signal = if price > ema20 and price[1] <= ema20[1] then 1 else 0;
# Add label to display stocks where the cross above occurred
AddLabel(yes, if Signal == 1 then "Price crossed above 20 EMA" else "", color.green);
Write a Pine Script™ code to find major support levels on a chart.
//@version=5
indicator("Major Support Levels", overlay=true)
// Define variables
var float prevLow = na
var float currentLow = na
var float supportLevel = na
// Calculate current low
currentLow := low[1]
// If current low is lower than previous low, update support level
if (currentLow < prevLow or na(prevLow))
supportLevel := currentLow
// Plot support level
plot(supportLevel, color=color.green, style=plot.style_linebr)
Python code to find areas of liquidity for a stock.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# Sample historical volume data
dates = pd.date_range(start='2022-01-01', end='2022-01-31')
volume = np.random.randint(10000, 100000, size=len(dates))
# Smooth the volume data to identify significant volume spikes
smoothed_volume = pd.Series(volume).rolling(window=5, min_periods=1).mean()
# Identify areas of liquidity based on volume spikes
liquidity_threshold = 2.5 # Adjust as needed
liquidity_areas = smoothed_volume[smoothed_volume > liquidity_threshold * smoothed_volume.mean()]
# Plotting
plt.figure(figsize=(10, 6))
plt.plot(dates, volume, label='Volume')
plt.plot(dates, smoothed_volume, label='Smoothed Volume', linestyle='--')
plt.scatter(liquidity_areas.index, liquidity_areas.values, color='red', label='Liquidity Areas')
plt.title('Stock Liquidity Analysis')
plt.xlabel('Date')
plt.ylabel('Volume')
plt.legend()
plt.grid(True)
plt.show()
Write a Java code to find stocks that have just had a 52 week low.
import java.util.ArrayList;
import java.util.List;
class Stock {
String symbol;
double price;
public Stock(String symbol, double price) {
this.symbol = symbol;
this.price = price;
}
}
public class Main {
public static void main(String[] args) {
// Assume stocksList contains historical price data of stocks
List<Stock> stocksList = new ArrayList<>();
stocksList.add(new Stock("AAPL", 120.0));
stocksList.add(new Stock("GOOG", 2000.0));
stocksList.add(new Stock("MSFT", 230.0));
// Add more stocks and their prices
// Initialize variables to track 52-week low
double lowestPrice = Double.MAX_VALUE;
List<Stock> lowestStocks = new ArrayList<>();
// Calculate 52-week low
for (Stock stock : stocksList) {
if (stock.price < lowestPrice) {
lowestPrice = stock.price;
lowestStocks.clear();
lowestStocks.add(stock);
} else if (stock.price == lowestPrice) {
lowestStocks.add(stock);
}
}
// Output stocks that have just reached 52-week low
System.out.println("Stocks that have just reached a 52-week low:");
for (Stock stock : lowestStocks) {
System.out.println("Symbol: " + stock.symbol + ", Price: " + stock.price);
}
}
}