I am trying to implement a rule in my Trading System, where I would like to close the position on a symbol before 3 days of the earning and reopen 5 days after the earning if some certain conditions are met.
I am backtesting using the Historical Earnings Calendar for Major Stock Exchanges: https://www.quantshare.com/item-742-historical-earnings-calendar-for-major-stock-exchanges
I was trying to use GetCustomDatabaseData in the Money Management script in the following way:
It looks like the customValues.Length is always 0. What I am doing wrong?
Unfortunately I did not found an useful example which would demonstrate the usage of the GetCustomDatabaseData.
Could you please provide me an example how could I check whether there is or not and earning announcement in the next 3 days or if there was one 5 days ago based on the Divers.CurrentDate.
What would be the best solution for this problem?
You can use the QS language instead of the money management tool.
e1 = GetDataCount("earnings_cal", "timeday");
buy = hhv(e1, 5) > 0; // earnings in the past 5 bars
buy = hhv(e1, -3) > 0; // earnings in the next 3 bars
You can plot these on a chart to have a visual confirmation.
My Trading system needs some advanced calculation which are not supported in the QS language (some calculations are using the EntryPrice which as I understood is not available in the QS language), therefore most of my strategy is implemented inside the Money management tool.
Isn't possible to achieve the same result in the Money management tool what you have provided in QS language?
Any other alternatives?
The "VectorCustom" class will contains database data. To access the current bar date, you need to use [0], to get the previous bar [1].
Example:
VectorCustom earnings_cal_Timeday = Data.GetCustomDatabaseData("earnings_cal", "timeday", symbol);
CustomDatabaseValues c = earnings_cal_Timeday[0]; // To get current bar data
The easiest way to achieve what you want is to mix C# with QS language. Example:
TimeSeries t = Data.ParseFormula("a = rsi(14);").GetTimeSeries(symbol, "a");
t[0] to get current bar RSI value (in the above example)
Yes I am using the mixture of C# code with QS language and it works well.
Regarding to the custom database read, as I understood I can use earnings_cal_Timeday[0]; to get the current bar data and earnings_cal_Timeday[1]; to get the previous bar data, but as I see it isn't possible to get the next bar data, because the earnings_cal_Timeday VectorCustom contains data until the current bar. Is this true?
In my case I need to get data for the next days as well. Is this possible?
Unfortunately based on your answers it is still not clear how can I get the data what I need using the money management script combining with "Data.ParseFormula" function.
So let summarize here what I want to achieve:
I am using the following database for the earnings calendar:
(see the screenshot)
https://drive.google.com/open?id=12XxZL67Jmd3HNRCq6AhWHONJSGsaJKsN
What I need is very simple, in the money management script I want to check if there will be an earning announcement 3 bars later or not.
Knowing the database I am using could you please provide me the exact code using Money Management script ( and combined with QS language if it is needed) to achieve what I need.
I had to replace the hhv(e1, -3) > 0; with hhv(ref(e1, -3),1) > 0; because I have to move 3 bars ahead and for that bar I am checking whether there is an announcement or not.
Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.