GET    /api/MarketCycles/{symbol}

End of Day dominant cycle analysis for 3,000 US companies, major global market indices, commodities and foreign exchange rates. Returns current dominant cycle.

Input:

  • Symbol/Market to analyze for current dominant cycle.
  • Range (min/max) to scan for actual dominant cycle length and last date to use.

Output:

  • Current dominant cycle length in bars
  • Cycle info (amplitude, phase)
  • Human readable last cycle pivots as bar offset from last bar (lastlow, lasttop)
  • Human readable next cycle pivots as bot offsets from last bar (nextlow, nexttop)
  • Human readable current cycle phase (e.g. approaching top)
  • Profitability score for trading the detected cycle against the price dataset
  • Phasing Score to show the combined phase status for current long- and short-term cycle on a scale from (-200 to +200
  • Full timeseries datapoints with cycle value, price-cycle and close to plot a chart with dominant cycle as indicator

Example Request:

https://api.marketcycles.online/api/MarketCycles/EURJPY?marketType=FX&api_Key=wttpreview

Index – marketType: INDEX

Examples: DJIA, SP500

Federal Reserve Bank of St. Louis – FRED – Check Symbols

Forex – marketType: FX

Examples: EURUSD, EURJPY

Quandl – ECB – Check Symbols

Commodities – marketType: COM

Examples: AG_USD (Silver) , AU_LPM (Gold)

Quandl – WIKI Commodities – Check Symbols

Stocks – marketType: STOCKS

Examples: AAPL, MSFT

Quandl – WIKI EOD Stocks – Check Symbols

Crypto Currencies – marketType: CRYPTO

Examples: BTC (Bitcoin USD), ETH (Ethereum USD)

CryptoCompare –  USD Toplist – Check Symbols

The following example uses a php function to add a new shortcode (marketcycles symbol=… market=…) to wordpress site:

Usage:
Add the following shortcode to a wordpress page to see the current dominant cycles for major indices:

(marketcycles symbol=”SP500,DJIA,NASDAQ100,NIKKEI225,VIXCLS” market=”INDEX”)

Output:

SymbolDatePriceCycle PhasePhasing ScoreCycle LengthNext Cycle PivotBars to Go
SP500January 24, 20203295.47TOP_Departure19548Top0.3
DJIAJanuary 24, 202028989.73Uptrend_Neutral18054Top11.7
NASDAQ100January 24, 20209141.47Downtrend_Starting20047Low21.1
NIKKEI225January 24, 202023827.18Downtrend_Starting-20161Low68.1
VIXCLSJanuary 23, 202012.98TOP_Departure-19531Top0.5

Example page:
See here: https://www.whentotrade.com/dominant-market-cycles/

PHP Backend:
Add the following code to your functions.php file:

// Add marketcycles shortcode
function wtt_marketcycles( $atts ) {

	// get symbol and market from attributes
	$a = shortcode_atts( array(
        'symbol' => 'DJIA',
        'market' => 'INDEX',
    ), $atts );

	$symbols = explode(',', $a['symbol']);

	$table="

<table>";
	$table.="

<tr class='avia-heading-row'>

<th class='avia-desc-col'>Symbol</th>


<th class='avia-desc-col'>Date</th>


<th class='avia-desc-col'>Price</th>


<th class='avia-desc-col'>Cycle Phase</th>


<th class='avia-desc-col'>Phasing Score</th>


<th class='avia-desc-col'>Cycle Length</th>


<th class='avia-desc-col'>Next Cycle Pivot</th>


<th class='avia-desc-col'>Bars to Go</th>

</tr>

";

	foreach ($symbols as $symbol) {

		$cacheKey="CycleExplorer_{$symbol}_{$a['market']}";
		$newload="cached";
		if(($body = get_transient($cacheKey)) === false) 
		{
			
			$wttapi="https://api.marketcycles.online/api/MarketCycles/{$symbol}?marketType={$a['market']}&api_Key=***YOURKEY****";

			$body = wp_remote_retrieve_body( wp_remote_get( $wttapi ) );
			set_transient($cacheKey, $body, 3600);
			$newload="newload";
		} 

		if (isset($body) && $body !== '') {
			//If something went wrong, $body would then be empty, so you’d have to check for that
			$cycle = json_decode($body, true);
			if ($cycle['nextlow'] > $cycle['nexttop'])
			{
				$nextpivotbars=$cycle['nexttop'];
				$nextpivottype="Top";
			} else
			{
				$nextpivotbars=$cycle['nextlow'];
				$nextpivottype="Low";
			}

			if (strpos($cycle['phase_status'], 'TOP') !== false) {
				$backcolor='LightPink';
			} else if (strpos($cycle['phase_status'], 'BOTTOM') !== false) {
				$backcolor='LightGreen';
			} else {
				$backcolor='';
			}

			if ($cycle['PhasingScore'] > 190) {
				$pbackcolor='LightPink';
			} else if ($cycle['PhasingScore'] < -190) {
				$pbackcolor='LightGreen';
			} else {
				$pbackcolor='';
			}

			$mydate=date("F j, Y", strtotime($cycle&#91;'AnalysisEndDate'&#93;));
			$table.="

<tr class='avia-heading-row'>".sprintf("

<td>%s</td>


<td>%s</td>


<td>%.2f</td>


<td bgcolor='%s'>%s</td>


<td bgcolor='%s'>%s</td>


<td>%s</td>


<td>%s</td>


<td>%.1f</td>

", $cycle['Symbol'], $mydate, $cycle['currentPrice'], $backcolor, $cycle['phase_status'], $pbackcolor, $cycle['PhasingScore'], $cycle['length'], $nextpivottype, $nextpivotbars)."</tr>

";

		}
	}

	$table.="</table>

";

	return $table;

}
add_shortcode( 'marketcycles', 'wtt_marketcycles' );

To get you started quickly, we provide a short Excel sheet which allows to pull up dominant cycle information for EOD ticker symbols and to plot the chart with cycle as indicator. We just use the PowerQuery functions available in Excel to connect to external data-sources.

You can dowload the ready-made pre-build workbook down below. If you want to build a workbook on your own, the quick steps are:

  1. Create & setup a table named “Parameter” where all API parameters are available:
  2. Create a new query from web
  3. Enter an example API call in the windowe.g.: https://api.marketcycles.online/api/CycleExplorer/EURJPY?marketType=FX&api_Key=wttpreview
  4. Switch to “Home” / “Advanced Editor”
  5. Change or Edit the power queryThe PowerQuery to get all chart data is:
    let
      //GET THE PARAMETER FROM TABLE
      Parameter = Excel.CurrentWorkbook(){[Name="Parameter"]}[Content],
      sym = Parameter{0}[Value],
      mt = Parameter{1}[Value],
      ad = Parameter{2}[Value],
      min = Number.ToText(Parameter{3}[Value], "D", "") ,
      max = Number.ToText(Parameter{4}[Value], "D", "") ,
      forward = Number.ToText(Parameter{5}[Value], "D", "") ,
      fillweekdays = Parameter{6}[Value],
      apikey = Parameter{7}[Value],
    
      //API URL ENDPOINT
      URL="https://api.marketcycles.online/api/MarketCycles/"&sym, 
      Source = Json.Document(Web.Contents(URL,
      [Query=[ #"marketType"=mt , #"analysisDate"=ad, #"minCycleLength"=min, #"maxCycleLength"=max, 
      #"plotForward"=forward, #"fillMissingWeekdays"=fillweekdays, #"includeTimeseries"="true",
      #"api_Key"=apikey] 
      ])),
     
      //GET THE TIMESERIES ARRAY
      TimeSeries = Source[TimeSeries],
    
      //CONVERT TO EXCEL TABLE
      #"TimeSeries to Table" = Table.FromList(TimeSeries, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
      #"Expanded Records" = Table.ExpandRecordColumn(#"TimeSeries to Table", "Column1", 
      { "date", "price", "dominantCycle", "cycleHighlighter"}, 
      { "date", "price", "dominantCycle", "cycleHighlighter"}),
      #"Changed Type" = Table.TransformColumnTypes(#"Expanded Records",{{"date", type date}})
      in
      #"Changed Type"
  6. If needed, you need to change the privacy settings to allow data loading from external sources

Download Excel file with power query: