Possibilty found for adjusted continues contracts in MC

Questions about MultiCharts and user contributed studies.
Joerg
Posts: 24
Joined: 13 Feb 2007

Possibilty found for adjusted continues contracts in MC

Postby Joerg » 18 Apr 2008

Hello,

as I red in the duscussion forum it´s not natively supported to build cont. contracts. For me it seems a useful way to export the data of the old contract via the Print-Command in EasyLanguage to an ASCII file and import them into the new contract again (or use ASCII-Mapping which ensures that overwriting is´nt possible via Reloading). During the export the data can be adjusted to the level of the new contract and so the trading systems should give correct signals. Here´s my code for exporting Quotes via an indicator:

----------------------------------------------------------------------------------
Inputs: Target_Path("C:\"),Compression("1Min"),Decimals(4),Adjustment(0),Start_Date(19991231),End_Date(20071231);

Vars: Header(""),Path_String(""),FirstLine(true), Hour(""), Minute(""),Open_(""),High_(""), Low_(""),Close_(""),Vol_("");

Header = "Date,Time,Open,High,Low,Close,Volume"; //Header
Path_String = Target_Path&getsymbolname&"_"&Compression&".txt"; //Build File Name

If FirstLine = true then Print(File(Path_String),Header); //Add header
FirstLine = false;

If barstatus(1) = 2 then begin //Export only finished bars
If Date >= (Start_Date-19000000) and Date <= (End_Date-19000000)then begin //Restrict Exportet Time Period

Open_ = NumToStr(IntPortion(Open+Adjustment),0)&"."&RightStr(NumToStr(Open+Adjustment,Decimals),Decimals);
High_ = NumToStr(IntPortion(High+Adjustment),0)&"."&RightStr(NumToStr(High+Adjustment,Decimals),Decimals);
Low_ = NumToStr(IntPortion(Low+Adjustment),0)&"."&RightStr(NumToStr(Low+Adjustment,Decimals),Decimals);
Close_ = NumToStr(IntPortion(Close+Adjustment),0)&"."&RightStr(NumToStr(Close+Adjustment,Decimals),Decimals);
Vol_ = NumToStr(IntPortion(Volume),0);

Print(File(Path_String),ELDateToString(Date),",",FormatTime("HHmm",eltimetodatetime(time)),
",",Open_,",",High_,",",Low_,",",Close_,",",Vol_);

end;
end;
----------------------------------------------------------------------------------

Target_Path("C:\temp\"): Directory where the file will be written
Compression("1Min"): Will be added to the file name behind the symbol name
Decimals(4): No of places behind "." for the exported quotes; must be >=1
Adjustment(0): for getting adjusted data for reimporting into a cont. contract
Start_Date(YYYYMMDD): Beginning of export, must be plotted in the chart
End_Date(YYYYMMDD): End of exported data, typically the last active traded day of the old contract, must be plotted in the chart

If someone has ideas for improvements please let me know.

The data are also useable for ASCII-import into TS if someone needs it.

Regards

Joerg

zukkaweb
Posts: 125
Joined: 08 Feb 2008

Postby zukkaweb » 20 Aug 2008

thats's a good things, could the support test it to confirm that works well for any futures?

i find this

Description:

Very often you will need historical futures data so your indicators and/or trading systems work properly; the first few days a future contract is traded can not be analyzed because of lack of historical data. You will be able to create adjusted daily continuous future contracts by creating a new indicator. The Power Editor code for this Indicator is contained in the Futures Roll Over Indicator.

Usage:

When you apply this indicator to a future contract it will export all the price data to a ASCII file with the name specified in the input Trgt. Here is what you will have to do to create a continuous contract:

1. Determine what day you want to roll over the future contract. This date can be the first trading day of the current contract or any other day you feel would be appropriate for the roll over. We will call this the D Date.

2. Create two charts, one with the new symbol formatted so the D Date is shown on the chart, and a second chart showing the expired contract with the D Date as the last day to be displayed.

3. Calculate the difference between the Open of D Date bar of the new contract and the Close of the D Date of the old contract. This value will be the adjust amount, do not disregard a negative number if you get one.
For example: If the open of the D Date for the December contract is 691.90 and the close of the D Date of the September contract is 684.05, the difference is 7.85.

4. After you calculate the indicator created should be applied to the chart with the expired contract specifying the path and file name as the input Trgt and the adjustment amount as the input Adjust. Once you apply the indicator, a file with the file name specified in the input Trgt with the adjusted data will be created.

5. What is left is to go to either your Omega Server or Omega Downloader and import this ASCII file into the current contract. For example, you would apply the indicator to the September contract of the S&P and import the resulting ASCII file to the December contract of the S&P.

You will not be able to create continuous contracts of Server data because it is not possible to import ASCII tick data into your server.




Inputs:

Adjust - adjustment amount
Trgt - file name

EasyLanguage Code:

INPUTS: ADJUST(0), TRGT("C:\OMEGA\ROLL.TXT");

VAR: PS(0), TXT("");



TXT = NUMTOSTR(PRICESCALE,0);

PS = STRLEN(TXT) - 1;



IF BARNUMBER = 1 THEN BEGIN

FILEDELETE(TRGT);

FILEAPPEND(TRGT,"DATE,TIME,OPEN,HIGH,LOW,CLOSE,VOLUME,OI"+NEWLINE);

END;



FILEAPPEND(TRGT, NUMTOSTR(DATE,0) +","+ NUMTOSTR(TIME,0) +","+

NUMTOSTR(OPEN+ADJUST,PS) +","+ NUMTOSTR(HIGH+ADJUST,PS) +","+

NUMTOSTR(LOW+ADJUST,PS) +","+ NUMTOSTR(CLOSE+ADJUST,PS) +","+

NUMTOSTR(VOLUME,0) +","+ NUMTOSTR(I,0)+NEWLINE);



PLOT1(CLOSE,"ROLLO");


Return to “MultiCharts”