Rank: Advanced Member
Groups: Moderators, Registered, Registered Users, Subscribers Joined: 10/8/2010(UTC) Posts: 1,960
Thanks: 92 times Was thanked: 155 time(s) in 150 post(s)
|
Using a variable does not automatically make the code faster but used properly, it does help, a lot. I my opionion, a variable should be used: - where a value is used through out a formula, like a number of periods. The variable makes it easy to keep the code consistent and allows quick edits - for key sections of complex code. By breaking the code into sections, the logic of the formula is easier to read. for example: Code:
con1:= Stoch(16,8) - Mov(Stoch(16,8),8,S) > 0;
con2:= (RSI(7) + RSI(14) + RSI(21))/3 > 70;
con3:= MACD() - Mov(MACD(),9,E) > 0;
con4:= Cross( C, Mov(MP(), 40, S) );
con5:= Cross( Mov(typical(), 20, E), C);
if(con1 AND con2 AND con4, 1, if( con3 and con5, -1, prev))
That formula is contrived and not meant as a valid signal but it does show how messy code can get. The last line, without variables could be confusing to read and sort out. - variables can be used for Security(), Fml(), and FmlVar() function calls. These slow down the calculation of formulas. I have also seen odd results when they are used in the middle of a formula. However, if they are called once at the top of a formula and the the variable used as needed, the calcualtion runs much smoother
|