Topics
Forum Topics not found
Replies
amusleh
31 Dec 2021, 08:48
Hi,
You can't use the bar counter on chart from Automate API, and there is no need for it.
You can easily code one, each bar has an open time and if you know the time frame you can subtract the bar open time from current time, ex:
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
{
private TimeSpan _barTimeLeft;
protected override void OnStart()
{
Timer.Start(1);
}
protected override void OnTimer()
{
var previousBarTimePeriod = Bars.LastBar.OpenTime - Bars.Last(1).OpenTime;
_barTimeLeft = previousBarTimePeriod - (Server.Time - Bars.LastBar.OpenTime);
// Check logs, it should match with chart counter
Print("{0:hh':'mm':'ss}", _barTimeLeft);
// Close all positions if the time left is less than or equal 10 seconds
if (_barTimeLeft.TotalSeconds <= 10)
{
foreach (var position in Positions)
{
ClosePosition(position);
}
}
}
}
}
@amusleh
amusleh
31 Dec 2021, 07:25
Hi,
Please follow this instruction: Creating an Indicator | cTrader Help Center
@amusleh
amusleh
30 Dec 2021, 15:45
Hi,
Try this:
using System;
using cAlgo.API;
namespace cAlgo.Indicators
{
[Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
public class RoundNumbers : Indicator
{
[Parameter("Line Color", DefaultValue = "Gray")]
public string LineColor { get; set; }
[Parameter("Color", DefaultValue = 255, MinValue = 0, MaxValue = 255)]
public int ColorAlpha { get; set; }
[Parameter(DefaultValue = 100)]
public int StepPips { get; set; }
protected override void Initialize()
{
double max = Bars.HighPrices.Maximum(Bars.HighPrices.Count);
double min = Bars.LowPrices.Minimum(Bars.LowPrices.Count);
double step = Symbol.PipSize * StepPips;
double start = Math.Floor(min / step) * step;
var color = GetColor(LineColor, ColorAlpha);
for (double level = start; level <= max + step; level += step)
{
Chart.DrawHorizontalLine("line_" + level, level, color);
}
}
public override void Calculate(int index)
{
}
private Color GetColor(string colorString, int alpha = 255)
{
var color = colorString[0] == '#' ? Color.FromHex(colorString) : Color.FromName(colorString);
return Color.FromArgb(alpha, color);
}
}
}
You can use any Color name or hexadecimal color code for line color parameter, with Color alpha you can control the color transparency.
@amusleh
amusleh
29 Dec 2021, 08:58
Hi,
Do you mean something like this:
using System;
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 TopYbottomYtest : Indicator
{
[Parameter("Source")]
public DataSeries Source { get; set; }
protected override void Initialize()
{
if (Source == Bars.HighPrices)
{
Print("High Prices");
}
}
public override void Calculate(int index)
{
}
}
}
@amusleh
amusleh
28 Dec 2021, 08:00
Hi,
On your first post you just asked for Bollinger bands cross, you didn't mentioned any other indicator.
When you post code please use the editor "Insert Code Snippet" option.
The issue with your code is invalid indicator index, if you are using this code on a cBot try to use .Last(1) or .Last(2), you shouldn't pass the bar index which starts from beginning because the Last method uses reverse indexing.
And the LastValue property gives you the latest value inside indicator series, you should not use it because it will give non deterministic results as the last value isn't completed yet and it can change.
For more please check code examples on automate API references.
@amusleh
amusleh
24 Dec 2021, 07:57
Hi,
It works fine, try this:
using System;
using cAlgo.API;
using cAlgo.API.Internals;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class TopYbottomYtest : Indicator
{
private double topY, bottomY;
protected override void Initialize()
{
TopBottomYtest();
Chart.ScrollChanged += onscrollchanged;
}
private void onscrollchanged(ChartScrollEventArgs f)
{
TopBottomYtest();
}
private void TopBottomYtest()
{
topY = Math.Round(Chart.TopY, Symbol.Digits);
bottomY = Math.Round(Chart.BottomY, Symbol.Digits);
Chart.DrawStaticText("test", "TOP " + topY.ToString() + " Bottom " + bottomY.ToString(), VerticalAlignment.Bottom, HorizontalAlignment.Center, Color.Red);
Chart.DrawTrendLine("trendlinetesttop", Chart.FirstVisibleBarIndex, Chart.TopY, Chart.LastVisibleBarIndex, Chart.TopY, Color.Red, 30);
Chart.DrawTrendLine("trendlinetestbottom", Chart.FirstVisibleBarIndex, Chart.BottomY, Chart.LastVisibleBarIndex, Chart.BottomY, Color.Red, 30);
}
public override void Calculate(int index)
{
}
}
}
@amusleh
amusleh
24 Dec 2021, 07:51
Hi,
Its possible, please post a job request or contact one of our consultants.
@amusleh
amusleh
23 Dec 2021, 11:25
( Updated at: 21 Dec 2023, 09:22 )
RE: RE: RE:
firemyst said:
amusleh said:
The clouds uses output color which user can change, the color is not hardcoded, the output names are.
How does a user change the output color?
I have several indicators with "clouds" on them and cannot see anywhere in the indicator properties to change the colors of the clouds between the lines -- only the "lines" that make up the indicator.
Nothing in the online API reference seems to indicate how either:
https://ctrader.com/api/reference/cloudattribute
Thank you
Hi,
Did you tried the example indicator on API references?
If one output line goes above the other then the color change to that output line color. you don't have to provide the color for cloud attribute, that's optional.
@amusleh
amusleh
23 Dec 2021, 09:10
RE:
firemyst said:
While a nice feature (and finally catching up with the competition), it would be nice if the Spotware cTrader team even allowed end users to be able to select their own colors rather than what the programmer does!
The @Spotware team needs some sort of human-interface engineer (or someone) when implementing such features -- it's ridiculous that a charting feature with colors is implemented and end users have no way to change/customize it. Certainly doesn't put "traders first".
The clouds uses output color which user can change, the color is not hardcoded, the output names are.
@amusleh
amusleh
31 Dec 2021, 11:55 ( Updated at: 31 Dec 2021, 11:56 )
Hi,
I added line style:
@amusleh