Realtime Feed

Use all the fxcodebase indicator in your application!

Moderator: admin

Realtime Feed

Postby whninja » Thu Oct 21, 2010 12:48 pm

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
whninja
 
Posts: 15
Joined: Wed Aug 18, 2010 2:19 am

Re: Realtime Feed

Postby whninja » Fri Oct 22, 2010 6:21 am

Access via Order2Go Api
whninja
 
Posts: 15
Joined: Wed Aug 18, 2010 2:19 am

Re: Realtime Feed

Postby allpin » Wed Oct 27, 2010 1:16 pm

You can use "Order2Go" and "Indicore Integration SDK" in the same application. "Order2Go" would be used for getting prices, while "Indicore Intergration SDK" would be used for loading indicator, and using it on the price collection.
The steps of the program:
- Add "gehtsoft.indicore.dll" and "FXCore.dll" as the references to your project
- Copy "indicore2.dll" and "lua5.1.dll" to your target directory
- Create "Core" object
- Create "trade desk" object
- Login
- Create an instance of the "IndicoreManager"
- Load a list of indicators
- Get a list of indicator profiles
- Get the indicator profile
- Get the new instance of the indicator parameters
- Fill the values of the parameters
- Get a source for your indicator. In our case we used "MVA" indicator which uses tick source. We implemented "IndicatorTickSource" class. We used "GetPriceHistory" calls to fill the price collection. The "Close" price was used for creating "ticks".
- Create the instance of the indicator using the source you got
- Call "Update" method
- Process output
The example shows using "MVA" indicator on the prices (note: this program is not intended for use with ticks as time frame interval).

Code: Select all
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;
        }
    }
}


The command line should look like:
[application].exe [username] [password] [instrument] [timeframe] [datetime_start] [datetime_end] [max_number_periods]

Class "MyIndicatorTickSource" is intended to keep price collection.
Function "GetAllPriceHistory" is intended to get a price history of arbitrary length between two dates. Latest prices are retrieved first. This function is called recursively until we reach maximum number of periods or until we get to start date, whatever is first.
Function "GetPreviousCandle" is used to get the date one time frame earlier than specific date.
allpin
FXCodeBase: Confirmed User
 
Posts: 21
Joined: Thu Aug 19, 2010 3:29 pm


Return to C++/.NET API

Who is online

Users browsing this forum: No registered users and 2 guests