Click here to Login





                                                   Need assistance with C# creating an indicator

  0

0
Mike
2015-05-31 01:34:06


Guys,

I need some assistance understanding how to reference the data of the present bar value of a VectorD. I want to test if the current bar value is the highest in the last lookback period by doing a comparison with my current highest value (algoithm loops to optimize variables).

I am new to C# so there is likely a simple gap in my understanding of how this should work.

The indicator I'm trying to build will find the highest sharpe value for combinations of the current stock and a specified bond. Lookback, % allocation and f factor are being optimised. this is based on Frank Grossmans articles

All advice appreciated! Thanks,
Mike

//////////extracted from full listing below

total = Nshares*close + Nbonds*Bondsymbol;

perf = TA.PerfD(total,LB);
sd = TA.Pow(TA.Stddev(total,LB),f);
Score = perf / sd;

if( Score < ScoreMax) <- This line fails I want to capture the highest Sharpe values generated by the optimised variables



//////////////Full listing

VectorD Bondsymbol = (VectorD)BondSymbol1;
VectorD close = cFunctions.Close;
VectorD total = 0; // stores the composite NoBonds*BondClosePrice + Noshares*ShareClosePrice close price
VectorD Score = 0;
double ScoreMax = 0;
int LBBest = 0;
double pSharesBest = 0;
double fBest = 0;
double pShares =100;
VectorD Nshares =0;
VectorD Nbonds =0;
VectorD perf =0;
VectorD sd=0;
int LB=0;
double f =0;
double scoretest =0;



cFunctions.SetForwardAndBackwardBars(81,0);

//VectorD bond = cFunctions.CompileFormula("bonda = getseries(" + BondSymbol + ",close);").GetVectorDouble("bonda");

for( LB =80;LB <81;LB++)
{
for(f=2.9;f<3;f=f+0.2)
{
for(pShares =100 ;pShares<101;pShares = pShares+10)
{
Nshares = (pShares/100) / TA.Ref(close,LB);
Nbonds = ((100 - pShares) / 100) / TA.Ref(Bondsymbol,LB);
total = Nshares*close + Nbonds*Bondsymbol;

perf = TA.PerfD(total,LB);
sd = TA.Pow(TA.Stddev(total,LB),f);
Score = perf / sd;

if( Score < ScoreMax) <- This line fails I want to capture the highest Sharpe values generated by the optimised variables
{
ScoreMax = Score.GetValue(0);
LBBest = LB;
pSharesBest = pShares;
fBest = f;
}
}
}
}

result = ScoreMax;



Mike
2015-05-31 03:54:08

  0

Further to this post...

I am checking the result of the script in the screener and as a test I sent Bondsymbol which is the time series of symbol TLT.

When I use the format Bondsymbol I get the correct value for the close price.
When I use the format Bondsymbol[0] I get a range of values with lots of NaN results on the screener result associated with each stock.

is this expected? Does anyone know what the current bar index value is that I should be using to get the correct result?

Thanks,
Mike



Mike
2015-05-31 05:20:49

  0

Ok so I think I've found it,

1) I think the script is calculating the entire vector for each stock and bar, so changed my max value variables to VectorD's. Then looped through all values in the array looking for the max value of each array element. I then needed to change teh way I created the cariable so it initialised to the same size as the score array I was comparing to. I did this at intialisation of variable ScoreMax = Bondsymbol-Bondsymbol;

I now seem to be getting values that seem more what I would expect. Though its incredibly slow to process...


for(int i=0;i< Score.Length;i++)
{

if( Score[i] > ScoreMax[i])
{
ScoreMax[i] = Score[i];
LBBest[i] = LB;
pSharesBest[i] = pShares;
fBest[i] = f;
}
}



QuantShare
2015-06-01 03:14:13

  0

Yes, you need to use [] to get a specific value from a series/vector.

In order to detect what is slowing the process, you should remove few lines of code at a time (without breaking the compilation), test then repeat. But I am guessing it is the different loops (for) that is causing this.



No more messages
0




Reply:

No html code. URLs turn into links automatically.

Type in the trading objects you want to include: - Add Objects
To add a trading object in your message, type in the object name, select it and then click on "Add Objects"










QuantShare

Trading Items
Consecutive Up and Down Bars - Works With Any Trading Indicator
Ichimoku Kinko Hyo - Trading Indicator
Dynamic Zones RSI - Technical Indicator
ADX Composite Indicator for the Stock Market
Coppock - VLT Momentum Indicator

How-to Lessons
How to add a trading indicator to a chart
How to screen for stocks having a high correlation with the Dow J...
How to hide a trading indicator from a particular time frame
How to use QuantShare with Metastock data
How to dynamically update the settings of an indicator

Related Forum Threads
Creating Watchlist with Two Timeframes
Need help with a MM Script
Alligator Indicator need Help
Creating Shortcuts with arrow keys? Function keys?
Creating my own indicator (basics)

Blog Posts
Working with the formula editor
How to Select the Best Market Indicator for your Trading System
Industry Analysis - How to Compare Stocks with their Industries
How to measure market strength with the composite tool
Backtesting chart patterns using the auto support and resistance ...









QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



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.