Get values of custom indicator in cBot
Created at 08 Jan 2022, 00:02
Get values of custom indicator in cBot
08 Jan 2022, 00:02
Hi,
I'm trying to get the output values of a custom indicator to work in a cBot. I tried a lot of things and read through many treads on this forum. But I can't get it to work. The indicator works fine visually. On backtest, the cBot always get 0 - no event.
What am I missing / doing wrong? Please help! :)
Thanks in advance
Here is the indicator:
And here is the "work in progress" cBot:
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class Bot3_1 : Robot
{
[Parameter("Quantity (Lots)", Group = "Volume", DefaultValue = 0.1, MinValue = 0.01, Step = 0.01)]
public double Quantity { get; set; }
public enum Multi
{
Pips = 10,
Unit = 100,
Point = 1
}
public enum devi
{
Price = 1,
ATR = 2
}
[Parameter("Deviation Size", Group = "Deviations Settings", DefaultValue = Multi.Unit)]
public Multi Multiplier { get; set; }
[Parameter("Deviation", Group = "Deviations Settings", DefaultValue = 50, MinValue = 1)]
public int Deviation { get; set; }
[Parameter("Sell Histogram Negative", Group = "Histogram Settings", DefaultValue = false)]
public bool change { get; set; }
[Output("UpVolume", LineColor = "DarkViolet", PlotType = PlotType.Histogram, Thickness = 5)]
public IndicatorDataSeries UpVolume { get; set; }
[Output("DownVolume", LineColor = "White", PlotType = PlotType.Histogram, Thickness = 5)]
public IndicatorDataSeries DownVolume { get; set; }
[Parameter("Atr Multiplier", Group = "ATR Settings", DefaultValue = 1.5, MinValue = 0, MaxValue = 10)]
public double atrMultiplier { get; set; }
[Parameter("Atr Period", Group = "ATR Settings", DefaultValue = 13, MinValue = 1)]
public int atrPeriod { get; set; }
[Parameter("Deviation Type", Group = "Deviations Settings", DefaultValue = devi.ATR)]
public devi deviationType { get; set; }
public IndicatorDataSeries Result { get; set; }
public TradeType TradeType { get; set; }
public double ClosePrices { get; set; }
string label = "Bot 3.1";
public Position[] BotPositions
{
get { return Positions.FindAll(label, SymbolName, TradeType); }
}
private double _point;
private DataSeries CurrentClose;
private IndicatorDataSeries Direction;
private IndicatorDataSeries DownBuffer;
private AverageTrueRange _averageTrueRange;
private WeisWavesTraderExperto WWTE { get; set; }
protected override void OnStart()
{
WWTE = Indicators.GetIndicator<WeisWavesTraderExperto>(Multiplier, Deviation, change, atrMultiplier, atrPeriod, deviationType);
Direction = CreateDataSeries();
CurrentClose = Bars.ClosePrices;
DownBuffer = CreateDataSeries();
_point = Symbol.TickSize * (double)Multiplier;
_averageTrueRange = Indicators.AverageTrueRange(atrPeriod, MovingAverageType.Weighted);
}
protected override void OnTick()
{
if (WWTE.UpVolume.Last(1) > 0)
{
{
{
Close(TradeType.Sell);
Open(TradeType.Buy);
}
}
}
if (WWTE.DownVolume.Last(1) > 0)
{
{
{
Close(TradeType.Buy);
Open(TradeType.Sell);
}
}
}
}
private void Close(TradeType tradeType)
{
foreach (var position in Positions.FindAll(label, SymbolName, tradeType))
ClosePosition(position);
}
private void Open(TradeType tradeType)
{
var position = Positions.Find(label, SymbolName, tradeType);
var volumeInUnits = Symbol.QuantityToVolumeInUnits(Quantity);
if (position == null)
ExecuteMarketOrder(tradeType, SymbolName, volumeInUnits, label);
}
}
}
Mia999
08 Jan 2022, 06:34
So I was able to find the solution myself.
For future reference (it might help others), what I have done is: I modified references to be "public" instead of "private" where possible, both in the indicator and in the cBot. And in the cBot, I added { get; set; } to these references where possible.
So the indicator introduction now looks like this (see last section cited herein):
And the cBot introduction now looks like this (see last section cited herein):
Thanks anyway!
@Mia999