How to use end of data in live trading

Posted By: stephane97490

How to use end of data in live trading - 06/23/17 16:45

Hi everybody ,
I have some difficulty for implementing a live trading. I have a solution to the problem but It requires to use R. So It's not a efficient solution. First of all, suppose you have the the strategy below :
function run()
{
StartDate = 20110101;
EndDate = 20171231;
BarPeriod = 60*24; //
LookBack = 600;

set(PRELOAD|LOGFILE|PLOTNOW);
assetHistory("^GSPC",FROM_AV);
asset("^GSPC");
PlotHeight1 = 800; // height of the chart with results
PlotWidth = 2000;

/////////////////////////////////
vars Price = series(priceClose());
vars high=series(priceHigh());
vars low=series(priceLow());
vars zerolag=series(KAMA(Price,10));
vars fastema = series(EMA(Price,50));
vars slowema = series(EMA(Price,80));

asset("SPX500");
if(fastema[0]>slowema[0])
{
enterLong();

}

if(fastema[0]<slowema[0])
{
exitLong();

}


}


I use it for backtest, and it's working but It's not the case in live trading (no asset data for ^GSPC).
I've said that , there is a solution to solve it : the use of R. I call R via the script and I do all calculation in R, and I retrieve the signal for trading. In real case, if I have a lot of calculation, and multiple account to manage. It's became hard to do this.

So can you give me some advise or suggestion to solve my problems without using R .
THANKS FOR YOUR HELP !! :-)
Posted By: Spirit

Re: How to use end of data in live trading - 06/24/17 14:46

Is ^GSPC in your asset list?
Posted By: stephane97490

Re: How to use end of data in live trading - 06/26/17 19:09

i added ^GSPC in my asset list : it says :
Error 53 : ^GSPC is not unavailable at this time

But Zorro says that is possible to use external data to trade asset in the borker's user.
Posted By: jcl

Re: How to use end of data in live trading - 06/27/17 12:38

^GSPC is most likely not available from IB. IB assets don't begin with a '^' character. Check if IB has that asset at all, and if so, with which name. Otherwise you could download it from Quandl, with the dataFromQuandl function. If neither IB nor Quandl have it, then we've got a problem.
Posted By: stephane97490

Re: How to use end of data in live trading - 06/27/17 16:18

Hi,
In fact, ^ GSPC is the ticker of the SP500 on the alpha vantage data provider. As I said, my algorithms works better with external data rather than from the broker. The best choice for me is alpha vantage. The main problem I have is to use the external data (sp500 from alpha vantage) I use to trade the fxcm sp500.
Zorro says that is possible but I don't know how to code it, I've try to use set(PRELOAD), but It isn't woking :-(
Posted By: jcl

Re: How to use end of data in live trading - 06/28/17 17:23

AlphaVantage delivers historical EOD data. If you want to use that for live trading, you must download it once per day. This is a bit tricky. Call assetHistory with FROM_AV|IMMEDIATE - this works at any call and not only at trading start. Then load the resulting .t1 file into a database and get the current price from the last record.
Posted By: stephane97490

Re: How to use end of data in live trading - 06/29/17 14:39

Thanks,
May be, it will require more tricky , but i'd like to use 1000 records on the open, high, low and close in the data. Can i store them in priceHigh or else for example , and do the calculation ?
Posted By: jcl

Re: How to use end of data in live trading - 06/30/17 08:31

Yes, with the priceSet() function, but you normally need only to set the prices of the current day. The prices of the previous days have then already been set.
Posted By: stephane97490

Re: How to use end of data in live trading - 06/30/17 16:51

thnaks for your help. I've looked up on the data download by alpha vantage. So it return the daily data and the last record. I've tried to use priceSet, but in live mode it returns :
Trade: model2 2017-06-30
Lookback period (145 bars)
Error 030: asset ^GSPC missing in INITRUN
Error 011: Function KAMA called with invalid parameters (no price)
Error 011: Function EMA called with invalid parameters (no price)

It seems the script won't charge the database ^GSPC.t6 in live mode.
© 2024 lite-C Forums