Topics
Replies
apollinaire89
08 Aug 2019, 17:59
( Updated at: 21 Dec 2023, 09:21 )
RE:
Panagiotis Charalampous said:
Hi apollinaire89,
Can you explain what do you mean? This line of code should not affect your trading in any way. Do you get any messages in your log?
Best Regards,
Panagiotis
Thank you for being so quick. Unfortunately it is not set up and also not in Log.
@apollinaire89
apollinaire89
08 Aug 2019, 17:51
RE:
Panagiotis Charalampous said:
Hi apollinaire89
See below a modified example.
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class SampleRSIcBot : Robot { [Parameter("Quantity (Lots)", Group = "Volume", DefaultValue = 1, MinValue = 0.01, Step = 0.01)] public double Quantity { get; set; } [Parameter("Source", Group = "RSI")] public DataSeries Source { get; set; } [Parameter("Periods", Group = "RSI", DefaultValue = 14)] public int Periods { get; set; } [Parameter("Stop Loss Pips", Group = "Protection", DefaultValue = 0.0, MinValue = 0.0, Step = 1)] public double StopLossPips { get; set; } [Parameter("Take Profit Pips", Group = "Protection", DefaultValue = 0.0, MinValue = 0.0, Step = 1)] public double TakeProfitPips { get; set; } private RelativeStrengthIndex rsi; protected override void OnStart() { rsi = Indicators.RelativeStrengthIndex(Source, Periods); Positions.Opened += OnPositionsOpened; } void OnPositionsOpened(PositionOpenedEventArgs obj) { Notifications.SendEmail("youremail@address.com", "youremail@address.com", "MyRSISell", "position opened"); } protected override void OnTick() { if (rsi.Result.LastValue < 62) { Close(TradeType.Buy); Open(TradeType.Sell); } } private void Close(TradeType tradeType) { foreach (var position in Positions.FindAll("SampleRSI", SymbolName, tradeType)) ClosePosition(position); } private void Open(TradeType tradeType) { var position = Positions.Find("SampleRSI", SymbolName, tradeType); var volumeInUnits = Symbol.QuantityToVolumeInUnits(Quantity); if (position == null) ExecuteMarketOrder(tradeType, SymbolName, volumeInUnits, "SampleRSI"); } } }Best Regards,
Panagiotis
Dear Panagiotis,
the stopp loss and take profit is not set in order after the code line has been added. Could you please help here if possible ?
Positions.Opened += OnPositionsOpened;
@apollinaire89
apollinaire89
08 Aug 2019, 09:58
RE:
Panagiotis Charalampous said:
Hi apollinaire89
See below a modified example.
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class SampleRSIcBot : Robot { [Parameter("Quantity (Lots)", Group = "Volume", DefaultValue = 1, MinValue = 0.01, Step = 0.01)] public double Quantity { get; set; } [Parameter("Source", Group = "RSI")] public DataSeries Source { get; set; } [Parameter("Periods", Group = "RSI", DefaultValue = 14)] public int Periods { get; set; } [Parameter("Stop Loss Pips", Group = "Protection", DefaultValue = 0.0, MinValue = 0.0, Step = 1)] public double StopLossPips { get; set; } [Parameter("Take Profit Pips", Group = "Protection", DefaultValue = 0.0, MinValue = 0.0, Step = 1)] public double TakeProfitPips { get; set; } private RelativeStrengthIndex rsi; protected override void OnStart() { rsi = Indicators.RelativeStrengthIndex(Source, Periods); Positions.Opened += OnPositionsOpened; } void OnPositionsOpened(PositionOpenedEventArgs obj) { Notifications.SendEmail("youremail@address.com", "youremail@address.com", "MyRSISell", "position opened"); } protected override void OnTick() { if (rsi.Result.LastValue < 62) { Close(TradeType.Buy); Open(TradeType.Sell); } } private void Close(TradeType tradeType) { foreach (var position in Positions.FindAll("SampleRSI", SymbolName, tradeType)) ClosePosition(position); } private void Open(TradeType tradeType) { var position = Positions.Find("SampleRSI", SymbolName, tradeType); var volumeInUnits = Symbol.QuantityToVolumeInUnits(Quantity); if (position == null) ExecuteMarketOrder(tradeType, SymbolName, volumeInUnits, "SampleRSI"); } } }Best Regards,
Panagiotis
Thank you so much! It is perfect! My next step is to learn C# :)
@apollinaire89
apollinaire89
08 Aug 2019, 09:37
RE:
Panagiotis Charalampous said:
Hi apollinaire89,
It seems correct to me, assuming that the rest of the cBot is correctly implemented.
Best Regards,
Panagiotis
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class SampleRSIcBot : Robot
{
[Parameter("Quantity (Lots)", Group = "Volume", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
public double Quantity { get; set; }
[Parameter("Source", Group = "RSI")]
public DataSeries Source { get; set; }
[Parameter("Periods", Group = "RSI", DefaultValue = 14)]
public int Periods { get; set; }
[Parameter("Stop Loss Pips", Group = "Protection", DefaultValue = 0.0, MinValue = 0.0, Step = 1)]
public double StopLossPips { get; set; }
[Parameter("Take Profit Pips", Group = "Protection", DefaultValue = 0.0, MinValue = 0.0, Step = 1)]
public double TakeProfitPips { get; set; }
private RelativeStrengthIndex rsi;
protected override void OnStart()
{
rsi = Indicators.RelativeStrengthIndex(Source, Periods);
}
protected override void OnTick()
{
if (rsi.Result.LastValue < 62)
{
Close(TradeType.Buy);
Open(TradeType.Sell);
}
}
private void Close(TradeType tradeType)
{
foreach (var position in Positions.FindAll("SampleRSI", SymbolName, tradeType))
ClosePosition(position);
}
private void Open(TradeType tradeType)
{
var position = Positions.Find("SampleRSI", SymbolName, tradeType);
var volumeInUnits = Symbol.QuantityToVolumeInUnits(Quantity);
if (position == null)
ExecuteMarketOrder(tradeType, SymbolName, volumeInUnits, "SampleRSI");
}
}
}
Hello! Where should i put the command ? I think i am putting it in wrong place ? Many thanks.
@apollinaire89
apollinaire89
08 Aug 2019, 09:23
Hi Panagiotis,
Yes. it is only a part and would like to know the correct coding to receive notification at opening position by cbot.
@apollinaire89
apollinaire89
08 Aug 2019, 18:31
RE:
Panagiotis Charalampous said:
Thank you! I added them now. Perfect! Many thanks!
@apollinaire89