Your interactive trading laboratory!
8 users online

SwingHigh SwingLow Bar Indicator
Q Merlin wrote 16 days ago ...

In one of my existing Ninja strategies, i'm using a SwingHigh-SwingLow Bar Indicator where i can define a SwingStrength. In QS, is there a similar indicator available?


Attachment

Cancel

Responses
Q Glitch posted 16 days ago, and edited 16 days ago

The analog in Quantacula would be the PeakTroughCalculator helper class.

Other products call this ZigZag, and take care when using this kind of analysis in a trading strategy, since the detection of peaks and troughs by nature happens after the fact. The Quantacula PeakTroughCalculator provides extra information including the index on which the peak/trough was detected, which will always be a few bars after the actual peak/trough bar itself. Here a grey line is drawn between the peak/trough bar and the bar at which it was detected.

using QuantaculaBacktest;
using System;
using QuantaculaCore;
using QuantaculaIndicators;
using QuantaculaChart;
using System.Drawing;
using System.Collections.Generic;

namespace Quantacula
{
    public class PeakTroughAnalysis : UserModelBase
    {
        //create indicators and other objects here, this is executed prior to the main trading loop
        public override void Initialize(BarHistory bars)
        {
			//perform peak/trough analysis
			PeakTroughCalculator ptc = new PeakTroughCalculator(bars, 5);
			for (int n = 1; n < ptc.PeakTroughs.Count; n++)
			{
				int x1 = ptc.PeakTroughs[n - 1].PeakTroughIndex;
				double y1 = ptc.PeakTroughs[n - 1].Value;
				int x2 = ptc.PeakTroughs[n].PeakTroughIndex;
				double y2 = ptc.PeakTroughs[n].Value;
				DrawLine(x1, y1, x2, y2, Color.Red, LineStyles.Thick);
			}

			//render peak/trough detection delay
			foreach (PeakTrough pt in ptc.PeakTroughs)
			{
				int x1 = pt.PeakTroughIndex;
				int x2 = pt.DetectedAtIndex;
				double y = pt.Value;
				DrawLine(x1, y, x2, y, Color.DarkGray, LineStyles.Solid);
			}
        }
	    
		public override void Execute(BarHistory bars, int idx)
		{
		}
    }
}
The analog in Quantacula would be the [PeakTroughCalculator](https://www.quantacula.com/Help/OpenHelp/csharp/36) helper class. Other products call this ZigZag, and take care when using this kind of analysis in a trading strategy, since the detection of peaks and troughs by nature happens after the fact. The Quantacula PeakTroughCalculator provides extra information including the index on which the peak/trough was detected, which will always be a few bars after the actual peak/trough bar itself. Here a grey line is drawn between the peak/trough bar and the bar at which it was detected. [CODE] using QuantaculaBacktest; using System; using QuantaculaCore; using QuantaculaIndicators; using QuantaculaChart; using System.Drawing; using System.Collections.Generic; namespace Quantacula { public class PeakTroughAnalysis : UserModelBase { //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) { //perform peak/trough analysis PeakTroughCalculator ptc = new PeakTroughCalculator(bars, 5); for (int n = 1; n < ptc.PeakTroughs.Count; n++) { int x1 = ptc.PeakTroughs[n - 1].PeakTroughIndex; double y1 = ptc.PeakTroughs[n - 1].Value; int x2 = ptc.PeakTroughs[n].PeakTroughIndex; double y2 = ptc.PeakTroughs[n].Value; DrawLine(x1, y1, x2, y2, Color.Red, LineStyles.Thick); } //render peak/trough detection delay foreach (PeakTrough pt in ptc.PeakTroughs) { int x1 = pt.PeakTroughIndex; int x2 = pt.DetectedAtIndex; double y = pt.Value; DrawLine(x1, y, x2, y, Color.DarkGray, LineStyles.Solid); } } public override void Execute(BarHistory bars, int idx) { } } } [/CODE]

Forum Tips

Please sign in if you want to participate in our forum.

Our forum uses Markdown syntax to format posts.

To embed code snippets, enclose them in [CODE][/CODE] tags.