I have installed the Indicore Development Kit.
Is anywhere are sample for daily eurusd rates from marketscope?
Or how do I reach MarketScope from c#?
best regards
arne
Moderator: admin
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;
using gehtsoft.indicore;
namespace PriceHistPlusIndicator
{
class Program
{
static IndicatorManager mgr;
static FXCore.CoreAut mCore;
static FXCore.TradeDeskAut mDesk;
static string username;
static string password;
static string connection = "demo";
static string url = "www.fxcorporate.com";
static string timeFrame;
static string instrument;
static DateTime dtStart;
static DateTime dtEnd;
static int iMaxNum;
static List<MyIndicatorTickSource> tickPriceList = new List<MyIndicatorTickSource>();
static int iNumPeriods = 0;
static void Main(string[] args)
{
try
{
if (args.Length < 4)
{
Console.WriteLine("Not Enough Parameters!");
Console.WriteLine("USAGE: [application].exe [username] [password] [instrument] [timeframe] [datetime_start] [datetime_end] [max_number_periods]");
Console.WriteLine("\nPress any key to close the program");
Console.ReadKey();
return;
}
username = args[0];
password = args[1];
instrument = args[2];
timeFrame = args[3];
if (timeFrame == "t1")
{
Console.WriteLine("This program is not intended to use with ticks.\nPlease use other interval.");
Console.WriteLine("\nPress any key to close the program");
Console.ReadKey();
return;
}
if (args.Length > 4)
{
string strStart = args[4];
dtStart = Convert.ToDateTime(strStart);
}
else
{
dtStart = DateTime.MinValue;
}
if (args.Length > 5)
{
string strEnd = args[5];
dtEnd = Convert.ToDateTime(strEnd);
}
else
{
dtEnd = DateTime.MinValue;
}
if (args.Length > 6)
{
string strMaxNum = args[6];
iMaxNum = Convert.ToInt32(strMaxNum);
}
else
{
iMaxNum = 0;
}
mCore = new FXCore.CoreAut();
mDesk = (FXCore.TradeDeskAut)mCore.CreateTradeDesk("trader");
mDesk.Login(username, password, url, connection);
mgr = new IndicatorManager();
string path = (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\Software\\CandleWorks\\FXTS2", "InstallPath", "");
LoadErrorList errList;
errList = mgr.loadIndicators(path + "\\indicators\\standard");
foreach(string sError in errList)
{
Console.WriteLine("Error loading indicators {0}", sError);
}
errList = mgr.loadIndicators(path + "\\indicators\\custom");
foreach (string sError in errList)
{
Console.WriteLine("Error loading indicators {0}", sError);
}
IndicatorsCollection indicators = mgr.getIndicators();
Indicator indicator = indicators["MVA"];
if (indicator == null)
{
Console.WriteLine("Cannot find indicator \"MVA\"");
Console.WriteLine("Press any key to close the program");
Console.ReadKey();
return;
}
MyIndicatorTickSource tickSrc = new MyIndicatorTickSource();
GetAllPriceHistory(dtStart, dtEnd, iMaxNum);
foreach (MyIndicatorTickSource ts in tickPriceList)
{
for (int k = 0; k < ts.size(); k++)
{
MyIndicatorTickSource.tickData td = ts.getItem(k);
tickSrc.AddLast(td.dt, td.tickVal);
}
}
IndicatorParametersCollection parameters = indicator.getParameters();
//TODO: set parameters if needed
IndicatorInstance instance;
string sErr;
instance = indicator.getInstance(tickSrc, parameters, out sErr);
IndicatorOutputStreamsCollection _outputs = instance.getStreams();
List<IndicatorOutputStream> outputs = new List<IndicatorOutputStream>();
for (int i = 0; i < _outputs.Count; i++)
{
outputs.Add((IndicatorOutputStream)_outputs[i]);
}
instance.update(true, out sErr);
//print result
IndicatorOutputStream output = outputs[0]; // just one output for MVA
int max;
if (tickSrc.size() > output.size())
max = tickSrc.size();
else
max = output.size();
Console.WriteLine("Date;Tick;MVA;");
for (int i = 0; i < max; i++)
{
if (i < tickSrc.size())
{
if (i >= output.getFirstPeriod())
{
Console.WriteLine("{0};{1};{2}", tickSrc.getDate(i).ToString(), tickSrc.getTick(i), output.getTick(i));
}
else
Console.WriteLine("{0};{1};{2}", tickSrc.getDate(i).ToString(), tickSrc.getTick(i), "n/a");
}
else
{
Console.WriteLine("n/a;n/a;");
}
}
mDesk.Logout();
Console.WriteLine("\nDone! Press any key to close the program");
Console.ReadKey();
}
catch (Exception e)
{
if (mDesk != null)
{
mDesk.Logout();
}
Console.WriteLine("Exception {0}; \n\nPress any key to close the program", e.ToString());
Console.ReadKey();
}
}
static DateTime GetPreviousCandle(DateTime fromDate)
{
switch (timeFrame)
{
case "m1":
return fromDate.AddMinutes(-1);
case "m5":
return fromDate.AddMinutes(-5);
case "m15":
return fromDate.AddMinutes(-15);
case "m30":
return fromDate.AddMinutes(-30);
case "H1":
return fromDate.AddHours(-1);
case "H2":
return fromDate.AddHours(-2);
case "H3":
return fromDate.AddHours(-3);
case "H4":
return fromDate.AddHours(-4);
case "H6":
return fromDate.AddHours(-6);
case "H8":
return fromDate.AddHours(-8);
case "D1":
return fromDate.AddDays(-1);
case "W1":
return fromDate.AddDays(-7);
case "M1":
return fromDate.AddMonths(-1);
default:
return fromDate.AddMinutes(-1); // should not happen
}
}
static void GetAllPriceHistory(DateTime start, DateTime end, int iPeriodsLeft) //get the whole collection of price history (othewise we'll could get last 300 candles before end)
{
FXCore.MarketRateEnumAut rates = (FXCore.MarketRateEnumAut)mDesk.GetPriceHistory(instrument, timeFrame, start, end, iPeriodsLeft, true, true);
if (rates.Count > 0)
{
FXCore.MarketRateAut firstRate = (FXCore.MarketRateAut)rates.Item(1);
DateTime firstDt = firstRate.StartDate;
MyIndicatorTickSource ts = new MyIndicatorTickSource();
foreach (FXCore.MarketRateAut rate in rates)
{
ts.AddLast(rate.StartDate, rate.BidClose); // use close price
iNumPeriods++;
}
tickPriceList.Insert(0, ts);
if (iNumPeriods < iMaxNum)
{
DateTime prevCandle = GetPreviousCandle(firstDt);
if (prevCandle > dtStart)
{
GetAllPriceHistory(dtStart, firstDt.AddSeconds(-1), iMaxNum - iNumPeriods);
}
}
}
}
}
class MyIndicatorTickSource : IndicatorTickSource
{
private List<tickData> myData = new List<tickData>();
public tickData getItem(int i)
{
return myData[i];
}
private int precision = 4;
private double pipSize = 0.01;
private string instrument;
public struct tickData
{
public int serial;
public DateTime dt;
public double tickVal;
}
private int mSerial = 0;
public override string getName()
{
return "aaa";
}
public override int size()
{
return myData.Count;
}
public override bool isBar()
{
return false;
}
public override bool hasData(int index)
{
if (index >= myData.Count)
return false;
else
return true;
}
public override bool supportsVolume()
{
return false;
}
public void setInstrument(string instrument)
{
this.instrument = instrument;
}
public override string getInstrument()
{
return instrument;
}
public override int getSerial(int index)
{
return myData[index].serial;
}
public void setPipSize(double pipSize)
{
this.pipSize = pipSize;
}
public override double getPipSize()
{
return pipSize;
}
public void AddLast(System.DateTime dt, double val)
{
tickData td;
td.serial = ++mSerial;
td.dt = dt;
td.tickVal = val;
myData.Add(td);
}
public override double getTick(int index)
{
tickData tickD = myData[index];
double tick = tickD.tickVal;
return tick;
}
public DateTime getDate(int index)
{
DateTime dt = myData[index].dt;
return dt;
}
public override bool isBid()
{
return false;
}
public override bool isAlive()
{
return true;
}
public void setPrecision(int precision)
{
this.precision = precision;
}
public override int getPrecision()
{
return precision;
}
public override int getDisplayPrecision()
{
return precision;
}
public override int getFirstPeriod()
{
return 0;
}
public override DateTime date(int index)
{
return myData[index].dt;
}
}
}
Users browsing this forum: No registered users and 7 guests