Topics
Replies
radoslawkupisek
30 Oct 2019, 17:39
Ok, still not sure how to use it..
When I copy the egsample then I've got" Error : No algo source file was found in "ReadWriteCsv.csproj"".
When I just use some of this code at the end when the program stops as"
protected override void OnStop()
{
using (var streamWriter = File.CreateText("123.csv"))
{
var writer = new CsvWriter(streamWriter);
writer.WriteRecords(Table);
}
}
Then I ve got Error CS0246: saying that there is no CsvWriter. despite the fact that I have on the beginning of my robot
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
using System.IO;
using System.Text;
using System.Collections.Generic;
How it should be done to be able to save this file?
@radoslawkupisek
radoslawkupisek
12 Sep 2019, 20:20
Hi, how to set corner in Chart.DrawText method?
public ChartText DrawText(string name, string text, DateTime time, double y, Color color) for example: Chart.DrawText("text", "test", ?,?, Color.White); It used to be StaticPosition, what can I use now?
@radoslawkupisek
radoslawkupisek
12 Sep 2019, 18:48
cause of Print method. The right code below
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
namespace cAlgo.Indicators
{
[Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
public class PRCD1 : Indicator
{
[Parameter(DefaultValue = 2.0, MinValue = 1, MaxValue = 4)]
public int degree { get; set; }
[Parameter(DefaultValue = 120)]
public int period { get; set; }
[Parameter(DefaultValue = 1.62)]
public double strdDev { get; set; }
[Parameter(DefaultValue = 2)]
public double strdDev2 { get; set; }
[Output("PRC", Color = Colors.Gray)]
public IndicatorDataSeries prc { get; set; }
[Output("SQH", Color = Colors.Red)]
public IndicatorDataSeries sqh { get; set; }
[Output("SQL", Color = Colors.Blue)]
public IndicatorDataSeries sql { get; set; }
[Output("SQL2", Color = Colors.Blue)]
public IndicatorDataSeries sql2 { get; set; }
[Output("SQH2", Color = Colors.Red)]
public IndicatorDataSeries sqh2 { get; set; }
private double[,] ai = new double[10, 10];
private double[] b = new double[10];
private double[] x = new double[10];
private double[] sx = new double[10];
private double sum;
private int ip;
private int p;
private int n;
private int f;
private double qq;
private double mm;
private double tt;
private int ii;
private int jj;
private int kk;
private int ll;
private int nn;
private double sq;
private double sq2;
private int i0 = 0;
private int mi;
public MarketSeries TF;
public IndicatorDataSeries TFF;
protected override void Initialize()
{
TF = MarketData.GetSeries(TimeFrame.Daily);
}
public override void Calculate(int index)
{
var index24h = GetIndexByDate(TF, MarketSeries.OpenTime[index]);
if (index24h != -1)
{
ip = period;
p = ip;
sx[1] = p + 1;
nn = degree + 1;
//----------------------sx-------------------------------------------------------------------
//
for (mi = 1; mi <= nn * 2 - 2; mi++)
{
sum = 0;
for (n = i0; n <= i0 + p; n++)
{
sum += Math.Pow(n, mi);
}
sx[mi + 1] = sum;
}
//----------------------syx-----------
for (mi = 1; mi <= nn; mi++)
{
sum = 0.0;
for (n = i0; n <= i0 + p; n++)
{
if (mi == 1)
sum += TF.Close[index24h - n];
else
// before sum += MarketSeries.Close[index - n];
sum += TF.Close[index24h - n] * Math.Pow(n, mi - 1);
// before sum += MarketSeries.Close[index - n] * Math.Pow(n, mi - 1);
}
b[mi] = sum;
}
//===============Matrix=======================================================================================================
for (jj = 1; jj <= nn; jj++)
{
for (ii = 1; ii <= nn; ii++)
{
kk = ii + jj - 1;
ai[ii, jj] = sx[kk];
}
}
//===============Gauss========================================================================================================
for (kk = 1; kk <= nn - 1; kk++)
{
ll = 0;
mm = 0;
for (ii = kk; ii <= nn; ii++)
{
if (Math.Abs(ai[ii, kk]) > mm)
{
mm = Math.Abs(ai[ii, kk]);
ll = ii;
}
}
if (ll == 0)
return;
if (ll != kk)
{
for (jj = 1; jj <= nn; jj++)
{
tt = ai[kk, jj];
ai[kk, jj] = ai[ll, jj];
ai[ll, jj] = tt;
}
tt = b[kk];
b[kk] = b[ll];
b[ll] = tt;
}
for (ii = kk + 1; ii <= nn; ii++)
{
qq = ai[ii, kk] / ai[kk, kk];
for (jj = 1; jj <= nn; jj++)
{
if (jj == kk)
ai[ii, jj] = 0;
else
ai[ii, jj] = ai[ii, jj] - qq * ai[kk, jj];
}
b[ii] = b[ii] - qq * b[kk];
}
}
x[nn] = b[nn] / ai[nn, nn];
for (ii = nn - 1; ii >= 1; ii--)
{
tt = 0;
for (jj = 1; jj <= nn - ii; jj++)
{
tt = tt + ai[ii, ii + jj] * x[ii + jj];
x[ii] = (1 / ai[ii, ii]) * (b[ii] - tt);
}
}
sq = 0.0;
sq2 = 0.0;
for (n = i0; n <= i0 + p; n++)
{
sum = 0;
for (kk = 1; kk <= degree; kk++)
{
sum += x[kk + 1] * Math.Pow(n, kk);
}
prc[index - n] = (x[1] + sum);
sq += Math.Pow(TF.Close[index24h - n] - prc[index - n], 2);
//before sq += Math.Pow(MarketSeries.Close[index - n] - prc[index - n], 2);
sq2 += Math.Pow(TF.Close[index24h - n] - prc[index - n], 2);
//before sq2 += Math.Pow(MarketSeries.Close[index - n] - prc[index - n], 2);
}
sq = Math.Sqrt(sq / (p + 1)) * strdDev;
sq2 = Math.Sqrt(sq2 / (p + 1)) * strdDev2;
for (n = i0; n <= i0 + p; n++)
{
sqh[index - n] = (prc[index - n] + sq);
sql[index - n] = (prc[index - n] - sq);
sqh2[index - n] = (prc[index - n] + sq2);
sql2[index - n] = (prc[index - n] - sq2);
}
}
//just to check the price point
Print("d1 sql ", sql);
Print("d1 sql2 ", sql2);
Print("d1 sqh ", sqh);
Print("d1 sqh2 ", sqh2);
}
private int GetIndexByDate(MarketSeries series, DateTime time)
{
for (int i = series.Close.Count - 1; i > 0; i--)
{
if (time == series.OpenTime[i])
return i;
}
return -1;
}
}
}
@radoslawkupisek
radoslawkupisek
12 Sep 2019, 10:20
There is PRC indicator which works fine, all I have changed is timeframe. I paste oryginal code below and I underline the part that has been changed by me. When I launch it on any time frame it works (shows correct D1 price levels) but not on m1.
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
namespace cAlgo.Indicators
{
[Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
public class PRCD1 : Indicator
{
[Parameter(DefaultValue = 2.0, MinValue = 1, MaxValue = 4)]
public int degree { get; set; }
[Parameter(DefaultValue = 120)]
public int period { get; set; }
[Parameter(DefaultValue = 1.62)]
public double strdDev { get; set; }
[Parameter(DefaultValue = 2)]
public double strdDev2 { get; set; }
[Output("PRC", Color = Colors.Gray)]
public IndicatorDataSeries prc { get; set; }
[Output("SQH", Color = Colors.Red)]
public IndicatorDataSeries sqh { get; set; }
[Output("SQL", Color = Colors.Blue)]
public IndicatorDataSeries sql { get; set; }
[Output("SQL2", Color = Colors.Blue)]
public IndicatorDataSeries sql2 { get; set; }
[Output("SQH2", Color = Colors.Red)]
public IndicatorDataSeries sqh2 { get; set; }
private double[,] ai = new double[10, 10];
private double[] b = new double[10];
private double[] x = new double[10];
private double[] sx = new double[10];
private double sum;
private int ip;
private int p;
private int n;
private int f;
private double qq;
private double mm;
private double tt;
private int ii;
private int jj;
private int kk;
private int ll;
private int nn;
private double sq;
private double sq2;
private int i0 = 0;
private int mi;
public MarketSeries TF;
public IndicatorDataSeries TFF;
protected override void Initialize()
{
TF = MarketData.GetSeries(TimeFrame.Daily);
}
public override void Calculate(int index)
{
var index24h = GetIndexByDate(TF, MarketSeries.OpenTime[index]);
if (index24h != -1)
{
ip = period;
p = ip;
sx[1] = p + 1;
nn = degree + 1;
//----------------------sx-------------------------------------------------------------------
//
for (mi = 1; mi <= nn * 2 - 2; mi++)
{
sum = 0;
for (n = i0; n <= i0 + p; n++)
{
sum += Math.Pow(n, mi);
}
sx[mi + 1] = sum;
}
//----------------------syx-----------
for (mi = 1; mi <= nn; mi++)
{
sum = 0.0;
for (n = i0; n <= i0 + p; n++)
{
if (mi == 1)
sum += TF.Close[index24h - n]; // before sum += MarketSeries.Close[index - n];
else
sum += TF.Close[index24h - n] * Math.Pow(n, mi - 1); // before sum += MarketSeries.Close[index - n] * Math.Pow(n, mi - 1);
}
b[mi] = sum;
}
//===============Matrix=======================================================================================================
for (jj = 1; jj <= nn; jj++)
{
for (ii = 1; ii <= nn; ii++)
{
kk = ii + jj - 1;
ai[ii, jj] = sx[kk];
}
}
//===============Gauss========================================================================================================
for (kk = 1; kk <= nn - 1; kk++)
{
ll = 0;
mm = 0;
for (ii = kk; ii <= nn; ii++)
{
if (Math.Abs(ai[ii, kk]) > mm)
{
mm = Math.Abs(ai[ii, kk]);
ll = ii;
}
}
if (ll == 0)
return;
if (ll != kk)
{
for (jj = 1; jj <= nn; jj++)
{
tt = ai[kk, jj];
ai[kk, jj] = ai[ll, jj];
ai[ll, jj] = tt;
}
tt = b[kk];
b[kk] = b[ll];
b[ll] = tt;
}
for (ii = kk + 1; ii <= nn; ii++)
{
qq = ai[ii, kk] / ai[kk, kk];
for (jj = 1; jj <= nn; jj++)
{
if (jj == kk)
ai[ii, jj] = 0;
else
ai[ii, jj] = ai[ii, jj] - qq * ai[kk, jj];
}
b[ii] = b[ii] - qq * b[kk];
}
}
x[nn] = b[nn] / ai[nn, nn];
for (ii = nn - 1; ii >= 1; ii--)
{
tt = 0;
for (jj = 1; jj <= nn - ii; jj++)
{
tt = tt + ai[ii, ii + jj] * x[ii + jj];
x[ii] = (1 / ai[ii, ii]) * (b[ii] - tt);
}
}
sq = 0.0;
sq2 = 0.0;
for (n = i0; n <= i0 + p; n++)
{
sum = 0;
for (kk = 1; kk <= degree; kk++)
{
sum += x[kk + 1] * Math.Pow(n, kk);
}
prc[index - n] = (x[1] + sum);
sq += Math.Pow(TF.Close[index24h - n] - prc[index - n], 2); //before sq += Math.Pow(MarketSeries.Close[index - n] - prc[index - n], 2);
sq2 += Math.Pow(TF.Close[index24h - n] - prc[index - n], 2); //before sq2 += Math.Pow(MarketSeries.Close[index - n] - prc[index - n], 2);
}
sq = Math.Sqrt(sq / (p + 1)) * strdDev;
sq2 = Math.Sqrt(sq2 / (p + 1)) * strdDev2;
for (n = i0; n <= i0 + p; n++)
{
sqh[index - n] = (prc[index - n] + sq);
sql[index - n] = (prc[index - n] - sq);
sqh2[index - n] = (prc[index - n] + sq2);
sql2[index - n] = (prc[index - n] - sq2);
}
}
}
//just to check the price point
double sqld1 = Convert.ToDouble(sql.LastValue);
double sql2d1 = Convert.ToDouble(sql2.LastValue);
double sqhd1 = Convert.ToDouble(sqh.LastValue);
double sqh2d1 = Convert.ToDouble(sqh2.LastValue);
double prclined1 = Convert.ToDouble(prc.LastValue);
Print("d1 sql ", sqld1);
Print("d1 sql2 ", sql2d1);
Print("d1 sqh ", sqhd1);
Print("d1 sqh2 ", sqh2d1);
private int GetIndexByDate(MarketSeries series, DateTime time)
{
for (int i = series.Close.Count - 1; i > 0; i--)
{
if (time == series.OpenTime[i])
return i;
}
return -1;
}
}
}
@radoslawkupisek
radoslawkupisek
04 Nov 2019, 19:15
OK, what can we do if there is right code to write and read but we get "04/11/2019 20: 10: 21.934 | RK RENKO v9, EURUSD, Re10 | Crashed in OnStop with SecurityException: Permission request of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089' failed."?
@radoslawkupisek