kippod
kippod 02 Dec 2023, 13:23 ( Updated at: 04 Dec 2023, 08:32 )
firemyst said:
Can you post example code and example output that demonstrates your issue?
Hi firemystThank you for your time.
Actually I don't get any error it just doesn't workhere's the code
(This is not my bot, it just shows you the problem)
using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class FractalsSample : Robot { private double _volumeInUnits; private Fractals _fractals; [Parameter("Volume (Lots)", DefaultValue = 0.01)] public double VolumeInLots { get; set; } [Parameter("Stop Loss (Pips)", DefaultValue = 10)] public double StopLossInPips { get; set; } [Parameter("Take Profit (Pips)", DefaultValue = 10)] public double TakeProfitInPips { get; set; } [Parameter("Label", DefaultValue = "Sample")] public string Label { get; set; } public Position[] BotPositions { get { return Positions.FindAll(Label); } } protected override void OnStart() { _volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots); _fractals = Indicators.Fractals(5); } protected override void OnBar() { if (_fractals.UpFractal.LastValue < Bars.ClosePrices.Last(1)) { ClosePositions(TradeType.Sell); ExecuteMarketOrder(TradeType.Buy, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips); } else if (_fractals.DownFractal.LastValue > Bars.ClosePrices.Last(1)) { ClosePositions(TradeType.Buy); ExecuteMarketOrder(TradeType.Sell, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips); } } private void ClosePositions(TradeType tradeType) { foreach (var position in BotPositions) { if (position.TradeType != tradeType) continue; ClosePosition(position); } } } }// i just want to call previous fractals
kippod
02 Dec 2023, 13:23 ( Updated at: 04 Dec 2023, 08:32 )
RE: _
firemyst said:
Hi firemyst
Thank you for your time.
Actually I don't get any error it just doesn't work
here's the code
(This is not my bot, it just shows you the problem)
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class FractalsSample : Robot
{
private double _volumeInUnits;
private Fractals _fractals;
[Parameter("Volume (Lots)", DefaultValue = 0.01)]
public double VolumeInLots { get; set; }
[Parameter("Stop Loss (Pips)", DefaultValue = 10)]
public double StopLossInPips { get; set; }
[Parameter("Take Profit (Pips)", DefaultValue = 10)]
public double TakeProfitInPips { get; set; }
[Parameter("Label", DefaultValue = "Sample")]
public string Label { get; set; }
public Position[] BotPositions
{
get
{
return Positions.FindAll(Label);
}
}
protected override void OnStart()
{
_volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots);
_fractals = Indicators.Fractals(5);
}
protected override void OnBar()
{
if (_fractals.UpFractal.LastValue < Bars.ClosePrices.Last(1))
{
ClosePositions(TradeType.Sell);
ExecuteMarketOrder(TradeType.Buy, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
}
else if (_fractals.DownFractal.LastValue > Bars.ClosePrices.Last(1))
{
ClosePositions(TradeType.Buy);
ExecuteMarketOrder(TradeType.Sell, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
}
}
private void ClosePositions(TradeType tradeType)
{
foreach (var position in BotPositions)
{
if (position.TradeType != tradeType) continue;
ClosePosition(position);
}
}
}
}
// i just want to call previous fractals
@kippod