Click here to Login





                                                   Turning the present value of an array into AN INTEGER (not array)?

  0

0
Josh McCormick
2020-07-11 21:05:20


I am working with a function that requires the input to be an integer, and only an integer.
The input value *cannot be an array*.

The problem *CANNOT BE SOLVED* like this:
cl = ref(close,0);

Why? Because cl is yet another array at the current offset.

Is there any way to create an integer type variable which holds the current single value from an array?

Actually, let me go ahead and give you the real problem.

period=Round (Ht_DCPeriod(),0);
s = relative_vigor_index_signal(period);
plot(s, "Signal", colorRed, ChartLine, StyleBringToFront|StyleWidth2);

I'm using HT_DCPeriod to provide my period. (The output is in the 10-30 range.) This works well for a number of indicators, but there are a few (like relative_vigor_index_signal) which just seems to barf on it. I've verified that I end up with an integer in the 10-30 range. And if I say "period=30" it works. But if I try an array of numbers (like close) it fails.

A message "Error in formula relative_vigor" flashes on the plot.
The code for relative_vigor_index_signal is as follows:

var p : int = period[0];
var formula : String = "p = " + p + ";v1 = ((close-open)+(2*Ref(close-open,1))+(2*Ref(close-open,2))+Ref(close-open,3))/6;v2 = ((high-low)+(2*Ref(high-low,1))+(2*Ref(high-low,2))+Ref(high-low,3))/6;d = iff(Sum(v2,p)==0, 0.0001, Sum(v2,p));rvi = Sum(v1, p)/d;rviS = (rvi+Ref(2*rvi,1)+Ref(2*rvi,2)+Ref(rvi,3))/6;";

result = cFunctions.CompileFormula(formula).GetVectorDouble("rviS");


Thanks again,
Josh



QuantShare
2020-07-13 13:10:40

  0

Josh,

The formula is working well. It it is named: relative_vigor_index_signal then simply use something like that in QuantShare and it should work:

a = relative_vigor_index_signal(10);
plot(a, "");



Josh McCormick
2020-07-13 20:50:12

  0

Here's a simplified version of what I'm wanting to do:

period=Round (HT_DCPeriod(),0);
s = relative_vigor_index_signal(period);

The function HT_DCPeriod is designed to return the ideal period for many different functions, so I'm wanting to use the value it provides as my period.
Unfortunately, my chart is flashing a message which says, "Compilation error in 'relative_vigor_index': Type mismatch

This fails, too:
s = relative_vigor_index_signal(Round (HT_DCPeriod(),0));
plot(s, "IndexSig", colorPurple, ChartLine, StyleBringToFront|StyleWidth2);
That doesn't flash a message, but it doesn't plot the line and at the top it says "IndexSig: NaN".

I'm needing some help getting this to allow me to use a *dynamic* variable (not just "period=10") or a function for my input period.

HELP?



QuantShare
2020-07-18 11:22:05

  0

The "relative_vigor_index_signal" implementation gets the first value of the "period" variable/vector to make calculation.
var p : int = period[0];

If the value returned by:
Round (HT_DCPeriod(),0) is Nan or something not numeric then it will create issues.



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
Foreign Exchange Value of the Dollar - Nominal Indexes
Measure the value of the stock market using the Q-Ratio valuation...
PREV - Previous value of the same formula
The Best trading rules for the ADX technical indicator
Trading rules using the VIX Index

How-to Lessons
How to quickly select stocks based on the last value of a databas...
How to calculate the average of a time series using the money man...
How to import trades into a portfolio
How to create a volatility-based Stop - Dynamic stop based on the...
How to display the bar index of a stock on a chart

Related Forum Threads
Replacing value for the last 100 bars (end of day data)
STOP/Profit targets based on the indicator value at the time of e...
Access the equity value of the portfolio from the simulator
Can Pivot Tables run my symbols in the order provided? (not sorte...
Graphing hypothetical candlesticks into the future?

Blog Posts
How to create the advance/decline market breadth indicator
Download Trading Data using the Post-Script
Backtesting chart patterns using the auto support and resistance ...
QuantShare Trading Software: New Features in the 3.4.2 Version
How to Automatically Import Local Data Into QuantShare









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.