Topics
12 Apr 2016, 23:58
 2238
 2
Replies

GoldnOil750
16 Nov 2015, 16:18

correction in above code

Set "Access Right"  to "Full Access" in the above code. 


@GoldnOil750

GoldnOil750
16 Nov 2015, 16:11

RE:

Spotware said:

Dear Trader,

When you use the count method to receive the number of the bars it includes the initial bar which has the index 0. So in other words the first bar has index 0, the second bar has index 1 and the n bar has index n-1. You can't use the count method to retrieve values in the way you do it. Since the code snippet you provide isn't in the OnBar() method and we don't know when your method is called we can't further assist you. Please also note that we don't provide coding assistance services. We more than glad to assist you with specific questions about cAlgo.API. You also contact one of our Partners or post a job in Development Jobs section for further coding assistance.

 

Dear SPOTWARE,

I have pasted the CODE HERE, BELOW to explain the frustration I am going through and will appreciate if you can explain that why do I GET  """TWO SETS OF DIFFERENT DATA"""  on OPEN AND CLOSE prices, when I CALL IT through ""OnBar()"   and when I call through "OnSTOP" function.  CAN YOU EXPLAIN THIS ?  and how do "WE" programmers know which is correct. 

Secondly, if you choose START DATE as 05-January-2015 to 09-Jan-2015,  you get 100 count of previous data, but if you chose a week in June or any other month you get around 197 count of previous data. SO HOW DO "WE" figure out what kind of previous data we will get on a particular time frame and on a particular date????

TIME FRAME = 15 minutes.  Currency = GBP/JPY

START DATE = 05-Jan-2015 to 09-Jan-15  (one week)

CODE (copy and paste and it will RUN and you can compare the two data.  One will be in the LOG FILE and the OTHER will be in a CSV file.  just compare and see for yourself.  Check from Count = 100 onwards :   THE OPEN & CLOSE PRICES in LOG file does not match with the one in CSV file.

THANK YOU !!!!

(waiting for your reply)

///S.Khan

 

 

using System.Globalization;
using System.IO;
using System.Threading;
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]

    public class SK_cBOT_BuySell_onSIGNAL : Robot
    {
        ////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////
        ////                        GLOBAL VARIABLES
        ////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////

        //private static string label_Trade = "B&S_SIGNAL-1";
        private int Bar_Count = 0;

        //END OF GLOBAL VARIABLES Declaration

        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////                        ON START
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        protected override void OnStart()
        {
            //Print Date Time to Display Charts/Screen
            string tempText1 = string.Format("{0:ddd-d-MM-y,h:mm tt}", Server.Time);
            Print("cBOT Start Date & Time : " + tempText1);
        }
        //End of On_START  function

        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////                        ON       BAR
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        protected override void OnBar()
        {
            int i = Bar_Count;

            Print(i, ",   ", MarketSeries.OpenTime[i], ",   ", MarketSeries.Open[i], ",   ", MarketSeries.Close[i], ",   ", MarketSeries.High[i], MarketSeries.Low[i],
            MarketSeries.TickVolume[i], MarketSeries.Median[i], MarketSeries.Typical[i], MarketSeries.WeightedClose[i]);

            Bar_Count += 1;
        }
        //End of On_TICK  function

        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////                        ON STOP
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        protected override void OnStop()
        {
            string temp_Text = string.Format("{0:ddd-d-MMM-y,h:mm tt}", Server.Time);
            Print("cBOT ''onStop'' Stop Date & time : " + temp_Text);

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            var desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            var folderPath = Path.Combine(desktopFolder, "trendbars");

            Directory.CreateDirectory(folderPath);

            var filePath = Path.Combine(folderPath, Symbol.Code + " SK " + TimeFrame + ".csv");

            using (var writer = File.CreateText(filePath))
            {
                for (var i = 0; i < MarketSeries.Close.Count + 1; i++)
                {
                    writer.WriteLine(ConcatWithComma(i, MarketSeries.OpenTime[i], MarketSeries.Open[i], MarketSeries.Close[i], MarketSeries.High[i], MarketSeries.Low[i], MarketSeries.TickVolume[i], MarketSeries.Median[i], MarketSeries.Typical[i], MarketSeries.WeightedClose[i]));
                }
                //END FOR
            }
            //END USING
        }
        //END FUNCTION : On_STOP

        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////            FUNCTION  CONCATE WITH COMMA
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        private string ConcatWithComma(params object[] parameters)
        {
            return string.Join(",", parameters.Select(p => p.ToString()));
        }
        //END FUNCTION : Concate with Comma
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    }
    //END OF MAIN PUBLIC CLASS
    //////////////////////////////////////////////

}
//END OF MAIN cALGO ROBOT
/////////////////////////////////////////////////////////////////////////

 


@GoldnOil750

GoldnOil750
16 Nov 2015, 10:11

RE:

Spotware said:

Dear Trader,

This is done on purpose to simulate the real time environment. When you start a cBot on a real time environment you have some candles from the past. In addition, Indicators which are calculated based on past values wouldn't work in if these candles were not existing.

 

THANK YOU !   BUT what about the OPEN AND CLOSE PRICE values.  why are they same ?  check the jpeg files.  on START DATE 8/June/15  it gives different values but if Start DATE is 15/June/15, it gives same values for both OPEN AND CLOSE in the Function MarketSeries.Open[count] or MarketSeries.Close[count].

same code, same everything just changing the START DATES on BACK TESTING !!!!

??????


@GoldnOil750

GoldnOil750
16 Nov 2015, 07:06

RE:

Daedalusx086 said:

Looks like that is being caused by the fact you're only updating the values for Current_Open_Price and Current_Close_Price at the start of each new bar.

 

That means that when you're getting the values for Current_Close_Price when only 1 tick has defined the current bar, which means the close price (the last tick) the system has for that bar also happens to be the starting (opening value) for that bar. Backtesting treats the tick flow as if it's in real-time for the bot, so won't let it see the "future" (namely the ticks yet to pass) from the bot's time reference.

 

You would need to adjust your code so it is updating the Current_Close_Price dynamically every few ticks if the Current_Close_Price is vital in your algo. 

 

Cheers.

 

Thank you for your comment.  What I understand is that "OnBAR" function gets triggers when a new BAR is found.  While I thought when a 'bar' has closed. 

Also, please see the first jpeg attachment. in that see the yellow underline and in that it is getting the "Close_Price" of the bar, every time perfectly.

 

also, why does cALGO throw the BAR data before the BACK-TESTING start date.  Like if the start date is 15June, but u will get data from 13/june or so and have to skip so many bars.


@GoldnOil750