Description
Add target/stop colored shapes on pending orders similar to Trading View Tool
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 TradingOrderLines : Indicator
{
[Parameter("TP Color", DefaultValue = "8065FE66")]
public string TPColor { get; set; }
[Parameter("SL Color", DefaultValue = "80FF999A")]
public string SLColor { get; set; }
[Output("Main")]
public IndicatorDataSeries Result { get; set; }
protected override void Initialize()
{
PendingOrders.Cancelled += OnPendingOrdersCancelled;
PendingOrders.Created += OnPendingOrdersCreated;
PendingOrders.Filled += OnPendingOrdersFilled;
PendingOrders.Modified += OnPendingOrdersModified;
foreach (var order in PendingOrders)
{
DrawShapes(order);
}
}
void OnPendingOrdersCancelled(PendingOrderCancelledEventArgs obj)
{
RemoveShapes(obj.PendingOrder);
}
void OnPendingOrdersCreated(PendingOrderCreatedEventArgs obj)
{
DrawShapes(obj.PendingOrder);
}
void OnPendingOrdersFilled(PendingOrderFilledEventArgs obj)
{
RemoveShapes(obj.PendingOrder);
}
void OnPendingOrdersModified(PendingOrderModifiedEventArgs obj)
{
DrawShapes(obj.PendingOrder);
}
void DrawShapes(PendingOrder order)
{
var start = Bars.ClosePrices.Count - 1;
var end = start + 20;
if (order.TakeProfit.HasValue)
{
var rect = Chart.DrawRectangle("TP" + order.Id, start, order.TargetPrice, end, order.TakeProfit.Value, Color.FromHex(TPColor));
rect.IsFilled = true;
}
if (order.StopLoss.HasValue)
{
var rect = Chart.DrawRectangle("SL" + order.Id, start, order.TargetPrice, end, order.StopLoss.Value, Color.FromHex(SLColor));
rect.IsFilled = true;
}
}
void RemoveShapes(PendingOrder order)
{
Chart.RemoveObject("TP" + order.Id);
Chart.RemoveObject("SL" + order.Id);
}
public override void Calculate(int index)
{
}
}
}
reyx
Joined on 16.02.2019
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: TradingOrderLines.algo
- Rating: 2.5
- Installs: 2961
- Modified: 13/10/2021 09:54
Note that publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section, please use the Copyright Infringement Notification form to submit a claim.
Comments
Log in to add a comment.
Could you plz support market order?