Description
Robot Create For Pending Order before the News, Exactly on second
Parameters:
- News Hour UTC - Hour when news will be published
- News Minute - Minute when news will be published
- Pips away - The number of pips away from the current market price where the pending buy and sell orders will be placed.
- Take Profit - Take Profit in pips for each order
- Stop Loss - Stop Loss in pips for each order
- Volume - trading volume
- Seconds before - Seconds Before News when robota will place Pending Orders
- Seconds timeout - Seconds After News when Pending Orders will be deleted
- One Cancels Other - If "Yes" then when one order will be filled, another order will be deleted
If you have any questions or need to code a robot or change don't hesitate to contact me at
Email: Nghiand.amz@gmail.com Telegram: https://t.me/ndnghia
You can find all bot at https://gumroad.com/nghia312
Donate me at https://nghia312.gumroad.com/l/yagsz
using System;
using System.Diagnostics;
using System.Linq;
using System.Text;
using cAlgo.API;
using Button = cAlgo.API.Button;
using HorizontalAlignment = cAlgo.API.HorizontalAlignment;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
public class NewsRobot : Robot
{
[Parameter("News Hour UTC", DefaultValue = 14, MinValue = 0, MaxValue = 23)]
public int NewsHour { get; set; }
[Parameter("News Minute", DefaultValue = 30, MinValue = 0, MaxValue = 59)]
public int NewsMinute { get; set; }
[Parameter("Pips away", DefaultValue = 10)]
public int PipsAway { get; set; }
[Parameter("Take Profit", DefaultValue = 50)]
public int TakeProfit { get; set; }
[Parameter("Stop Loss", DefaultValue = 10)]
public int StopLoss { get; set; }
[Parameter("Lot", DefaultValue = 1, MinValue = 0)]
public double Lot { get; set; }
[Parameter("Seconds Before", DefaultValue = 10, MinValue = 1)]
public int SecondsBefore { get; set; }
[Parameter("Seconds Timeout", DefaultValue = 10, MinValue = 1)]
public int SecondsTimeout { get; set; }
[Parameter("One Cancels Other")]
public bool Oco { get; set; }
[Parameter("ShowTimeLeftNews", DefaultValue = false)]
public bool ShowTimeLeftToNews { get; set; }
[Parameter("ShowTimeLeftPlaceOrders", DefaultValue = true)]
public bool ShowTimeLeftToPlaceOrders { get; set; }
private bool _ordersCreated;
private DateTime _triggerTimeInServerTimeZone;
private const string Label = "News Robot";
protected override void OnStart()
{
Positions.Opened += OnPositionOpened;
Positions.Closed += Positions_Closed;
var btnDonate = new Button()
{
Text = "DONATE",
Margin = 5,
BackgroundColor=Color.Green
};
btnDonate.Click += btnDonate_Click;
var stackPanel = new StackPanel()
{
Width = 120,
HorizontalAlignment = HorizontalAlignment.Left
};
stackPanel.AddChild(btnDonate);
Chart.AddControl(stackPanel);
Timer.Start(1);
}
private void Positions_Closed(PositionClosedEventArgs obj)
{
var position = obj.Position;
if (position.Label == Label && position.SymbolName == SymbolName)
{
if (position.NetProfit > 100)
{
MessageBoxResult targetMessageResult = API.MessageBox.Show("Congratulation you've won, donate to developer?",
"Congratulation!!", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (targetMessageResult == MessageBoxResult.Yes)
{
StartDonate();
}
}
Stop();
}
}
private void btnDonate_Click(ButtonClickEventArgs obj)
{
StartDonate();
}
private void StartDonate()
{
ProcessStartInfo sInfo = new ProcessStartInfo("https://nghia312.gumroad.com/l/yagsz");
sInfo.UseShellExecute = true;
Process.Start(sInfo);
}
protected override void OnTimer()
{
var trigTime = Server.Time;
_triggerTimeInServerTimeZone = new DateTime(trigTime.Year, trigTime.Month, trigTime.Day, NewsHour, NewsMinute, 0);
var remainingTime = _triggerTimeInServerTimeZone - Server.Time;
DrawRemainingTime(remainingTime);
if (!_ordersCreated)
{
var sellOrderTargetPrice = Symbol.Bid - PipsAway * Symbol.PipSize;
Chart.DrawHorizontalLine("sell target", sellOrderTargetPrice, Color.Red, 1, LineStyle.DotsVeryRare);
var buyOrderTargetPrice = Symbol.Ask + PipsAway * Symbol.PipSize;
Chart.DrawHorizontalLine("buy target", buyOrderTargetPrice, Color.Blue, 1, LineStyle.DotsVeryRare);
if (Server.Time <= _triggerTimeInServerTimeZone && (_triggerTimeInServerTimeZone - Server.Time).TotalSeconds <= SecondsBefore)
{
_ordersCreated = true;
var expirationTime = _triggerTimeInServerTimeZone.AddSeconds(SecondsTimeout);
var volume = Symbol.QuantityToVolumeInUnits(Lot);
var nomalVolume = Symbol.NormalizeVolumeInUnits(volume);
var res = PlaceStopOrder(TradeType.Sell, SymbolName, nomalVolume, sellOrderTargetPrice, Label, StopLoss, TakeProfit, expirationTime);
var res2 = PlaceStopOrder(TradeType.Buy, SymbolName, nomalVolume, buyOrderTargetPrice, Label, StopLoss, TakeProfit, expirationTime);
Chart.RemoveObject("sell target");
Chart.RemoveObject("buy target");
}
}
if (_ordersCreated && !PendingOrders.Any(o => o.Label == Label))
{
Print("Orders expired");
foreach (var order in PendingOrders)
{
if (order.Label == Label && order.SymbolName == SymbolName)
{
CancelPendingOrderAsync(order);
}
}
}
}
private void DrawRemainingTime(TimeSpan remainingTimeToNews)
{
if (ShowTimeLeftToNews)
{
if (remainingTimeToNews > TimeSpan.Zero)
{
Chart.DrawStaticText("countdown1", "Time left to news: " + FormatTime(remainingTimeToNews),
VerticalAlignment.Top, HorizontalAlignment.Left, Color.Red);
}
else
{
Chart.RemoveObject("countdown1");
}
}
if (ShowTimeLeftToPlaceOrders)
{
var remainingTimeToOrders = remainingTimeToNews - TimeSpan.FromSeconds(SecondsBefore);
if (remainingTimeToOrders > TimeSpan.Zero)
{
Chart.DrawStaticText("countdown2", "Time left to place orders: " + FormatTime(remainingTimeToOrders),
VerticalAlignment.Top, HorizontalAlignment.Right, Color.Red);
}
else
{
Chart.RemoveObject("countdown2");
}
}
}
private static StringBuilder FormatTime(TimeSpan remainingTime)
{
var remainingTimeStr = new StringBuilder();
if (remainingTime.TotalHours >= 1)
remainingTimeStr.Append((int)remainingTime.TotalHours + "h ");
if (remainingTime.TotalMinutes >= 1)
remainingTimeStr.Append(remainingTime.Minutes + "m ");
if (remainingTime.TotalSeconds > 0)
remainingTimeStr.Append(remainingTime.Seconds + "s");
return remainingTimeStr;
}
private void OnPositionOpened(PositionOpenedEventArgs args)
{
var position = args.Position;
if (position.Label == Label && position.SymbolName == SymbolName)
{
if (Oco)
{
foreach (var order in PendingOrders)
{
if (order.Label == Label && order.SymbolName == SymbolName)
{
CancelPendingOrderAsync(order);
}
}
}
}
}
}
}
nghiand.amz
Joined on 06.07.2020
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: DragonNewsBot.algo
- Rating: 5
- Installs: 900
- Modified: 14/12/2022 17:47
Warning! Running cBots downloaded from this section may lead to financial losses. Use them at your own risk.
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.
Hi, can you please add Trailing? maybe the classic or with Trigger, Distance and step pisp? thanks