
Topics
Replies
PanagiotisCharalampous
18 Dec 2019, 08:45
Hi 8089669,
Please use the Suggestions section for posting your suggestions.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
17 Dec 2019, 16:28
Hi mr.polax.troy,
See below the answers to your questions
- I assume you refer to cTrader Automate. At the moment you cannot display indicators on the chart via cTrader Automate API.
- Most indicators have a source option. You can pass a source from another timeframe which you can get using MarketData.GetSeries() method.
- There is no such option at the moment.
- As explained in point 1, there is no such option. You will need to add the indicators manually.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
17 Dec 2019, 15:44
Hi v,kredov,
The way you handle indices between different data series is wrong. An index in calculate is not the same index in a series retrieved by GetBars(). See below a corrected version
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System.Threading;
using System.Collections.Generic;
namespace cAlgo
{
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None, ScalePrecision = 5, AutoRescale = true)]
public class Correlation : Indicator
{
[Parameter("Master Currency", DefaultValue = "EURUSD")]
public string masterName { get; set; }
[Parameter("Slave Currency", DefaultValue = "AUDUSD")]
public string slaveName { get; set; }
[Parameter("Periods", DefaultValue = 120)]
public int Period { get; set; }
[Output("Correlation", LineColor = "Red")]
public IndicatorDataSeries Result { get; set; }
private Bars masterBars;
private Bars slaveBars;
private Symbol masterSymbol;
private Symbol slaveSymbol;
protected override void Initialize()
{
masterSymbol = Symbols.GetSymbol(masterName);
slaveSymbol = Symbols.GetSymbol(slaveName);
masterBars = MarketData.GetBars(Bars.TimeFrame, masterName);
slaveBars = MarketData.GetBars(Bars.TimeFrame, slaveName);
while (masterBars.Count < Period)
{
var loadedCount = masterBars.LoadMoreHistory();
if (loadedCount == 0)
break;
}
while (slaveBars.Count < Period)
{
var loadedCount = slaveBars.LoadMoreHistory();
if (loadedCount == 0)
break;
}
}
public override void Calculate(int index)
{
if (index < Period + 1)
{
return;
}
double masterSum = 0;
double masterMedian = 0;
double slaveSum = 0;
double slaveMedian = 0;
double upPartSum = 0;
double masterDeltaSqrtSum = 0;
double slaveDeltaSqrtSum = 0;
for (int i = 0; i < Period; i++)
{
var masterBarsIndex = masterBars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]) - i;
if (!double.IsNaN(masterBarsIndex))
masterSum = masterSum + masterBars[masterBarsIndex].Close;
var slaveBarsIndex = slaveBars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]) - i;
if (!double.IsNaN(slaveBarsIndex) && slaveBarsIndex >= 0 && slaveBars.Count > slaveBarsIndex)
slaveSum = slaveBars[slaveBarsIndex].Close;
}
masterMedian = masterSum / Period;
slaveMedian = slaveSum / Period;
for (int i = 0; i < Period; i++)
{
upPartSum = upPartSum + (masterBars[masterBars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]) - i].Close - masterMedian) * (slaveBars[slaveBars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]) - i].Close - slaveMedian);
masterDeltaSqrtSum = masterDeltaSqrtSum + Math.Pow(masterBars[masterBars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]) - i].Close - masterMedian, 2);
slaveDeltaSqrtSum = slaveDeltaSqrtSum + Math.Pow(slaveBars[slaveBars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]) - i].Close - slaveMedian, 2);
}
Result[index] = upPartSum / Math.Sqrt(masterDeltaSqrtSum * slaveDeltaSqrtSum);
}
}
}
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
17 Dec 2019, 08:15
( Updated at: 21 Dec 2023, 09:21 )
Hi M K,
I assume you are using 3.7
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
16 Dec 2019, 14:59
( Updated at: 21 Dec 2023, 09:21 )
Hi M K,
As I said I have tried this cBot but I do not see any issues. See below an example from GBPUSD t1
Am I missing something?
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
16 Dec 2019, 14:50
RE:
Hi useretinv,
See an example below with the cBot trading on two symbols.
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 marto : Robot
{
[Parameter("Initial Volume", DefaultValue = 10000, MinValue = 0)]
public int InitialVolume { get; set; }
[Parameter("Stop Loss", DefaultValue = 40)]
public int StopLoss { get; set; }
[Parameter("Take Profit", DefaultValue = 40)]
public int TakeProfit { get; set; }
private Random random = new Random();
protected override void OnStart()
{
Positions.Closed += OnPositionsClosed;
ExecuteOrder("EURUSD", InitialVolume, GetRandomTradeType());
ExecuteOrder("GBPUSD", InitialVolume, GetRandomTradeType());
}
private void ExecuteOrder(string symbol, long volume, TradeType tradeType)
{
var result = ExecuteMarketOrder(tradeType, symbol, volume, "Martingale", StopLoss, TakeProfit);
if (result.Error == ErrorCode.NoMoney)
Stop();
}
private void OnPositionsClosed(PositionClosedEventArgs args)
{
Print("Closed");
var position = args.Position;
if (position.Label != "Martingale")
return;
if (position.GrossProfit > 0)
{
ExecuteOrder(position.SymbolName, InitialVolume, GetRandomTradeType());
}
else
{
if (position.TradeType == TradeType.Buy)
ExecuteOrder(position.SymbolName, (int)position.Volume * 2, TradeType.Sell);
else
ExecuteOrder(position.SymbolName, (int)position.Volume * 2, TradeType.Buy);
}
}
private TradeType GetRandomTradeType()
{
return random.Next(2) == 0 ? TradeType.Buy : TradeType.Sell;
}
}
}
You can modify this accordingly
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
16 Dec 2019, 14:28
Hi useretinv,
I am not sure what do you mean when you say.
to apply new Multi-Symbol Back testing code
This cBot is not a multisymbol cBot. It just trades one symbol. Do you want this cBot to trade on many symbols at the same time?
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
16 Dec 2019, 14:06
Hi fardugotra,
Multisymbol backtesting allows you to backtest cBots that execute orders on other symbols than the chart symbol. To do what you have described, you will need backtest your cBot on different instances with different symbols and compare the results.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
16 Dec 2019, 10:58
Hi pooria222222,
Your example is a bit over exaggerated. When your account receives the deposit from your fees, your followers subaccounts will be adjusted to reflect the new equity to equity ratio. Here some positions will partially close in profit or loss, depending on the market condition at the moment. After that the two positions will have a different entry price due to the partial closing of the position of the follower. Indeed the follower might have more loss than you but more profit as well depending on where the partial closing took place. such discrepancies are expected and they are clearly described in our EULA which has been agreed before the strategy following has started.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
16 Dec 2019, 10:20
Hi pooria222222,
No there isn't. Followers started following your strategy agreeing on a specified fee. You cannot change the fee on the go, it is not fair for them. If you want to change the fee, the followers will need to agree in your new fees.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
16 Dec 2019, 09:14
Hi pooria222222,
Please use the Suggestions section for posting suggestions. Regarding
Suppose I have 100$ balance and 0.1 EURUSD position, my subscriber with 200$ balance has 0.2 LOT EURUSD
Now after adding 300 $ performance fee , my balance is 300 and I still have 0.1 lot EURUSD , what happened to my copier now?
Still 0.2 or changed to 0.05 ?!
Your copier's position will change to 0.05 to reflect the change in equity to equity ratio.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
16 Dec 2019, 09:09
Hi Tom,
Please use the Suggestions section for posting your suggestions.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
16 Dec 2019, 09:08
Hi chernish2,
There is no such option at the moment.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
16 Dec 2019, 09:06
Hi huy.tr22,
If you need somebody to implement a custom indicator for you, you can consider posting a Job or contacting a Consultant.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
16 Dec 2019, 09:04
Hi VFX Managing Trader,
I have replied to you regarding this matter here https://ctrader.com/forum/ctrader-copy/22535?page=1#post-2.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
16 Dec 2019, 09:01
RE:
Hi Jan,
You cannot apply a color for an indicator series on runtime. You can only apply it on declaration. To apply opacity, you can set a HEX code as a color. See below
[Output("Histogram Down", PlotType = PlotType.Histogram, LineColor = "#32FF0000")]
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
16 Dec 2019, 08:47
Hi chernish2,
There is no such option built in at the moment but this can be easily programmed into a cBot using the Chart ScrollXTo() method.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
16 Dec 2019, 08:40
Hi VFX Managing Trader,
There is no such option at the moment. However there is no easy way for somebody to copy your strategy since follower subaccounts are not accessible via any API. For somebody to copy your strategy efficiently then he will need to monitor your account 24/7.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
16 Dec 2019, 08:38
Hi Tommy2019,
You can also consider posting a Job or ask the help of a professional.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
19 Dec 2019, 08:29
Hi FireMyst,
As far as I know it is the close price which is considering only the bid price.
Best Regards,
Panagiotis
Join us on Telegram
@PanagiotisCharalampous