Fractals cBot
Fractals cBot
11 Sep 2021, 14:30
Hi,
I am trying to build a fractals cbot, which executes orders when fractals appear in the previous candle, but it does not work. It gives the previous fractal instead of the current fractal.
___________________
using System;
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 NewcBot : Robot
{
[Parameter("Fractal Period", DefaultValue = 5)]
public int _period { get; set; }
[Parameter("Volume", DefaultValue = 1000)]
public double FirstVolume { get; set; }
private Fractals _fractal;
protected override void OnStart()
{
_fractal = Indicators.Fractals(_period);
}
protected override void OnBar()
{
if (Bars.HighPrices.Last(1) == _fractal.UpFractal.Last(0))
{
foreach (var position in Positions)
{
if (position.SymbolName == SymbolName && position.Label == "Fractal")
ClosePosition(position);
}
ExecuteMarketOrder(TradeType.Sell, SymbolName, FirstVolume, "Fractal", null, null, null, false);
}
if (Bars.LowPrices.Last(1) == _fractal.DownFractal.Last(0))
{
foreach (var position in Positions)
{
if (position.SymbolName == SymbolName && position.Label == "Fractal")
ClosePosition(position);
}
ExecuteMarketOrder(TradeType.Buy, SymbolName, FirstVolume, "Fractal", null, null, null, false);
}
}
}
}
Replies
PanagiotisCharalampous
14 Sep 2021, 08:43
Hi cTraderX,
Please note that Fractals indicator is a redrawing indicator. Fractals do not appear immediately but only some candles after. So you cannot expect trades to be placed on the bar immediately after the fractals.
Best Regards,
Panagiotis
Join us on Telegram and Facebook
@PanagiotisCharalampous
jaydcrowe1989
10 Sep 2022, 13:24
RE:
PanagiotisCharalampous said:
Hi cTraderX,
Please note that Fractals indicator is a redrawing indicator. Fractals do not appear immediately but only some candles after. So you cannot expect trades to be placed on the bar immediately after the fractals.
Best Regards,
Panagiotis
How do you determine which arrow was drawn last? I am trying to use the fractals indicator within a bot and I need the latest arrow that was drawn? I seem to be able to get the last up arrow and the last arrow but I have no way of determining which arrow was drawn last or a way of matching an arrow to a bar
@jaydcrowe1989
amusleh
13 Sep 2021, 11:10
Hi,
Try this:
@amusleh