Click here to Login





                                                   How do I get the date of the current bar in a custom function?

  0

0
Chaim6
2014-09-14 23:25:20


I tried:

DateTime ThisBar = cFunctions.Date;
result = ThisBar.ToString() ;
cFunctions.SetForwardAndBackwardBars(0, 0);

When run in the screener it says 1/3/1950. What's the right way to do this? My goal is to create a function that returns 1 if the current bar is the last bar of the month. This function would be useable across a number of my systems.

Thanks.



QuantShare
2014-09-15 03:50:11

  0

cFunctions.Date returns a Vector not a single DateTime.

Please use the exising function:
a = IsLastBar();




Chaim6
2014-09-15 14:55:41

  0

Maybe I wasn't so clear about this. I am writing a custom function to tell me if the current bar is the last bar of the month. This is useful for simulations that use daily bar periods to signal a trade at the end of the month. I could write the code in the simulation itself but then I would need to duplicate it for each sim. I figured that creating a custom function to be shared by many sims is a better way.

The first step is getting the date of the current bar. That's where I'm stuck. I tried using cFunctions.Date and cFunctions.Date[0]. They both returned the same date in 1950. Doesn't 0 index the *current* bar of the vector?

Thanks



Chaim6
2014-09-15 19:09:40

  0

When running a simulation using a custom function, is the custom function called once for the entire vector or is it called anew for each bar? I am assuming that the answer is yes. Therefore to get the number of days in this month:

// Returns the number of days in this month
VectorDate dates = cFunctions.Date;

for (int i = 0; i < result.Length; i++)
{
result[i] = DateTime.DaysInMonth(dates[i].Year, dates[i].Month);
}

cFunctions.SetForwardAndBackwardBars(0, 0);

This seems to work!



QuantShare
2014-09-16 05:12:04

  1

The custom function is called once for the entire vector.
date[0] references the first bar
date[date.Length - 1] references the last/current bar



Chaim6
2014-09-16 15:04:41

  0

Thanks. Did you mean to point out a possible bug? Is date.Length different than result.Length?


QuantShare
2014-09-17 03:38:38

  0

No, both are vectors and all vectors in a custom function have the same size.
I used "date" vector because you wanted to get the last date.



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
How far are the close prices from the support line
Derivatives: Number of days until the expiration date
Decreasing the Trailing Stop Level every Trading Bar
Vary the Start Date of a Trading System Simulation
Top 20 stocks with the highest 10 day rate of change - Current an...

How-to Lessons
How to change volume bar colors when the price closes down
How to display the bar index of a stock on a chart
How to get stocks for a particular index using the global script
How to plot the relative performance of several stocks/indices
How to add a metric in the trading system simulation report

Related Forum Threads
Get the Previous N bar Date/DateTime in Money Management script
How to get the last day of the month in C#
How do I find the close price for an entry matching a custom DB
How to update the custom variables (var1,var2,...) in a position ...
How do I change the date format?

Blog Posts
Fundamental analysis: How to track economic indicators in the For...
Create custom metrics for the statistical data analysis tool
How to create the advance/decline market breadth indicator
How to use the new Market Regimes Feature in QuantShare Trading S...
How to Calculate and Display the Bid/Ask Spread on a Chart









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.