Description
This bot is based on ADX, Moving Average and Fractals indicator. It uses Fractal indicator to set TP and SL.
It works on all timeframes and assets. Standard parameter working good for 1H EURUSD.
Bot maybe be started simultaneously on several Assets.
------------------
HOW TO INSTALL
- Download and install “Fractals” indicator: https://ctrader.com/algos/indicators/show/142
- Download and install this very cBot: https://ctrader.com/algos/cbots/show/2016
- Refer “Fractals” indicator to “ADX Fractals” bot, see howto here: https://ctrader.com/forum/whats-new/2713
------------------
PARAMETERS
SMA Slow
Slow Simple Moving Average Period
SMA Fast
Fast Simple Moving Average Period
MA Cross
Max periods moving average crossed
ADX Min Value
Direction Movement System Min. Value
ADX Max Value
Direction Movement System Max. Value
Fractal Period
Max Period to Calculate Fractals for the TP and SL
Fractal diff
Pips to add to SL and subtract from TP
Min SL
Minimum SL in pips
Max SL
Maximum SL in pips
Min TP
Minimum TP in pips
Max TP
Maximum TP in pips
Volume Units
Volume to trade in units
using System;
using System.Collections;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class ADXFractals : Robot
{
[Parameter("SMA Slow", DefaultValue = 100, MinValue = 50, MaxValue = 1000, Step = 50)]
public int ma_slow_period { get; set; }
[Parameter("SMA Fast", DefaultValue = 30, MinValue = 10, MaxValue = 100, Step = 10)]
public int ma_fast_period { get; set; }
[Parameter("MA Cross", DefaultValue = 30, MinValue = 10, MaxValue = 200, Step = 10)]
public int param_ma_cross_period { get; set; }
[Parameter("ADX Min Value", DefaultValue = 20, MinValue = 10, MaxValue = 100, Step = 1)]
public int param_adx_min { get; set; }
[Parameter("ADX Max Value", DefaultValue = 40, MinValue = 30, MaxValue = 100, Step = 5)]
public int param_adx_max { get; set; }
[Parameter("Fractal Period", DefaultValue = 10, MinValue = 10, MaxValue = 100, Step = 10)]
public int param_fractal_period { get; set; }
[Parameter("Fractal diff", DefaultValue = 0, MinValue = 0, MaxValue = 10, Step = 1)]
public int param_fractal_diff { get; set; }
[Parameter("Min SL", DefaultValue = 30, MinValue = 5, MaxValue = 100, Step = 1)]
public int param_min_stop_loss { get; set; }
[Parameter("Max SL", DefaultValue = 50, MinValue = 30, MaxValue = 50, Step = 5)]
public int param_max_stop_loss { get; set; }
[Parameter("Min TP", DefaultValue = 30, MinValue = 5, MaxValue = 50, Step = 5)]
public int param_min_take_profit { get; set; }
[Parameter("Max TP", DefaultValue = 50, MinValue = 30, MaxValue = 50, Step = 1)]
public int param_max_take_profit { get; set; }
[Parameter("Volume Units", DefaultValue = 100000, MinValue = 1000, MaxValue = 1000000, Step = 1000)]
public int volume_units { get; set; }
private MovingAverage i_MA_slow;
private MovingAverage i_MA_fast;
private DirectionalMovementSystem i_ADXR;
private RelativeStrengthIndex i_RSI;
private Fractals i_fractal;
protected override void OnStart()
{
i_MA_slow = Indicators.MovingAverage(MarketSeries.Close, ma_slow_period, MovingAverageType.Simple);
i_MA_fast = Indicators.MovingAverage(MarketSeries.Close, ma_fast_period, MovingAverageType.Simple);
i_ADXR = Indicators.DirectionalMovementSystem(20);
i_RSI = Indicators.RelativeStrengthIndex(MarketSeries.Close, 14);
i_fractal = Indicators.GetIndicator<Fractals>(param_fractal_period);
}
protected override void OnTick()
{
if (Positions.FindAll("MA", SymbolName).Length == 0)
{
if (i_ADXR.ADX.LastValue > param_adx_min && i_ADXR.ADX.LastValue < param_adx_max)
if (i_RSI.Result.LastValue < 60)
if (i_MA_fast.Result.HasCrossedAbove(i_MA_slow.Result.LastValue, param_ma_cross_period))
if (Symbol.Bid > i_MA_fast.Result.LastValue)
{
Open_Buy_Order();
return;
}
if (i_ADXR.ADX.LastValue > param_adx_min && i_ADXR.ADX.LastValue < param_adx_max)
if (i_RSI.Result.LastValue > 40)
if (i_MA_fast.Result.HasCrossedBelow(i_MA_slow.Result.LastValue, param_ma_cross_period))
if (Symbol.Bid < i_MA_fast.Result.LastValue)
{
Open_Sell_Order();
return;
}
}
}
private void Open_Buy_Order()
{
double tp = 0, sl = 0;
tp = getTakeProfit(TradeType.Buy);
sl = getStopLoss(TradeType.Buy);
if (tp > param_min_take_profit && tp < param_max_take_profit && sl > param_min_stop_loss && sl < param_max_stop_loss)
ExecuteMarketOrder(TradeType.Buy, SymbolName, volume_units, "MA", sl + param_fractal_diff, tp - param_fractal_diff);
}
private void Open_Sell_Order()
{
double tp = 0, sl = 0;
tp = getTakeProfit(TradeType.Sell);
sl = getStopLoss(TradeType.Sell);
if (tp > param_min_take_profit && tp < param_max_take_profit && sl > param_min_stop_loss && sl < param_max_stop_loss)
ExecuteMarketOrder(TradeType.Sell, SymbolName, volume_units, "MA", sl + param_fractal_diff, tp - param_fractal_diff);
}
private double getTakeProfit(TradeType type)
{
double tp = 0;
if (type == TradeType.Buy)
{
for (int i = i_fractal.UpFractal.Count; i > 0; i--)
{
if (!double.IsNaN(i_fractal.UpFractal[i]))
{
if ((i_fractal.UpFractal[i] - Symbol.Bid) / Symbol.PipSize > param_min_take_profit)
if ((i_fractal.UpFractal[i] - Symbol.Bid) / Symbol.PipSize < param_max_take_profit)
{
tp = (i_fractal.UpFractal[i] - Symbol.Bid) / Symbol.PipSize;
break;
}
}
}
}
if (type == TradeType.Sell)
{
for (int i = i_fractal.DownFractal.Count; i > 0; i--)
{
if (!double.IsNaN(i_fractal.DownFractal[i]))
{
if ((Symbol.Bid - i_fractal.DownFractal[i]) / Symbol.PipSize > param_min_stop_loss)
if ((Symbol.Bid - i_fractal.DownFractal[i]) / Symbol.PipSize < param_max_stop_loss)
{
tp = (Symbol.Bid - i_fractal.DownFractal[i]) / Symbol.PipSize;
break;
}
}
}
}
return tp;
}
private double getStopLoss(TradeType type)
{
double sl = 0;
if (type == TradeType.Buy)
{
for (int i = i_fractal.DownFractal.Count; i > 0; i--)
{
if (!double.IsNaN(i_fractal.DownFractal[i]))
{
if ((Symbol.Bid - i_fractal.DownFractal[i]) / Symbol.PipSize > param_min_stop_loss)
if ((Symbol.Bid - i_fractal.DownFractal[i]) / Symbol.PipSize < param_max_stop_loss)
{
sl = (Symbol.Bid - i_fractal.DownFractal[i]) / Symbol.PipSize;
break;
}
}
}
}
if (type == TradeType.Sell)
{
for (int i = i_fractal.UpFractal.Count; i > 0; i--)
{
if (!double.IsNaN(i_fractal.UpFractal[i]))
{
if ((i_fractal.UpFractal[i] - Symbol.Bid) / Symbol.PipSize > param_min_take_profit)
if ((i_fractal.UpFractal[i] - Symbol.Bid) / Symbol.PipSize < param_max_take_profit)
{
sl = (i_fractal.UpFractal[i] - Symbol.Bid) / Symbol.PipSize;
break;
}
}
}
}
return sl;
}
}
}
sifneosfx
Joined on 22.10.2018
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: ADX Fractals.algo
- Rating: 2.5
- Installs: 11067
- Modified: 13/10/2021 09:54
Comments
Hello
Is there anyway of increasing MAX TP?
When i simply change this in the source course (Max TP only) and try to build, it comes up with an error about the ambiguity of the 'Fractals' (line 55)
Any help greatly appreciated
Thanks
Louis
Hi,
I think this cBot would be better if you can add couple more features such as trailing stop loss, and SL to breakeven. Do you know how can I add these and test it.
Another question is, If it uses Fractals to set SL and TP why do we have to enter min and max for SL and TP? If we change the SL and TP settings would it still use the fractals for SL and TP?
Please let me know. thanks
Hi, a question, why, for the sell part (and the calculation of the stop loss for a short entry), you always use the bid price and not the ask price? Thx for your attention. Regards.
I see on your webpage you use hedge strategy too, Im working on them and I'll try to use the strategy you posted with them. email me at eivaremir@gmail.com if u wanna see results and work together!
The forum link is dead.