just one trade at a time
just one trade at a time
23 Sep 2020, 03:12
Hi, how are you guys "Hi Panagiotis, how long man" I made a bot, but due to the variation in the average he is making several orders in a single trade. How can I create a programming line that solves this problem, that is, make only one negotiation and do not open new orders until the first one has been finalized. Thanks
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("Periods", DefaultValue = 14)]
public int Periods { get; set; }
[Parameter("Stop Loss (pips)", DefaultValue = 35, MinValue = 10)]
public double StopLoss { get; set; }
[Parameter("Volume", DefaultValue = 10000, MinValue = 1000)]
public int Volume { get; set; }
[Parameter("Take_Profit", DefaultValue = 100, MinValue = 10)]
public double TakeProfit { get; set; }
public RelativeStrengthIndex _rsi;
public RelativeStrengthIndex _rsi2;
public RelativeStrengthIndex _rsi3;
public RelativeStrengthIndex _rsi4;
private SimpleMovingAverage _sma;
private SimpleMovingAverage _sma2;
protected override void OnStart()
{
}
protected override void OnTick()
{
var day = Server.Time.DayOfWeek;
_rsi = Indicators.RelativeStrengthIndex(Bars.ClosePrices, 12);
_rsi2 = Indicators.RelativeStrengthIndex(Bars.ClosePrices, 6);
_rsi3 = Indicators.RelativeStrengthIndex(Bars.ClosePrices, 24);
_rsi4 = Indicators.RelativeStrengthIndex(Bars.ClosePrices, 48);
_sma = Indicators.SimpleMovingAverage(Bars.ClosePrices, 1);
_sma2 = Indicators.SimpleMovingAverage(Bars.ClosePrices, 4);
{
if (_rsi.Result.LastValue > 25)
if (_rsi.Result.LastValue < 50)
if (_rsi2.Result.LastValue > 25)
if (_rsi2.Result.LastValue < 50)
if (_rsi3.Result.LastValue < 45)
if (_rsi4.Result.LastValue < 45)
if (_sma.Result.HasCrossedAbove(_sma2.Result, 0))
if (day == DayOfWeek.Monday || day == DayOfWeek.Tuesday || day == DayOfWeek.Wednesday || day == DayOfWeek.Thursday)
ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "bot", StopLoss, TakeProfit);
}
if (_rsi.Result.LastValue < 75)
if (_rsi.Result.LastValue > 50)
if (_rsi2.Result.LastValue < 75)
if (_rsi2.Result.LastValue > 50)
if (_rsi3.Result.LastValue > 55)
if (_rsi4.Result.LastValue > 55)
if (_sma.Result.HasCrossedAbove(_sma2.Result, 0))
if (day == DayOfWeek.Monday || day == DayOfWeek.Tuesday || day == DayOfWeek.Wednesday || day == DayOfWeek.Thursday)
ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "bot", StopLoss, TakeProfit);
Replies
samuel.jus.cornelio
23 Sep 2020, 15:50
RE:
PanagiotisCharalampous said:
Hi Sam,
You can check if Positions.Count == 0 before placing a trade.
Best Regards,
Panagiotis
Hi Pani,
I tried that way and was unsuccessful.
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("Periods", DefaultValue = 14)]
public int Periods { get; set; }
[Parameter("Stop Loss (pips)", DefaultValue = 35, MinValue = 10)]
public double StopLoss { get; set; }
[Parameter("Volume", DefaultValue = 10000, MinValue = 1000)]
public int Volume { get; set; }
[Parameter("Take_Profit", DefaultValue = 75, MinValue = 10)]
public double TakeProfit { get; set; }
public RelativeStrengthIndex _rsi;
public RelativeStrengthIndex _rsi2;
public RelativeStrengthIndex _rsi3;
public RelativeStrengthIndex _rsi4;
public RelativeStrengthIndex _rsi1d;
public RelativeStrengthIndex _rsi2d;
public RelativeStrengthIndex _rsi3d;
private SimpleMovingAverage _sma;
private SimpleMovingAverage _sma2;
protected override void OnStart()
{
}
protected override void OnTick()
{
MarketData.GetSeries(Symbol, TimeFrame.Daily);
_rsi1d = Indicators.RelativeStrengthIndex(Bars.ClosePrices, 10);
_rsi2d = Indicators.RelativeStrengthIndex(Bars.ClosePrices, 5);
_rsi3d = Indicators.RelativeStrengthIndex(Bars.ClosePrices, 2);
var day = Server.Time.DayOfWeek;
_rsi = Indicators.RelativeStrengthIndex(Bars.ClosePrices, 50);
_rsi2 = Indicators.RelativeStrengthIndex(Bars.ClosePrices, 24);
_rsi3 = Indicators.RelativeStrengthIndex(Bars.ClosePrices, 12);
_rsi4 = Indicators.RelativeStrengthIndex(Bars.ClosePrices, 6);
_sma = Indicators.SimpleMovingAverage(Bars.ClosePrices, 1);
_sma2 = Indicators.SimpleMovingAverage(Bars.ClosePrices, 4);
{
if (_rsi1d.Result.LastValue < 40)
if (_rsi2d.Result.LastValue < 40)
if (_rsi3d.Result.LastValue < 40)
if (_rsi.Result.LastValue < 49)
if (_rsi2.Result.LastValue < 49)
if (_rsi3.Result.LastValue < 49)
if (_rsi4.Result.LastValue < 40)
if (Symbol.Ask > _sma2.Result.LastValue)
if (Trade.IsExecuting || position == 0)
return;
if (day == DayOfWeek.Monday || day == DayOfWeek.Tuesday || day == DayOfWeek.Wednesday || day == DayOfWeek.Thursday)
ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "bot", StopLoss, TakeProfit);
}
if (_rsi1d.Result.LastValue > 60)
if (_rsi2d.Result.LastValue > 60)
if (_rsi3d.Result.LastValue > 60)
if (_rsi.Result.LastValue < 51)
if (_rsi.Result.LastValue > 51)
if (_rsi2.Result.LastValue > 51)
if (_rsi3.Result.LastValue > 51)
if (_rsi4.Result.LastValue > 60)
if (Symbol.Ask < _sma2.Result.LastValue)
if (Trade.IsExecuting || position == 0)
return;
if (day == DayOfWeek.Monday || day == DayOfWeek.Tuesday || day == DayOfWeek.Wednesday || day == DayOfWeek.Thursday)
ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "bot", StopLoss, TakeProfit);
}
}
}
@samuel.jus.cornelio
PanagiotisCharalampous
23 Sep 2020, 16:03
Hi Sam,
Here is the correct condition
if (Positions.Count == 0)
{
// Do something
}
Best Regards,
Panagiotis
@PanagiotisCharalampous
samuel.jus.cornelio
23 Sep 2020, 16:06
RE:
PanagiotisCharalampous said:
Hi Sam,
Here is the correct condition
if (Positions.Count == 0) { // Do something }
Best Regards,
Panagiotis
thanks brow
@samuel.jus.cornelio
PanagiotisCharalampous
23 Sep 2020, 08:26
Hi Sam,
You can check if Positions.Count == 0 before placing a trade.
Best Regards,
Panagiotis
Join us on Telegram
@PanagiotisCharalampous