Topics
Forum Topics not found
Replies
amusleh
28 Jul 2021, 14:41
Hi,
Your indicator has two outputs, and it should display two lines, not one, it's not a bug.
Even if you don't provide a value for the line it will connect the line by using previous and next values on the output series.
To solve this use DiscontinuousLine or Histogram PlotType:
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class MACDHistogram : Indicator
{
public MacdHistogram MacdHistogram;
[Parameter()]
public DataSeries Source { get; set; }
[Parameter("Long Cycle", DefaultValue = 26)]
public int LongCycle { get; set; }
[Parameter("Short Cycle", DefaultValue = 12)]
public int ShortCycle { get; set; }
[Output("Histogram Up", PlotType = PlotType.DiscontinuousLine, Color = Colors.DodgerBlue)]
public IndicatorDataSeries HistogramPositive { get; set; }
[Output("Histogram Down", PlotType = PlotType.DiscontinuousLine, Color = Colors.Red)]
public IndicatorDataSeries HistogramNegative { get; set; }
protected override void Initialize()
{
MacdHistogram = Indicators.MacdHistogram(Source, LongCycle, ShortCycle, 9);
}
public override void Calculate(int index)
{
HistogramPositive[index] = double.NaN;
HistogramNegative[index] = double.NaN;
if (MacdHistogram.Histogram[index] > 0)
{
HistogramPositive[index] = MacdHistogram.Histogram[index];
}
else if (MacdHistogram.Histogram[index] < 0)
{
HistogramNegative[index] = MacdHistogram.Histogram[index];
}
}
}
}
@amusleh
amusleh
28 Jul 2021, 08:56
Hi,
You can post a job request on the Jobs page or ask one of our consultants to develop your cBot for you.
@amusleh
amusleh
28 Jul 2021, 08:50
Hi,
Try this:
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class AWMultiData : Indicator
{
private TextBlock tb = new TextBlock();
[Parameter("FontSize", DefaultValue = 12)]
public int FontSize { get; set; }
[Parameter("Space to Corner", DefaultValue = 10)]
public int Margin { get; set; }
[Parameter("Horizental Alignment", DefaultValue = HorizontalAlignment.Right)]
public HorizontalAlignment HAlignment { get; set; }
[Parameter("Vertical Alignment", DefaultValue = VerticalAlignment.Bottom)]
public VerticalAlignment VAlignment { get; set; }
[Parameter("Color", DefaultValue = "Red")]
public string Color1 { get; set; }
[Parameter("Opacity", DefaultValue = 0.7, MinValue = 0.1, MaxValue = 1)]
public double Opacity { get; set; }
[Parameter("Text Alignment", DefaultValue = TextAlignment.Center)]
public TextAlignment Alignment { get; set; }
protected override void Initialize()
{
Chart.AddControl(tb);
}
public override void Calculate(int index)
{
if (IsLastBar)
DisplaySpreadOnChart();
}
public void DisplaySpreadOnChart()
{
// Calc Spread
var spread = Math.Round(Symbol.Spread / Symbol.PipSize, 2);
string sp = string.Format("{0}", spread);
//Calc daily Net Profit
double DailyNet1 = Positions.Sum(p => p.NetProfit);
double DailyNet2 = History.Where(x => x.ClosingTime.Date == Time.Date).Sum(x => x.NetProfit);
double DailyNet = Math.Round(DailyNet1 + DailyNet2, 2);
var oldTrades = History.Where(x => x.ClosingTime.Date != Time.Date).OrderBy(x => x.ClosingTime).ToArray();
// get Starting Balance
double StartingBalance = oldTrades.Length > 0 ? oldTrades.Last().Balance : Account.Balance;
//calc Daily Percent Profit
string DailyPercent = Math.Round(DailyNet / StartingBalance * 100, 2).ToString();
//text property
tb.Text = Symbol.Name + ", " + TimeFrame.ShortName + "\n" + StartingBalance + "\n" + DailyPercent + " %" + "\n" + DailyNet + " $" + "\n" + sp;
tb.FontSize = FontSize;
tb.ForegroundColor = Color1.TrimEnd();
tb.HorizontalAlignment = HAlignment;
tb.VerticalAlignment = VAlignment;
tb.TextAlignment = Alignment;
tb.Margin = Margin;
tb.Opacity = Opacity;
}
}
}
@amusleh
amusleh
27 Jul 2021, 13:33
RE: RE: RE: RE: Exactly same issue
mohanrajdeenadayalan said:
pepperstoneiphone 11 Pro 256 GB
iphone software 14.6
c trader version 4.1.54294
amusleh said:
witmq said:
myrtlegonzalez73 said:
Hello,
I've been troubleshooting this same problem as well, where it wont connect to ctrader server on Telstra 4G mobile network, seems to
be after a recent update, where its been rock solid for last 6 months.I also tried the legacy app with same symtoms.
I have also updated to IOS 14.4.2 on both iphone x and ipad and doesn't work on 4G network and works always when on wifi network
I couldn't see how the ISP blocking as the same device same IOS same app that wont connect on 4G connects immediately on telstra wifi
I've also deleted the app and its data and re signed in again and get exact same issue
Lastly I just tried connecting from ipad wifi only device using my ios iPhone as hotspot and works yet wont work directly from iphone unless it is connection to wifi.
Hi there,
I’ve been on undergoing with exactly the same issue and advised from Telstra support to contact CTrader support as per case ref.# 16500936. At the moment I’m looking forward to what solution of it.
Hi,
Can you give me these details please:
- Your broker name
- cTrader app version
- Your phone model
- Your phone OS version
Hi,
Thank you for providing the detail, we will continue our investigation and we will update you ASAP.
@amusleh
amusleh
27 Jul 2021, 12:22
RE: RE: Exactly same issue
witmq said:
myrtlegonzalez73 said:
Hello,
I've been troubleshooting this same problem as well, where it wont connect to ctrader server on Telstra 4G mobile network, seems to
be after a recent update, where its been rock solid for last 6 months.I also tried the legacy app with same symtoms.
I have also updated to IOS 14.4.2 on both iphone x and ipad and doesn't work on 4G network and works always when on wifi network
I couldn't see how the ISP blocking as the same device same IOS same app that wont connect on 4G connects immediately on telstra wifi
I've also deleted the app and its data and re signed in again and get exact same issue
Lastly I just tried connecting from ipad wifi only device using my ios iPhone as hotspot and works yet wont work directly from iphone unless it is connection to wifi.
Hi there,
I’ve been on undergoing with exactly the same issue and advised from Telstra support to contact CTrader support as per case ref.# 16500936. At the moment I’m looking forward to what solution of it.
Hi,
Can you give me these details please:
- Your broker name
- cTrader app version
- Your phone model
- Your phone OS version
@amusleh
amusleh
26 Jul 2021, 09:14
( Updated at: 09 Feb 2023, 11:43 )
Hi,
Please follow this tutorial: https://spotware.github.io/open-api-docs/symbol-data/#historical-bars-data
If you still had the same issue then please post your broker name and we will test.
@amusleh
amusleh
26 Jul 2021, 08:44
Hi,
You can use Symbol.Bid or Symbol.Ask if you want to get the latest Bid/Ask price of a symbol.
If you want to get the latest bar close Price you can use Bars.ClosePrices.LastValue.
For historical bars, you can use the Bars collection index and iterate over them.
@amusleh
amusleh
26 Jul 2021, 08:41
Hi,
Try this:
using cAlgo.API;
using System.Linq;
using System;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class AWBoxOffline : Indicator
{
private ChartVerticalLine _vl;
private ChartRectangle _box;
[Parameter("Period", DefaultValue = 26, MinValue = 1)]
public int Period { get; set; }
[Parameter("Line Color", DefaultValue = "Red", Group = "Line")]
public string LineColor { get; set; }
[Parameter("LineStyle", DefaultValue = LineStyle.LinesDots, Group = "Line")]
public LineStyle ls { get; set; }
[Parameter("Thickness", DefaultValue = 2, Group = "Line")]
public int Thickness { get; set; }
protected override void Initialize()
{
_vl = Chart.DrawVerticalLine("scrollLine", Chart.LastVisibleBarIndex, Color.FromName(LineColor), Thickness, ls);
_vl.IsInteractive = true;
var verticalLineBarIndex = Bars.OpenTimes.GetIndexByTime(_vl.Time);
_box = Chart.DrawRectangle("rectangle_sample", verticalLineBarIndex, Bars.LowPrices.Minimum(Period), verticalLineBarIndex - Period, Bars.HighPrices.Maximum(Period), Color.FromArgb(100, Color.Red));
_box.IsFilled = true;
_box.IsInteractive = false;
_box.IsFilled = false;
_box.Thickness = 3;
Chart.ObjectsUpdated += Chart_ObjectsUpdated;
}
private void Chart_ObjectsUpdated(ChartObjectsUpdatedEventArgs obj)
{
if (!obj.ChartObjects.Contains(_vl)) return;
var verticalLineBarIndex = Bars.OpenTimes.GetIndexByTime(_vl.Time);
_box.Time1 = Bars.OpenTimes[verticalLineBarIndex];
_box.Time2 = Bars.OpenTimes[verticalLineBarIndex - Period];
_box.Y1 = GetMinimum(Bars.LowPrices, verticalLineBarIndex, Period);
_box.Y2 = GetMaximum(Bars.HighPrices, verticalLineBarIndex, Period);
}
private double GetMinimum(DataSeries source, int index, int periods)
{
double min = double.MaxValue;
var lastBarIndex = index - periods;
for (int i = index; i > lastBarIndex; i--)
{
min = Math.Min(min, source[i]);
}
return min;
}
private double GetMaximum(DataSeries source, int index, int periods)
{
double max = double.MinValue;
var lastBarIndex = index - periods;
for (int i = index; i > lastBarIndex; i--)
{
max = Math.Max(max, source[i]);
}
return max;
}
public override void Calculate(int index)
{
}
}
}
@amusleh
amusleh
26 Jul 2021, 08:33
Hi,
cTrader doesn't have such a feature, but you can do it with a custom indicator.
Create your double Stochastic indicator and then use chart controls for showing/hiding one of the indicator outputs.
If the hide button got clicked you can fill the whole indicator output with NAN and it will disappear.
@amusleh
amusleh
24 Jul 2021, 16:21
Hi,
Your code is not correct at all! you should use instead Chart ObjectsUpdated event:
using cAlgo.API;
using System.Linq;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class AWBoxOffline : Indicator
{
private ChartVerticalLine _vl;
private ChartRectangle _box;
[Parameter("Period", DefaultValue = 26, MinValue = 1)]
public int Period { get; set; }
[Parameter("Line Color", DefaultValue = "Red", Group = "Line")]
public string LineColor { get; set; }
[Parameter("LineStyle", DefaultValue = LineStyle.LinesDots, Group = "Line")]
public LineStyle ls { get; set; }
[Parameter("Thickness", DefaultValue = 2, Group = "Line")]
public int Thickness { get; set; }
protected override void Initialize()
{
_vl = Chart.DrawVerticalLine("scrollLine", Chart.LastVisibleBarIndex, Color.FromName(LineColor), Thickness, ls);
_vl.IsInteractive = true;
var verticalLineBarIndex = Bars.OpenTimes.GetIndexByTime(_vl.Time);
_box = Chart.DrawRectangle("rectangle_sample", verticalLineBarIndex, Bars.LowPrices.Minimum(Period), verticalLineBarIndex - Period, Bars.HighPrices.Maximum(Period), Color.FromArgb(100, Color.Red));
_box.IsFilled = true;
_box.IsInteractive = false;
_box.IsFilled = false;
_box.Thickness = 3;
Chart.ObjectsUpdated += Chart_ObjectsUpdated;
}
private void Chart_ObjectsUpdated(ChartObjectsUpdatedEventArgs obj)
{
if (!obj.ChartObjects.Contains(_vl)) return;
var verticalLineBarIndex = Bars.OpenTimes.GetIndexByTime(_vl.Time);
_box.Time1 = Bars.OpenTimes[verticalLineBarIndex];
_box.Time2 = Bars.OpenTimes[verticalLineBarIndex - Period];
}
public override void Calculate(int index)
{
}
}
}
The above code only works for past bars, not future, the best way is to use Time instead of Bars index.
@amusleh
amusleh
28 Jul 2021, 14:47
Hi,
Try this:
@amusleh