Moving data between MC and Portfolio BackTester

Questions about MultiCharts and user contributed studies.
AMarsland
Posts: 28
Joined: 30 Sep 2010
Has thanked: 5 times
Been thanked: 1 time

Moving data between MC and Portfolio BackTester

Postby AMarsland » 09 Dec 2011

Tags: ADE, All Data Everywhere, EL Collections, Portfolio Backtester

Hi All,

I was wondering whether some EL Guru could point me in the direction of a solution to this challenge???

I want to transfer Close data from 23 individual MC price charts to be used in a Portfolio BackTester strategy trading the same 23 symbols.

The code below works perfectly on an MC feeder workspace to MC strategy workspace basis:

Code: Select all

// MultiCharts to MultiCharts
//Sender Code
[LegacyColorValue = true];
Vars: Class("OHLCV"),// class name for our test data
Vol(0);
// Calculate correct total volume regardless of bar type
Vol = IFF(BarType < 2, UpTicks + DownTicks, Volume);
// Store the data for this symbol and bar interval
Value1 = ADE.PutOHLCV(GetSymbolName, ADE.BarInterval, ADE.BarID, Open, High, Low, Close, Vol);

Code: Select all

// MultiCharts to MultiCharts
//Receiver Code
ade1 = ADE.GetOHLCV("SPY",0, ADE.BarID, Value1, Value2, Value3, SPY_Close, Value4);
ade2 = ADE.GetOHLCV("SH", 0, ADE.BarID, Value5, Value6, Value7, SH_Close, Value8);
ade3 = ADE.GetOHLCV("QQQ",0, ADE.BarID, Value9, Value10, Value11, QQQ_Close, Value12);
//ETC...
The above code works fine within ONE instance of MultiCharts. It will not transfer data between two instances of MultiCharts or MultiCharts to Portfolio BackTester

To transfer the data between applications Tech Support advised I need to save the OHLCV data to a file that then was called from the Strategy. I tried this:

Code: Select all

// MultiCharts to File code
//Sender Code
Inputs:
UseFile(ADE.UseFile);
Vars:
Class("OHLCV"),
Vol(0),
WriteOk(true);
// If UseFile is true, load any previously stored data from the file on the first bar.
if CurrentBar = 1 and UseFile then
Value1 = ADE.OpenMap(Class, GetSymbolName, ADE.BarInterval);
// Calculate correct total volume regardless of bar type
Vol = IFF(BarType < 2, UpTicks + DownTicks, Volume);
// Store the data for this symbol and bar interval
Value1 = ADE.PutOHLCV(GetSymbolName, ADE.BarInterval, ADE.BarID, Open, High, Low, Close, Vol);
// If UseFile is true, save the data to the file on the last bar.
if LastBarOnChart and BarStatus(1) = 2 and UseFile and WriteOk then begin
Value1 = ADE.SaveMap(Class, GetSymbolName, ADE.BarInterval);
WriteOk = false; // prevent repeated writes on new bars
end;
My attempt at reading the ADE data file so it can be used by Portfolio Backtester

Code: Select all

// File to PortfolioBactester code
//Receiver Code
Inputs:
UseFile(ADE.UseFile),
Interval(0);
Vars:
Class("OHLCV"), // class name for our test data
ade1(0),ade2(0),ade3(0),SPY_Close( 0 ),SH_Close( 0 ),QQQ_Close( 0 );
// If UseFile is true, load any previously stored data from the file on the first bar.
if CurrentBar = 1 and UseFile then begin
Value1 = ADE.OpenMap(Class,"SPY",Interval);
Value1 = ADE.OpenMap(Class,"SH",Interval);
Value1 = ADE.OpenMap(Class,"QQQ",Interval);
//ETC...
end;
// Get Close data from other charts
ade1 = ADE.GetOHLCV("SPY", 0, ADE.BarID, Value1, Value2, Value3, SPY_Close, Value4);
ade2 = ADE.GetOHLCV("SH", 0, ADE.BarID, Value5, Value6, Value7, SH_Close, Value8);
ade3 = ADE.GetOHLCV("QQQ", 0, ADE.BarID, Value9, Value10, Value11, QQQ_Close, Value12);
//ETC...
This is not working... All pointers gratefully received

Anthony

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Moving data between MC and Portfolio BackTester

Postby JoshM » 10 Dec 2011

I'm afraid I can't be of much help, but..
I want to transfer Close data from 23 individual MC price charts to be used in a Portfolio BackTester strategy trading the same 23 symbols.
Why don't you use a shared data map in the Portfolio Backtester? That should work, and perhaps can also prevent some reading errors when symbol A and symbol B both want to read file Z at the same time. And the Close data is already available in the Portfolio Backtester.

You said it worked perfectly when passing data between workspace A and workspace B, but not between Portfolio Backtester and MultiCharts. If I were you, I'd start at looking at these text files (perhaps a BarInterval wrong value why looking up fails?), and work backwards from that.

Good luck!

Josh

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Moving data between MC and Portfolio BackTester

Postby JoshM » 10 Dec 2011

Why don't you use a shared data map in the Portfolio Backtester?
Something like..

Code: Select all

Variables:
listOfPrices(ListN.Share("myPrices"));


if (CurrentBar < 200) then begin

// Add current close to the list
value1 = ListN.PushBack(listOfPrices, Close);

end;

// Export list
if (CurrentBar = 201) and (GetSymbolName = "EUR/GBP") then begin

value2 = ListN.Sort(listOfPrices, True);

// Get max en min values
value10 = ListN.Front(listOfPrices);
value11 = ListN.Back(listOfPrices);

FileAppend("C:\Temp\ExampleSharedList_10-12-11.txt",
Text(NumToStr(CurrentTime_s, 0), Spaces(3),
"Highest value of all instruments: ", NumToStr(value10, 5), Spaces(3),
"Lowest value: ", NumToStr(value11, 5)
)
);

value12 = ListN.Clear(listOfPrices);

end;
(Note: since I don't have the ADE DataMap functions imported here, this example is based on a Shared List. However, the principle/working is the same)

That code applied in the Portfolio Backtester on four instruments (USD/JPY, EUR/GBP, USD/CHF, GBP/USD) gives the following output in C:\Temp\ExampleSharedList_10-12-11.txt:

Code: Select all

94943 Highest value of all instruments: 81.73700 Lowest value: 0.85471
..which would be the highest close of USD/JPY and lowest of EUR/GBP (or GBP/USD?).

Anyway, this quick example shows that a shared list/data map does work in Portfolio Backtester, and is perhaps easier/quicker than writing to and reading from a file.

Regards,
Josh

AMarsland
Posts: 28
Joined: 30 Sep 2010
Has thanked: 5 times
Been thanked: 1 time

Re: Moving data between MC and Portfolio BackTester

Postby AMarsland » 10 Dec 2011

Hey Josh,

Thanks for your pointers.

As clarification the ADE code above works at passing OHLCV data through memory between MC workspaces. The write to file function doesn't work...

I like your idea of using a shared list to store closing prices on each passing bar. The strategy could then store them in variables rather than looking to an ever growing list for data.

I wonder whether 23 separate lists of one price data point is easier to work with than a single list of 23 data points?

Warm regards,

Anthony

AMarsland
Posts: 28
Joined: 30 Sep 2010
Has thanked: 5 times
Been thanked: 1 time

Moving data between Portfolio BackTester signals

Postby AMarsland » 13 Dec 2011

To keep this thread tidy here is A solution:

Define a Symbol/Number shared list (MapSN.Share) in variables and store each days/bars closing price. Place this in its own signal with a clone of the same portfolio of instruments the main signal will be used on:

Code: Select all

Vars:
ClosingPrices(MapSN.Share("Prices"));

// PUT today's Close price in shared map of symbols/prices called Closing_Prices ready for use tomorrow
if symbol = "SPY" then
Value1 = MapSN.Put(ClosingPrices,"SPY",Close);
if symbol = "SH" then
Value1 = MapSN.Put(ClosingPrices,"SH",Close);
if symbol = "QQQ" then
Value1 = MapSN.Put(ClosingPrices,"QQQ",Close);
//ETC...
This will now run on every symbol in the portfolio and if symbols match will store a close price. As each bar passes so the last closing price is overwritten in the Map. This keeps the code light-weight and speedy.

Note: With no date/time indexing the list this part of the code needs to run in its own signal and above the main code so that the prices do not change in the Map half way through a run...

In the 2nd signal define the shared map and then go GET the shared list of closing price values:

Code: Select all

Vars:
ClosingPrices(MapSN.Share("Prices")),
SPY_Close( 0 ),SH_Close( 0 ),QQQ_Close( 0 );

if date <> date[1] then begin
// Get yesterday's Close price from shared map of symbols/prices called Closing_Prices
SPY_Close = MapSN.Get(ClosingPrices,"SPY");
SH_Close = MapSN.Get(ClosingPrices,"SH");
QQQ_Close = MapSN.Get(ClosingPrices,"QQQ");
//ETC...
It's not as tidy as it could be BUT it works. When I work out how to index the data PUTS and GETS and only hold 2-3 bars of data in the list I will update this thread to show how the code can work from one signal.

Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Re: Moving data between MC and Portfolio BackTester

Postby Jonny473 » 02 Sep 2018

Thanks for the info AMarsland!
Can you make an example of how these two strategies look like in greater detail? Make an example of the strategy code around it?

Sorry but at the moment I am working with ADE in a normal chart window, having applied an Indicator to deliver the Symbol data and strategy info:

Code: Select all

// Store the indicator values in InfoMap so that we can pass it to ADE.PutBarInfo
Value1 = MapSN.Put(InfoMap, "MyPattern_XX", PatternDetected);
// Store the data for this symbol and bar interval.
// ADE.PutBarInfo will copy the information from our InfoMap into the appropriate DataMap.
Value1 = ADE.PutBarInfo(Class, GetSymbolName, ADE.BarInterval, ADE.BarID, InfoMap);
// If UseFile is true, save the data to the file on the last bar.
if LastBarOnChart and UseFile and WriteOk then begin
Value1 = ADE.SaveMap(Class, GetSymbolName, ADE.BarInterval);
WriteOk = false; // prevent repeated writes on new bars
received by my signal/strategy applied to another chart:

Code: Select all

// Retrieve the info for the current symbol and bar interval into InfoMap
Value1=ADE.GetBarInfo(Class, GetSymbolName, ADE.Daily, ADE.BarID, InfoMap);
PatternDetected_1=MapSN.Get(InfoMap, "MyPattern_XX");
Thanks

Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Re: Moving data between MC and Portfolio BackTester

Postby Jonny473 » 06 Sep 2018

Does anybody have a hint here?


Return to “MultiCharts”