Topics
Forum Topics not found
Replies
amusleh
13 Oct 2021, 14:30
Hi,
The decimal places of your stop price must much with symbol digits.
You can get the symbol digits from ProtoOASymbol.
@amusleh
amusleh
13 Oct 2021, 08:12
( Updated at: 13 Oct 2021, 08:45 )
RE:
Hi,
Once cTrader 4.2 released you will be bale to use Windows Task manager to check each custom indicator or cBot resource usage while its running.
There is no way to get server host name via Automate API, you can create a suggestion for it.
You can use FIX host name and ping it to check the latency.
@amusleh
amusleh
12 Oct 2021, 07:21
Hi,
No, there is no way to get the resource usage statistics of your cBot/indicator.
You can check indicators/cBots resource usage in cTrader 4.2 from Task manager, which will run each indicator/cBot on its own sandbox process.
Please wait for cTrader 4.2 release.
@amusleh
amusleh
09 Oct 2021, 08:41
RE: ctrader crashed
Hi,
Something is wrong with alert XML configuration files, it located at cAlgo folder.
There is an Alerts folder inside cAlgo folder, delete it and retry.
Also please copy and post the full log of exception so I will be able to find the exact issue.
@amusleh
amusleh
08 Oct 2021, 07:14
Hi,
Try this sample cBot:
using System;
using System.Linq;
using cAlgo.API;
using System.Globalization;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class NewcBot : Robot
{
private TimeSpan _closeTime;
[Parameter("Close Time", DefaultValue = "17:00:00")]
public string CloseTime { get; set; }
[Parameter("Close Day", DefaultValue = DayOfWeek.Friday)]
public DayOfWeek CloseDay { get; set; }
protected override void OnStart()
{
if (TimeSpan.TryParse(CloseTime, CultureInfo.InvariantCulture, out _closeTime) == false)
{
Print("Incorrect close time value");
Stop();
}
Timer.Start(1);
}
protected override void OnTimer()
{
if (Server.Time.DayOfWeek == CloseDay && Server.Time.TimeOfDay >= _closeTime)
{
var positionsCopy = Positions.ToArray();
foreach (var position in Positions)
{
ClosePosition(position);
}
}
}
}
}
@amusleh
amusleh
07 Oct 2021, 19:56
Ho,
Try this:
using cAlgo.API;
using cAlgo.API.Alert;
using System;
using cAlgo.API.Alert.Utility;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
public class AlertTest : Indicator
{
public MacdHistogram _Macd;
private int _lastAlertBar;
[Parameter("source")]
public DataSeries Source { get; set; }
[Parameter("Long Cycle 1", DefaultValue = 26)]
public int LongCycle1 { get; set; }
[Parameter("Short Cycle 1", DefaultValue = 12)]
public int ShortCycle1 { get; set; }
[Parameter("Signal 1", DefaultValue = 9)]
public int inpSingal1 { get; set; }
public IndicatorDataSeries Macdup { get; set; }
[Output("Macd", LineColor = "Red", Thickness = 2, PlotType = PlotType.Histogram)]
public IndicatorDataSeries Macd { get; set; }
protected override void Initialize()
{
_Macd = Indicators.MacdHistogram(Source, LongCycle1, ShortCycle1, inpSingal1);
}
public override void Calculate(int index)
{
Macd[index] = _Macd.Histogram[index];
if (index == _lastAlertBar) return;
_lastAlertBar = index;
if (_Macd.Histogram[index - 1] > 0 && _Macd.Histogram[index - 2] <= 0)
{
Notifications.ShowPopup(MarketSeries.TimeFrame, Symbol, TradeType.Buy, "AcademyWave.com", Symbol.Bid, "Macd cross Above zero", Server.Time);
}
if (_Macd.Histogram[index - 1] < 0 && _Macd.Histogram[index - 2] >= 0)
{
Notifications.ShowPopup(MarketSeries.TimeFrame, Symbol, TradeType.Sell, "AcademyWave.com", Symbol.Bid, "Macd cross Below zero", Server.Time);
}
}
}
}
It uses the last closed bar MACD value not the current open bar.
@amusleh
amusleh
06 Oct 2021, 12:40
Hi,
If you call LoadMoreHistory method it will load more bars data for that time frame, you can call it if your indicator needs to.
Regarding values not matching issue, it can be caused by difference in data that your cBot process and fed to indicator for calculation.
You can also check the indicator calculation code, the indicator itself can be the reason too.
The code I posted was just a guide for you to make the indicator support multiple time frames, not something read for use on your code.
@amusleh
amusleh
06 Oct 2021, 09:16
Hi,
The indicator doesn't support multi time frame, it only has one parameter which is Period.
To make it multi time frame it should have a data series source parameter so you would be able to pass another time price series to it and indicator will use that instead of current chart price series.
Try this:
using System;
using cAlgo.API;
using cAlgo.API.Internals;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class VariableMovingAverage : Indicator
{
[Parameter(DefaultValue = 6)]
public int Period { get; set; }
[Parameter("TimeFrame")]
public TimeFrame BaseTimeFrame { get; set; }
[Output("Main", LineColor = "Cyan")]
public IndicatorDataSeries Result { get; set; }
private double K = 1;
private IndicatorDataSeries pdmS, mdmS, pdiS, mdiS, iS, tempResult;
private Bars _baseBars;
protected override void Initialize()
{
_baseBars = MarketData.GetBars(BaseTimeFrame);
K /= Period;
pdmS = CreateDataSeries();
mdmS = CreateDataSeries();
pdiS = CreateDataSeries();
mdiS = CreateDataSeries();
iS = CreateDataSeries();
tempResult = CreateDataSeries();
}
public override void Calculate(int index)
{
var baseIndex = _baseBars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
if (baseIndex < Period) return;
double pdm = Math.Max(_baseBars[baseIndex].Close - _baseBars[baseIndex - 1].Close, 0), mdm = Math.Max(_baseBars[baseIndex - 1].Close - _baseBars[baseIndex].Close, 0);
pdmS[index] = ((1 - K) * (double.IsNaN(pdmS[index - 1]) ? 0 : pdmS[index - 1]) + K * pdm);
mdmS[index] = ((1 - K) * (double.IsNaN(mdmS[index - 1]) ? 0 : mdmS[index - 1]) + K * mdm);
double pdi = pdmS[index] / (pdmS[index] + mdmS[index]);
double mdi = mdmS[index] / (pdmS[index] + mdmS[index]);
pdiS[index] = ((1 - K) * (double.IsNaN(pdiS[index - 1]) ? 0 : pdiS[index - 1]) + K * pdi);
mdiS[index] = ((1 - K) * (double.IsNaN(mdiS[index - 1]) ? 0 : mdiS[index - 1]) + K * mdi);
iS[index] = ((1 - K) * (double.IsNaN(iS[index - 1]) ? 0 : iS[index - 1]) + K * Math.Abs(pdiS[index] - mdiS[index]) / (pdiS[index] + mdiS[index]));
double hhv = iS.Maximum(Period);
double llv = iS.Minimum(Period);
tempResult[index] = (1 - K * (iS[index] - llv) / (hhv - llv)) * (double.IsNaN(tempResult[index - 1]) ? 0 : tempResult[index - 1]) + _baseBars[baseIndex].Close * K * (iS[index] - llv) / (hhv - llv);
if (index > Period * 10)
Result[index] = tempResult[index];
}
}
}
I have added a new TimeFrame parameter on it, you can use it to pass an specific time frame to indicator so it will use that time frame price data instead of current time frame.
When using multiple time frames data the other time frame might not load all the historical data that your current chart time frame loaded, so you have to use LoadMoreHistory method of Bars to load more history based on your chart current amount of loaded data.
@amusleh
amusleh
06 Oct 2021, 09:04
Hi,
When a new bar opens all of its OHLC prices are same as its open price, but when new ticks are coming the high, low, and close will start to develop and change.
If you access the last bar OHLC values inside OnBar method it will be all same, because the OnBar method is called when a new bar opens and the new bar OHLC are all same.
Try this:
using cAlgo.API;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class NewcBot : Robot
{
protected override void OnTick()
{
Print("Open: {0} | High: {1} | Low: {2} | Close: {3}", Bars.OpenPrices.LastValue, Bars.HighPrices.LastValue, Bars.LowPrices.LastValue, Bars.ClosePrices.LastValue);
}
}
}
If you change the OnTick to OnBar you will see whenever a new bar opens the method will be called and all OHLC prices will be same.
@amusleh
amusleh
05 Oct 2021, 18:44
RE: RE:
khoshroomahdi said:
amusleh said:
Hi,
You should reference all DLL files inside Release zip file you downloaded, then it will work.
I strongly recommend you to use Visual Studio and install the alert library via Nuget.
Visual Studio is free, you can download it from here: Visual Studio - Visual Studio (microsoft.com)
is my code correct?
i do this even with visual studio but i didn't get any notification.
Hi,
Your code was correct, I tested and the popup showed up.
Check the cTrader automate logs tab, if your code calls the ShowPopup method and the popup didn't showed up then you most probably will see an error message on logs tab.
@amusleh
amusleh
15 Oct 2021, 08:27
RE: Option to Change Grid Lines Color
RayAdam said:
There is no way for changing grid lines color, If you need it then you can open a thread for it on suggestions section.
@amusleh