how to make just one trade a day?
how to make just one trade a day?
19 Feb 2021, 02:33
I tested the lines of code below. in order to make only one trade per day, but the bot keeps making several trades a day. How can I solve this problem?
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.ESouthAmericaStandardTime, AccessRights = AccessRights.None)]
public class bot : Robot
{
[Parameter(DefaultValue = 0.0)]
public double Parameter { get; set; }
[Parameter("Source")]
public DataSeries Source { get; set; }
[Parameter("Volume", DefaultValue = 10000, MinValue = 1000)]
public int Volume { get; set; }
[Parameter("Stop Loss (pips)", DefaultValue = 35, MinValue = 10)]
public double StopLoss { get; set; }
[Parameter("Take_Profit", DefaultValue = 30, MinValue = 10)]
public double TakeProfit { get; set; }
[Parameter("Start Time", DefaultValue = 7.0)]
public double StartTime { get; set; }
[Parameter("Stop Time", DefaultValue = 16.0)]
public double StopTime { get; set; }
DateTime _lastTrade;
private DateTime _startTime;
private DateTime _stopTime;
private RelativeStrengthIndex _1hrsi1;
private StochasticOscillator _hstoch1;
protected override void OnStart()
{
_startTime = Server.Time.Date.AddHours(StartTime);
_stopTime = Server.Time.Date.AddHours(StopTime);
_lastTrade = Server.Time.AddDays(-1);
}
protected override void OnTick()
{
var hour1 = MarketData.GetBars(TimeFrame.Hour);
var day = Server.Time.DayOfWeek;
_1hrsi1 = Indicators.RelativeStrengthIndex(hour1.ClosePrices, 80);
_hstoch1 = Indicators.StochasticOscillator(hour1, 80, 3, 80, MovingAverageType.Simple);
if (Trade.IsExecuting)
return;
var currentHours = Server.Time.TimeOfDay.TotalHours;
bool tradeTime = StartTime < StopTime ? currentHours > StartTime && currentHours < StopTime : currentHours < StopTime || currentHours > StartTime;
if (!tradeTime)
return;
if (_1hrsi1.Result.LastValue > 75) if (_lastTrade.DayOfYear != Server.Time.DayOfYear)
if (day == DayOfWeek.Monday || day == DayOfWeek.Tuesday || day == DayOfWeek.Wednesday || day == DayOfWeek.Thursday)
if (Positions.Count == 0)
_lastTrade = Server.Time;
ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "bot", StopLoss, TakeProfit);
Replies
... Deleted by UFO ...
... Deleted by UFO ...