Topics
Forum Topics not found
Replies
Boring
11 Aug 2022, 14:51
RE:
PanagiotisCharalampous said:
Hi Liquidity,
Here you go
if (Positions.Count < MaxPositions) { ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "BUY"); ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "SELL"); foreach (var position in Positions) { if (position.Pips > 2) { ClosePosition(position); } } }
Best Regards,
Panagiotis
Thanks! There seems to be a difference in the backtesting results after adding the above code into protected override void OnTick()
@Boring
Boring
11 Aug 2022, 14:13
RE:
PanagiotisCharalampous said:
Hi Liquidity,
You need to put the code inside the condition.
Best Regards,
Panagiotis
I have to be honest, sorry. I have no idea what that means "inside the condition".
If I know what the "condition" is, I can place the code inside it.
@Boring
Boring
11 Aug 2022, 14:08
( Updated at: 11 Aug 2022, 14:09 )
Parameter code for limiting max open trades not working
I need help, please :)
I was glad I found this and thought it would be simple to implement but I cannot get it to work in the following :
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.UTC, AccessRights = AccessRights.None)]
public class TestcBOT : Robot
{
[Parameter(DefaultValue = 1, MinValue = 1)]
public int MaxPositions { get; set; }
[Parameter("Volume", DefaultValue = 1000, MinValue = 1000, Step = 1000)]
public int Volume { get; set; }
protected override void OnStart()
{
}
protected override void OnTick()
{
if (Positions.Count < MaxPositions)
{
// Do somehting
}
}
protected override void OnStop()
{
}
protected override void OnBar()
{
ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "BUY");
ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "SELL");
foreach (var position in Positions)
{
if (position.Pips > 2)
{
ClosePosition(position);}
}
}
}
}
@Boring
Boring
18 Jul 2022, 09:22
( Updated at: 18 Jul 2022, 09:23 )
RE: thanks!
PanagiotisCharalampous said:
Hi Liquidity,
Here you go
// ------------------------------------------------------------------------------------------------- // // This code is a cAlgo API sample. // // This cBot is intended to be used as a sample and does not guarantee any particular outcome or // profit of any kind. Use it at your own risk. // // The "Sample RSI cBot" will create a buy order when the Relative Strength Index indicator crosses the level 30, // and a Sell order when the RSI indicator crosses the level 70. The order is closed be either a Stop Loss, defined in // the "Stop Loss" parameter, or by the opposite RSI crossing signal (buy orders close when RSI crosses the 70 level // and sell orders are closed when RSI crosses the 30 level). // // The cBot can generate only one Buy or Sell order at any given time. // // ------------------------------------------------------------------------------------------------- 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("Source")] public DataSeries Source { get; set; } [Parameter("Periods", DefaultValue = 14)] public int Periods { get; set; } [Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)] public double Quantity { get; set; } [Parameter("From", DefaultValue = 7)] public int From { get; set; } [Parameter("To", DefaultValue = 10)] public int To { get; set; } private RelativeStrengthIndex rsi; protected override void OnStart() { rsi = Indicators.RelativeStrengthIndex(Source, Periods); } protected override void OnTick() { if (Server.Time.Hour >= From && Server.Time.Hour < To) { if (rsi.Result.LastValue < 30) { Close(TradeType.Sell); Open(TradeType.Buy); } else if (rsi.Result.LastValue > 70) { Close(TradeType.Buy); Open(TradeType.Sell); } } } private void Close(TradeType tradeType) { foreach (var position in Positions.FindAll("SampleRSI", Symbol, tradeType)) ClosePosition(position); } private void Open(TradeType tradeType) { var position = Positions.Find("SampleRSI", Symbol, tradeType); var volumeInUnits = Symbol.QuantityToVolume(Quantity); if (position == null) ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, "SampleRSI"); } } }
Best Regards,
Panagiotis
Thanks a lot!
Looking at the code, that was so simple, lol!
@Boring
Boring
16 Jul 2022, 00:32
( Updated at: 16 Jul 2022, 00:33 )
RE: Setting Parameter for Hours
PanagiotisCharalampous said:
Hi Alex,
See below the modified code that trades between 7 and 10 am.
// ------------------------------------------------------------------------------------------------- // // This code is a cAlgo API sample. // // This cBot is intended to be used as a sample and does not guarantee any particular outcome or // profit of any kind. Use it at your own risk. // // The "Sample RSI cBot" will create a buy order when the Relative Strength Index indicator crosses the level 30, // and a Sell order when the RSI indicator crosses the level 70. The order is closed be either a Stop Loss, defined in // the "Stop Loss" parameter, or by the opposite RSI crossing signal (buy orders close when RSI crosses the 70 level // and sell orders are closed when RSI crosses the 30 level). // // The cBot can generate only one Buy or Sell order at any given time. // // ------------------------------------------------------------------------------------------------- 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("Source")] public DataSeries Source { get; set; } [Parameter("Periods", DefaultValue = 14)] public int Periods { get; set; } [Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)] public double Quantity { get; set; } private RelativeStrengthIndex rsi; protected override void OnStart() { rsi = Indicators.RelativeStrengthIndex(Source, Periods); } protected override void OnTick() { if (Server.Time.Hour >= 7 && Server.Time.Hour < 10) { if (rsi.Result.LastValue < 30) { Close(TradeType.Sell); Open(TradeType.Buy); } else if (rsi.Result.LastValue > 70) { Close(TradeType.Buy); Open(TradeType.Sell); } } } private void Close(TradeType tradeType) { foreach (var position in Positions.FindAll("SampleRSI", Symbol, tradeType)) ClosePosition(position); } private void Open(TradeType tradeType) { var position = Positions.Find("SampleRSI", Symbol, tradeType); var volumeInUnits = Symbol.QuantityToVolume(Quantity); if (position == null) ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, "SampleRSI"); } } }Best Regards,
Panagiotis
This works, thanks!
But is there anyway to add an input field (parameter) to change the start and stop hour like there is a field to change the RSI period and source? For now, I have to go into the code and manually set the hours I want to backtest.
@Boring
Boring
14 Oct 2022, 18:56 ( Updated at: 15 Oct 2022, 08:03 )
RE: Setting Parameter for Minutes
PanagiotisCharalampous said:
The parameters for the hours work well but is it possible to add "minutes" to the parameters. For example, instead of starting a trade at 14:00, it starts at 14:15 or even 14:18.
Is this possible? All help is highly appreciated!
@Boring