
Info
Username: | khoshroomahdi |
Name: | Mahdi |
Member since: | 17 Jun 2021 |
About
Signature
Last Algorithm Comments
@AW Moving Cloud: 12 Dec 2021, 22:44
@opit78 how could we have sepeate color for cloud and moving average? for example: different color for fast ema and up cloud.
@AW Moving Cloud: 12 Dec 2021, 22:43
@opit78 May i Use your code to update this indicator?
@Pattern Drawing: 22 Jun 2021, 20:12
why you didin't add this code to internal ctrader tools.? ex: Draw Traingle and fork is better than default tools
@Draw Spread: 18 Jun 2021, 16:54
Please add color parameter. enable $disable label, position on chart parameter
Last Forum Posts
@Add color input parameter in ctrader api: 13 Jan 2022, 09:32
please add this fucntion to api.
ex: i made an indicator that show text on chart. trader have to write name of color. it should be select color like output.
@Lock Charts When zooming in timeframes: 13 Jan 2022, 09:29
it's great
now i made an indicator ( aw vline). you could use that.
but it would be great if ctrader implement it as an internal feature
@add balance graph to statment export: 13 Jan 2022, 09:21
it would be great it when we export statment have graph based on trade not based on time like analyse in ctrader. metatrader is great for this option.
@add duration time to statement: 13 Jan 2022, 09:13
please add duration time column to statement.
trader should know how trade take time.
@macd signal line cross alert: 23 Dec 2021, 21:07
amusleh said:
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)
i make it. thanks for your amazing library.
it is 10 megabyte with source and i couldn't upload in algorithms.
using cAlgo.API;
using cAlgo.API.Alert;
using cAlgo.API.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
public class MacdHistogramAlert : Indicator
{
#region Fields
private MacdHistogram _macdHistogram;
private int _barIndex;
#endregion Fields
#region Parameters
[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; }
[Parameter("Signal Periods", DefaultValue = 9)]
public int Periods { get; set; }
[Parameter("Histogram Alert", DefaultValue = true)]
public bool macdh { get; set; }
[Parameter("Signal Alert", DefaultValue = true)]
public bool macds { get; set; }
#endregion Parameters
#region Outputs
[Output("Macd Up", LineColor = "Green", PlotType = PlotType.Histogram, Thickness = 2)]
public IndicatorDataSeries HistogramPositive { get; set; }
[Output("Macd Down", LineColor = "Red", PlotType = PlotType.Histogram, Thickness = 2)]
public IndicatorDataSeries HistogramNegative { get; set; }
[Output("Signal", LineColor = "Blue", LineStyle = LineStyle.Solid, Thickness = 2)]
public IndicatorDataSeries Signal { get; set; }
#endregion Outputs
#region Methods
protected override void Initialize()
{
_macdHistogram = Indicators.MacdHistogram(Source, LongCycle, ShortCycle, Periods);
}
public override void Calculate(int index)
{
if (_macdHistogram.Histogram[index] > _macdHistogram.Signal[index])
{
HistogramPositive[index] = _macdHistogram.Histogram[index];
}
if (_macdHistogram.Histogram[index] < _macdHistogram.Signal[index])
{
HistogramNegative[index] = _macdHistogram.Histogram[index];
}
Signal[index] = _macdHistogram.Signal[index];
if (macdh)
{
if (_macdHistogram.Histogram[index - 2] <= 0 && _macdHistogram.Histogram[index - 1] > 0)
{
TriggerAlert(TradeType.Buy, index);
}
else if (_macdHistogram.Histogram[index - 2] >= 0 && _macdHistogram.Histogram[index - 1] < 0)
{
TriggerAlert(TradeType.Sell, index);
}
}
if (macds)
{
if (_macdHistogram.Histogram[index - 2] <= _macdHistogram.Signal[index - 2] && _macdHistogram.Histogram[index - 1] > _macdHistogram.Signal[index - 1])
{
TriggerAlert2(TradeType.Buy, index);
}
else if (_macdHistogram.Histogram[index - 2] >= _macdHistogram.Signal[index - 2] && _macdHistogram.Histogram[index - 1] < _macdHistogram.Signal[index - 1])
{
TriggerAlert2(TradeType.Sell, index);
}
}
}
private void TriggerAlert(TradeType tradeType, int index)
{
if (_barIndex != index && IsLastBar)
{
_barIndex = index;
string comment = tradeType == TradeType.Buy ? "Histogram is above 0" : "Histogram is below 0";
Notifications.ShowPopup(TimeFrame, Symbol, tradeType, "MACD Alert", Bars.ClosePrices[index], comment);
}
}
private void TriggerAlert2(TradeType tradeType, int index)
{
if (_barIndex != index && IsLastBar)
{
_barIndex = index;
string comment = tradeType == TradeType.Buy ? "Histogram is above signal" : "Histogram is below signal";
Notifications.ShowPopup(TimeFrame, Symbol, tradeType, "MACD Alert", Bars.ClosePrices[index], comment);
}
}
#endregion Methods
}
}
@macd signal line cross alert: 22 Dec 2021, 21:33
i find this code for macd alert.
cTDN Forum - Adding a Crossover alert (ctrader.com)
i dont' know how to add signal line cross histogram to it?
other problem is about this library. i add it to indicator and now it has 10 megabyte. is there any way to reduce size of this indicator? i just need pop up alert without telegram and email.
how can i add sound to alert?
using cAlgo.API;
using cAlgo.API.Alert;
using cAlgo.API.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
public class MacdHistogramAlert : Indicator
{
#region Fields
private MacdHistogram _macdHistogram;
private int _lastAlertBarIndex;
#endregion Fields
#region Parameters
[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; }
[Parameter("Signal Periods", DefaultValue = 9)]
public int Periods { get; set; }
#endregion Parameters
#region Outputs
[Output("Histogram > 0", PlotType = PlotType.Histogram, Color = Colors.Green, Thickness = 2)]
public IndicatorDataSeries HistogramPositive { get; set; }
[Output("Histogram < 0", PlotType = PlotType.Histogram, Color = Colors.Red, Thickness = 2)]
public IndicatorDataSeries HistogramNegative { get; set; }
[Output("Signal", Color = Colors.Purple, LineStyle = LineStyle.Lines)]
public IndicatorDataSeries Signal { get; set; }
#endregion Outputs
#region Methods
protected override void Initialize()
{
_macdHistogram = Indicators.MacdHistogram(Source, LongCycle, ShortCycle, Periods);
}
public override void Calculate(int index)
{
if (_macdHistogram.Histogram[index] > 0)
{
HistogramPositive[index] = _macdHistogram.Histogram[index];
}
if (_macdHistogram.Histogram[index] < 0)
{
HistogramNegative[index] = _macdHistogram.Histogram[index];
}
Signal[index] = _macdHistogram.Signal[index];
if (_macdHistogram.Histogram[index - 2] <= 0 && _macdHistogram.Histogram[index - 1] > 0)
{
TriggerAlert(TradeType.Buy, index);
}
else if (_macdHistogram.Histogram[index - 2] >= 0 && _macdHistogram.Histogram[index - 1] < 0)
{
TriggerAlert(TradeType.Sell, index);
}
}
private void TriggerAlert(TradeType tradeType, int index)
{
if (index == _lastAlertBarIndex || !IsLastBar)
{
return;
}
string comment = tradeType == TradeType.Buy ? "Histogram is above 0" : "Histogram is below 0";
Notifications.ShowPopup(TimeFrame, Symbol, MarketSeries.Close[index], "MACD Histogram Alert", tradeType, comment);
}
#endregion Methods
}
}
@horizontal line y: 22 Dec 2021, 14:24
thanks
amusleh said:
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.
@horizontal line y: 21 Dec 2021, 15:16
i have cbot manager bot. i want this bot add a horizontal line to my chart and user could change that line.
i want my robot show me volume based my stop lost. and this horizontal line is stop lost that user could modify and move it.
i make that but code doesn't move. and i dont know how could i set y index while robot running in center of chart..
i tried with chart.drawhorionalline but i couldn't access y inedes in my code. and user could'nt move line?
other question: could we have access volume in one click trading in code?
using System;
using System.Linq;
using cAlgo.API;
namespace cAlgo
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class AWCPDaily : Robot
{
TextBlock tb = new TextBlock();
Chart.DrawHorizontalLine 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()
{
Chart.AddControl(sll);
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);
}
}
}
}
}
@How could i add Slowing to this code?: 15 Dec 2021, 22:37
how could i add slowing to this code?
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Levels(1)]
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class AWStochasticLimitless : Indicator
{
private double UpperResult1;
private double LowerResult1;
[Parameter("K% periods 1", DefaultValue = 5)]
public int inpKPeriods1 { get; set; }
[Parameter("K% Slowing", DefaultValue = 1)]
public int inpKSlowing { get; set; }
[Output("K% 1", LineColor = "Black", LineStyle = LineStyle.Dots, Thickness = 2)]
public IndicatorDataSeries k1 { get; set; }
protected override void Initialize()
{
}
public override void Calculate(int index)
{
UpperResult1 = Bars.HighPrices.Maximum(inpKPeriods1);
LowerResult1 = Bars.LowPrices.Minimum(inpKPeriods1);
k1[index] = (Bars.ClosePrices[index]) / ((UpperResult1 + LowerResult1) / 2);
}
}
}