Page 3 of 3
Re: Fractals and Swing Points, Defining Highs and Lows Properly
Posted: Tue Oct 20, 2026 8:04 am
by PTScalper
How to Test in MT4
Compile: Press F7 inside the MetaEditor. Look at the "Errors" tab at the bottom to ensure it says 0 errors, 0 warnings.
Strategy Tester: Go back to your MT4 terminal, press Ctrl+R to open the Strategy Tester, and select your newly compiled EA from the dropdown menu.
Run the Backtest: Choose a pair (e.g., EURUSD), set the period to H1 (1-Hour), check the "Visual Mode" box, and click Start to watch the EA execute crossovers historically.
Re: Fractals and Swing Points, Defining Highs and Lows Properly
Posted: Tue Oct 20, 2026 8:05 am
by PTScalper
This is the Exponential Moving Average (EMA) Crossover strategy written in C# for cTrader's Automate (formerly cAlgo) platform.
cTrader uses a modern, object-oriented API that simplifies position management and volume calculations compared to MetaTrader.
Re: Fractals and Swing Points, Defining Highs and Lows Properly
Posted: Tue Oct 20, 2026 8:05 am
by PTScalper
cTrader cBot Source Code (C#)
Open cTrader, go to the Automate tab on the left menu, click New cBot, name it EMACrossoverBot, and paste this code over the default template:
Code: Select all
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class EMACrossoverBot : Robot
{
// --- Input Parameters ---
[Parameter("Fast EMA Period", Group = "Indicators", DefaultValue = 10)]
public int FastEmaPeriod { get; set; }
[Parameter("Slow EMA Period", Group = "Indicators", DefaultValue = 50)]
public int SlowEmaPeriod { get; set; }
[Parameter("Trade Volume (Lots)", Group = "Risk Management", DefaultValue = 0.1)]
public double VolumeInLots { get; set; }
[Parameter("Stop Loss (Pips)", Group = "Risk Management", DefaultValue = 50)]
public double StopLossPips { get; set; }
[Parameter("Take Profit (Pips)", Group = "Risk Management", DefaultValue = 100)]
public double TakeProfitPips { get; set; }
// --- Global Variables ---
private ExponentialMovingAverage _fastEma;
private ExponentialMovingAverage _slowEma;
private string _botLabel = "EMACrossover";
protected override void OnStart()
{
// Initialize the indicators based on the closing prices
_fastEma = Indicators.ExponentialMovingAverage(Bars.ClosePrices, FastEmaPeriod);
_slowEma = Indicators.ExponentialMovingAverage(Bars.ClosePrices, SlowEmaPeriod);
}
protected override void OnTick()
{
// 1. Check if we already have an open position for this specific bot and symbol
var openPositions = Positions.Count(p => p.SymbolName == SymbolName && p.Label == _botLabel);
if (openPositions > 0)
return;
// 2. Get indicator values for the previous closed candles to avoid repainting
// Last(1) is the previous closed candle, Last(2) is the candle before it
double fastEma1 = _fastEma.Result.Last(1);
double fastEma2 = _fastEma.Result.Last(2);
double slowEma1 = _slowEma.Result.Last(1);
double slowEma2 = _slowEma.Result.Last(2);
// Convert standard lots (e.g., 0.1) into the required volume units (e.g., 10,000)
double volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots);
// 3. BUY LOGIC: Fast EMA crossed ABOVE Slow EMA
if (fastEma1 > slowEma1 && fastEma2 <= slowEma2)
{
ExecuteMarketOrder(TradeType.Buy, SymbolName, volumeInUnits, _botLabel, StopLossPips, TakeProfitPips);
Print("Buy Order Executed");
}
// 4. SELL LOGIC: Fast EMA crossed BELOW Slow EMA
else if (fastEma1 < slowEma1 && fastEma2 >= slowEma2)
{
ExecuteMarketOrder(TradeType.Sell, SymbolName, volumeInUnits, _botLabel, StopLossPips, TakeProfitPips);
Print("Sell Order Executed");
}
}
}
}
Re: Fractals and Swing Points, Defining Highs and Lows Properly
Posted: Tue Oct 20, 2026 8:06 am
by PTScalper
Key Differences from MetaTrader to cTrader
Pips Instead of Points: Unlike MT4 and MT5, which require you to calculate Stop Loss and Take Profit using raw price calculations and broker Points, cTrader natively accepts standard Pips directly in the ExecuteMarketOrder() function. A 50-pip stop loss is simply entered as 50.
Volume in Units: cTrader executes trades based on raw units rather than lots. The built-in Symbol.QuantityToVolumeInUnits(VolumeInLots) function safely converts a standard lot input (like 0.1) into the correct backend units (10,000) for the specific asset you are trading.
.Last() Indexing: While MQL arrays are often indexed backwards using [1] and [2], cTrader uses the .Last() method. Last(0) is the live, fluctuating candle, Last(1) is the most recently closed candle, and Last(2) is the candle before it.
LINQ for Position Management: Managing open trades is handled elegantly using C# LINQ Positions.Count(p => ...). This immediately filters the open trades by the current pair and the bot's specific _botLabel, ensuring it doesn't accidentally count trades opened by you manually or by other bots.
Re: Fractals and Swing Points, Defining Highs and Lows Properly
Posted: Tue Oct 20, 2026 8:06 am
by PTScalper
How to Backtest in cTrader
Build: Click the Build icon (the hammer symbol) at the top of the Automate window. Look at the Build Result tab at the bottom to ensure it says Build Succeeded.
Add an Instance: Click the + icon next to your cBot's name in the left menu to add a new instance. Select your desired pair and timeframe (e.g., EURUSD, h1).
Backtest: Go to the Backtesting tab at the top of the main window. Select your historical date range, click the Play button, and cTrader will generate a highly detailed equity chart and performance breakdown.
Re: Fractals and Swing Points, Defining Highs and Lows Properly
Posted: Fri Oct 30, 2026 7:32 am
by Shadow Trader
Swing highs and lows are the skeleton of price action. A series of higher highs and higher lows suggests an uptrend, and the reverse suggests a downtrend. Breaks of structure mark possible changes.
On one-minute charts, structure shifts constantly. Every small wiggle forms a swing, and the picture depends heavily on how swings are defined. A swing could be a candle with lower candles on each side, or it could require several candles on each side.
A consistent definition helps. For instance, define a swing high as a candle whose high exceeds the highs of the three candles before and after it. Then the structure becomes a rule instead of an impression.
It also helps to separate micro structure from the larger picture. A break of a one-minute swing means little if the fifteen-minute structure points the other way.
Which swing definition is used, and has the structure rule been checked against alternatives?
Re: Fractals and Swing Points, Defining Highs and Lows Properly
Posted: Thu Nov 05, 2026 10:04 am
by Fairman
The "changing the definition when it conflicts with your opinion" line hit home. I've done it more than once, swapping from a three candle fractal to five candles when the three-candle version didn't give the level I wanted. The five-candle one always seems to agree with whatever I already believed.
What helped me was writing the rule down and testing it on a chart I hadn't looked at. On EURUSD M15 I took 100 swing highs and lows, using two candles each side, and checked how often a retest of a marked swing held within 3 pips. It was around 58 percent. Then I did it with one candle each side and the number dropped to about 49 percent, basically a coin flip. That showed me that the smaller wiggles aren't worth marking, which supports your point about not marking everything.
For trading it with a stop, if the last intermediate low sits 14 pips away and I risk 50 dollars, that's about 0.36 lots. It also stops me from placing stops at some random number of pips.
Do you use the same swing order on every pair, or does it need adjusting for something quieter like EURCHF? And do you ever combine the higher-order swing with a trend filter?