#twitter-follow { border: 0;position: fixed; top: 240px; left:0;} #live-support { border: 0;position: fixed; top: 370px; left:0;} #knowledge-base { border: 0;position: fixed; top: 170px; left:0;}

 newbie looking for function help 0

 John Faig 2012-01-17 21:14:38 I am trying to recreate an indicator I used in a different trading platform. It takes three moving averages and creates an indicator of the strength of an uptrend (U1, U2, or U3) or a downtrend (D3, D2, D1). The function has lots of errors. I will eventually figure it out, but would appreciate some hlep to move up the learning curve faster. var score : int; var sma20_one_day : double; var sma65_one_day : double; var sma130_one_day : double; //VectorD pj = cFunctions.CreateNumericVector(); VectorD sma20 = cFunctions.CompileFormula("a = SMA(20);").GetVectorDouble("a") VectorD sma65 = cFunctions.CompileFormula("b = SMA(65);").GetVectorDouble("b") VectorD sma130 = cFunctions.CompileFormula("c = SMA(130);").GetVectorDouble("c") VectorD close = cFunctions.Close; for(int i = 130;i sma20_one_day) and (sma20_one_day > sma65_one_day) then score = 1; //U2 if (sma20_one_day > sma130_one_day) and (sma130_one_day > sma65_one_day) then score = 2; //U3 if (sma20_one_day > sma65_one_day) and (sma65_one_day > sma130_one_day) then score = 3; //D1 if (sma65_one_day > sma20_one_day) and (sma20_one_day > sma130_one_day) then score = 1; // D2 if (sma65_one_day > sma130_one_day) and (sma130_one_day > sma20_one_day) then score = 2; //pj[i] = score; result.SetValue(i, score); }
 QuantShare 2012-01-18 06:25:30   0 Best Answer Hi John, - The first problem is that you are combining CSharp and JScript codes. To initialize a variable in JScript: var score : int; In CSharp: int score = 0; - Some semi-colons are missing (After "CompileFormula") - Some errors when using the if condition "and" should be replaced by "&&" "then" should be removed If there is only one line of code after "if" then you can use: if(a == 5) b = 10; Otherwise you have to use parentheses: if(a==5) { b = 10; c = 20; } - Some other minor errors Here is the correct code: int score; double sma20_one_day; double sma65_one_day; double sma130_one_day; VectorD sma20 = cFunctions.CompileFormula("a = SMA(20);").GetVectorDouble("a"); VectorD sma65 = cFunctions.CompileFormula("b = SMA(65);").GetVectorDouble("b"); VectorD sma130 = cFunctions.CompileFormula("c = SMA(130);").GetVectorDouble("c"); VectorD close = cFunctions.Close; for(int i = 130;i < close.Length;i++) { sma20_one_day = sma20.GetValue(i); sma65_one_day = sma65.GetValue(i); sma130_one_day = sma130.GetValue(i); //assume D3 score = 3; //U1 if (sma130_one_day > sma20_one_day && sma20_one_day > sma65_one_day) score = 1; //U2 if (sma20_one_day > sma130_one_day && sma130_one_day > sma65_one_day) score = 2; //U3 if (sma20_one_day > sma65_one_day && sma65_one_day > sma130_one_day) score = 3; //D1 if (sma65_one_day > sma20_one_day && sma20_one_day > sma130_one_day) score = 1; // D2 if (sma65_one_day > sma130_one_day && sma130_one_day > sma20_one_day) score = 2; //pj[i] = score; result.SetValue(i, score); }
 John Faig 2012-01-18 23:21:32   0 Thanks for the feedback. It looks like there may be something wrong with the VECTORD commands. The sma20 function looks OK because the keywords have different colors. Everything from the sma65 statement and below is colored red. Any further suggestions are welcomed :-)
 QuantShare 2012-01-19 05:24:14   0 No problems here. Please double check the code and send a screenshot to support@quantshare.com.
No more messages
 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" Subscribe to this thread

 Support Contact Us Trading Forum How-to Lessons Manual Company About Us Privacy Terms of Use Copyright © 2017 QuantShare.com Social Media Follow us on Facebook Follow us on Twitter

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.