Topics
Forum Topics not found
Replies
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
23 Dec 2021, 09:08
Hi,
What do you mean by: "i dont' know how to add signal line cross histogram to it?"
Can you show this on a chart screenshot?
Not sure about the exact size of library but if you use the newer version library the size might reduce.
You don't need that library to show a popup alert or play a sound alert.
cTrader automate API has the email and sound alert itself under Notifications: cAlgo API Reference - INotifications Interface (ctrader.com)
@amusleh
amusleh
22 Dec 2021, 09:28
Hi,
Please read API references and check the examples there before asking a question: cAlgo API Reference - ChartHorizontalLine Interface (ctrader.com)
Try this:
using System;
using System.Linq;
using cAlgo.API;
namespace cAlgo
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class AWCPDaily : Robot
{
private TextBlock tb = new TextBlock();
private ChartHorizontalLine sll;
[Parameter("Take Profit", DefaultValue = 100)]
public double tp { get; set; }
[Parameter("Stop Profit", DefaultValue = 90)]
public double sl { get; set; }
[Parameter("FontSize", DefaultValue = 16, Group = "Text")]
public int FontSize { get; set; }
[Parameter("Space to Corner", DefaultValue = 10, Group = "Text")]
public int Margin { get; set; }
[Parameter("Horizental Alignment", DefaultValue = HorizontalAlignment.Left, Group = "Text")]
public HorizontalAlignment HAlignment { get; set; }
[Parameter("Vertical Alignment", DefaultValue = VerticalAlignment.Top, Group = "Text")]
public VerticalAlignment VAlignment { get; set; }
[Parameter("Color", DefaultValue = "Red", Group = "Text")]
public string Color1 { get; set; }
[Parameter("Opacity", DefaultValue = 0.7, MinValue = 0.1, MaxValue = 1, Group = "Text")]
public double Opacity { get; set; }
[Parameter("Text Alignment", DefaultValue = TextAlignment.Center, Group = "Text")]
public TextAlignment Alignment { get; set; }
protected override void OnStart()
{
var y = Chart.BottomY + ((Chart.TopY - Chart.BottomY) / 2);
sll = Chart.DrawHorizontalLine("horizontal", y, Color.Red);
sll.IsInteractive = true;
Chart.AddControl(tb);
tb.Text = "sl : " + sl.ToString() + ", " + "tp : " + tp.ToString() + "\n EQ: " + Account.Equity + ", ML%: " + Account.MarginLevel + "\nVP: " + Account.Margin / Account.Balance + "V: " + sll.Y;
tb.FontSize = FontSize;
tb.ForegroundColor = Color1.TrimEnd();
tb.HorizontalAlignment = HAlignment;
tb.VerticalAlignment = VAlignment;
tb.TextAlignment = Alignment;
tb.Margin = Margin;
tb.Opacity = Opacity;
}
protected override void OnTick()
{
foreach (var position in Positions)
{
if (Account.Equity > tp || Account.Equity < sl)
{
ClosePositionAsync(position);
}
}
foreach (var order in PendingOrders)
{
if (Account.Equity > tp || Account.Equity < sl)
{
CancelPendingOrder(order);
}
}
}
}
}
You have to set a chart object IsInteractive property to true, then you will be able to change it on the chart.
@amusleh
amusleh
22 Dec 2021, 09:24
Hi,
Try this:
using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class NewcBot : Robot
{
private BollingerBands _bbands;
protected override void OnStart()
{
_bbands = Indicators.BollingerBands(Bars.ClosePrices, 20, 2, MovingAverageType.Simple);
}
protected override void OnBar()
{
// When a bar crossed upper band from below
if (Bars.Last(2).High < _bbands.Top.Last(2) && Bars.Last(1).High > _bbands.Top.Last(1))
{
}
// When a bar crossed upper band from above
if (Bars.Last(2).Low > _bbands.Top.Last(2) && Bars.Last(1).Low < _bbands.Top.Last(1))
{
}
}
}
}
@amusleh
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:
@amusleh