mpatek
30th August 2010, 02:19 AM
Hello,
here is my first Vitamin-C code for Relative Performance analysis with the baseline security.
Code can be used for inter market analysis as well as for just simple relative performance analysis. While the code is working fine, I am not happy with its structure. Two functions have to be called from the Metastock Function builder. I was wondering if multiple charts per one window can be output from one MS call to code inside the c-function? For example, how to create the MACD indicator in Vitamin-C to just call MACD() function from MSFL? It would have to return two moving averages into one window.
Thanks and enjoy,
mpatek
++++++++++++++++++++++++++++++++++++++
/* This code allows charting of relative performance of multiple securities,
as described by Phil Doyle in Stocks & Commodities, May 2001 p.16
Relative performance with a base security can be evaluated from any user-define
date. Performance of base security is set to zero and performance (%) of other
securities is related to it.
MSFL
Baseline performance between a stock close price and close of SP500 (or any
other index/stock)from a given date forward. Date is set in Metastock function
Corresponding MLF is:
BAS:= Per()-Security("D:\MetaStockData\indexes\^GSPC",Per());
ExtFml( "VitaminC.CallScript1",
"baseline.c", { name of script file }
"Baseline(YYYYMMDD)", { function name and date }
BAS { Relative performance }
);
0;
*/
void Baseline(int _date)
{ float offset=0;
for(int i=0;i<BarCount;i++)
{
if(GetDate(i) == _date) //retrieve relative performance on the requested day
offset=User1[i];
if(GetDate(i) >= _date) //Draw RelPerf from that date on
{ Result[i]=User1[i]-offset; // start at zero for that date
}
else
Result[i]=0;
}
}
//*************************************************
/* Baseline performance with SP500 as a base and other stock/index
also in relation to SP500.
MSFL
BAS:= Per()-Security("D:\MetaStockData\indexes\^GSPC",Per());
GLD:= Security("D:\MetaStockData\SPDR\GLD",Per())-Security("D:\MetaStockData\
indexes\^GSPC",Per());
ExtFml( "VitaminC.CallScript1",
"baseline.c", { name of script file }
"Baselineint(20100104)", { function name and starting date }
BAS { base security - SP500 }
);
0; {draw line at zero}
ExtFml( "VitaminC.CallScript1",
"baseline.c", { name of script file }
"Baselineint1(20100104)", { function name and starting date }
GLD { another security/index - e.g. gold }
);
*/
void Baselineint(int _date)
{ float offset1=0;
for(int i=0;i<BarCount;i++)
{
if(GetDate(i) == _date) //retrieve relative performance on the requested day
offset1=User1[i];
if(GetDate(i) >= _date) //Draw RelPerf from that date on
{ Result[i]=User1[i]-offset1; // start at zero for that date
}
else
Result[i]=0;
}
}
void Baselineint1(int _date)
{ float offset1=0;
for(int i=0;i<BarCount;i++)
{
if(GetDate(i) == _date) //retrieve relative performance on the requested day
offset1=User1[i];
if(GetDate(i) >= _date) //Draw RelPerf from that date on
{ Result[i]=User1[i]-offset1; // start at zero for that date
}
else
Result[i]=0;
}
}
here is my first Vitamin-C code for Relative Performance analysis with the baseline security.
Code can be used for inter market analysis as well as for just simple relative performance analysis. While the code is working fine, I am not happy with its structure. Two functions have to be called from the Metastock Function builder. I was wondering if multiple charts per one window can be output from one MS call to code inside the c-function? For example, how to create the MACD indicator in Vitamin-C to just call MACD() function from MSFL? It would have to return two moving averages into one window.
Thanks and enjoy,
mpatek
++++++++++++++++++++++++++++++++++++++
/* This code allows charting of relative performance of multiple securities,
as described by Phil Doyle in Stocks & Commodities, May 2001 p.16
Relative performance with a base security can be evaluated from any user-define
date. Performance of base security is set to zero and performance (%) of other
securities is related to it.
MSFL
Baseline performance between a stock close price and close of SP500 (or any
other index/stock)from a given date forward. Date is set in Metastock function
Corresponding MLF is:
BAS:= Per()-Security("D:\MetaStockData\indexes\^GSPC",Per());
ExtFml( "VitaminC.CallScript1",
"baseline.c", { name of script file }
"Baseline(YYYYMMDD)", { function name and date }
BAS { Relative performance }
);
0;
*/
void Baseline(int _date)
{ float offset=0;
for(int i=0;i<BarCount;i++)
{
if(GetDate(i) == _date) //retrieve relative performance on the requested day
offset=User1[i];
if(GetDate(i) >= _date) //Draw RelPerf from that date on
{ Result[i]=User1[i]-offset; // start at zero for that date
}
else
Result[i]=0;
}
}
//*************************************************
/* Baseline performance with SP500 as a base and other stock/index
also in relation to SP500.
MSFL
BAS:= Per()-Security("D:\MetaStockData\indexes\^GSPC",Per());
GLD:= Security("D:\MetaStockData\SPDR\GLD",Per())-Security("D:\MetaStockData\
indexes\^GSPC",Per());
ExtFml( "VitaminC.CallScript1",
"baseline.c", { name of script file }
"Baselineint(20100104)", { function name and starting date }
BAS { base security - SP500 }
);
0; {draw line at zero}
ExtFml( "VitaminC.CallScript1",
"baseline.c", { name of script file }
"Baselineint1(20100104)", { function name and starting date }
GLD { another security/index - e.g. gold }
);
*/
void Baselineint(int _date)
{ float offset1=0;
for(int i=0;i<BarCount;i++)
{
if(GetDate(i) == _date) //retrieve relative performance on the requested day
offset1=User1[i];
if(GetDate(i) >= _date) //Draw RelPerf from that date on
{ Result[i]=User1[i]-offset1; // start at zero for that date
}
else
Result[i]=0;
}
}
void Baselineint1(int _date)
{ float offset1=0;
for(int i=0;i<BarCount;i++)
{
if(GetDate(i) == _date) //retrieve relative performance on the requested day
offset1=User1[i];
if(GetDate(i) >= _date) //Draw RelPerf from that date on
{ Result[i]=User1[i]-offset1; // start at zero for that date
}
else
Result[i]=0;
}
}