How To Calculate Ichimoku Cloud in Dart?

by tressie.damore , in category: Third Party Scripts , 8 months ago

How To Calculate Ichimoku Cloud in Dart?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by jasen_gottlieb , 8 months ago

@tressie.damore 

To calculate the Ichimoku Cloud in Dart, you will need to follow these steps:

  1. Define the required variables: Conversion Line (Tenkan-sen), Base Line (Kijun-sen), Leading Span A, Leading Span B, and Lagging Span.
  2. Calculate the Conversion Line (Tenkan-sen): Find the average of the highest high and the lowest low over the last 9 periods.
  3. Calculate the Base Line (Kijun-sen): Find the average of the highest high and the lowest low over the last 26 periods.
  4. Calculate the Leading Span A: (Conversion Line + Base Line) / 2. This line represents the midpoint of the Conversion Line and the Base Line and is plotted 26 periods ahead.
  5. Calculate the Leading Span B: Find the average of the highest high and the lowest low over the last 52 periods. This line is plotted 26 periods ahead.
  6. Calculate the Lagging Span: The closing price of the current period plotted 26 periods behind.
  7. Plot the Ichimoku Cloud on a chart by filling the area between Leading Span A and Leading Span B with different colors to represent bullish or bearish trends.


Here's a sample code snippet in Dart to calculate the Ichimoku Cloud:

 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
void calculateIchimokuCloud(List<double> highs, List<double> lows, List<double> closes) {
  // Calculate Conversion Line (Tenkan-sen)
  double tenkanSen = (highs.reduce(max) + lows.reduce(min)) / 2;

  // Calculate Base Line (Kijun-sen)
  double kijunSen = (highs.getRange(0, 26).reduce(max) + lows.getRange(0, 26).reduce(min)) / 2;

  // Calculate Leading Span A
  double leadingSpanA = (tenkanSen + kijunSen) / 2;

  // Calculate Leading Span B
  double leadingSpanB = (highs.getRange(0, 52).reduce(max) + lows.getRange(0, 52).reduce(min)) / 2;

  // Calculate Lagging Span
  double laggingSpan = closes[26];

  print('Tenkan-sen: $tenkanSen');
  print('Kijun-sen: $kijunSen');
  print('Leading Span A: $leadingSpanA');
  print('Leading Span B: $leadingSpanB');
  print('Lagging Span: $laggingSpan');
}

void main() {
  List<double> highs = [100, 105, 110, 108, 115, 112, 120, 118, 125, 123];
  List<double> lows = [95, 100, 105, 103, 110, 108, 115, 113, 120, 118];
  List<double> closes = [98, 103, 108, 106, 113, 110, 118, 116, 123, 121];

  calculateIchimokuCloud(highs, lows, closes);
}


In this code snippet, we calculate the required values for the Ichimoku Cloud using sample data for highs, lows, and closes. You can replace the sample data with your actual stock price data to get the Ichimoku Cloud values for a specific asset.