NexusFi: Find Your Edge


Home Menu

 





help needed in coding a variable in afl.


Discussion in Platforms and Indicators

Updated
      Top Posters
    1. looks_one milkysahai001 with 4 posts (0 thanks)
    2. looks_two maryfromcolorado with 3 posts (1 thanks)
    3. looks_3 aryan advisory with 1 posts (0 thanks)
    4. looks_4 johny with 1 posts (1 thanks)
    1. trending_up 2,632 views
    2. thumb_up 2 thanks given
    3. group 5 followers
    1. forum 7 posts
    2. attach_file 0 attachments




 
Search this Thread

help needed in coding a variable in afl.

  #1 (permalink)
milkysahai001
Agra+India
 
Posts: 42 since Sep 2016
Thanks Given: 17
Thanks Received: 3

i am trying to code a variable HaOpen (my modified open for Heikin Ashi) which depends on HaClose (modified close).

HaOpen is basically ((HaOpen[previous]) + smooth * ( HaClose – HaOpen[previous])), but the first value when the calculation starts HaOpen[previous] will be undefined or null, therefore to avoid that situation i want to define first value of HaOpen[previous] as HaClose and afterwards it will take HaOpen[previous] value by itself.

now, i tried coding it on multicharts, where the code is running flawlessly:
value1= IFF (vOpen[1] > 0, vOpen[1], vClose);
vOpen= ((value1) + smooth * ( vClose - value1));


in Amibroker i tried this:
if
(typeof (HaOpen) == "undefined")
{
HaOpen = HaClose;
}
HaOpen = Ref(HaOpen, -1) + smooth * (HaClose - Ref(HaOpen, -1));

which is giving different values of HaOpen in Ami and Multicharts on same data even when values of HaClose are the same.

i tried these 3 too:

value1 = IIf(Ref(HaOpen,-1)>0, Ref(HaOpen,-1),HaClose);
HaOpen = value1 + smooth*(HaClose-value1) ;


Value1 = IIf(IsNull(Ref(HaOpen, -1)), HaClose, Ref(HaOpen, -1));
HaOpen = Value1 + smooth * (HaClose - Value1);

HaOpen =Nz(Ref (HaOpen, -1) )+ smooth * (HaClose - Nz(Ref(HaOpen, -1)));

but all efforts are going in vain as it is asking to initialize HaOpen first, when I am initializing it to anything, it is not updating the new value of HaOpen and instead taking the value initialized throughout the chart.


I made an excel worksheet applying the excel formulae to get what i want and the results are matching completely with multicharts, but not with amibrokers leading to a lot of frustration. :|

Somebody please help. If you don't understand this please ask me. Thanks in anticipation!!


P.S: I am a newbie in afl coding and trying my best.

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
MC PL editor upgrade
MultiCharts
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Better Renko Gaps
The Elite Circle
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
What is Markets Chat (markets.chat) real-time trading ro …
77 thanks
Spoo-nalysis ES e-mini futures S&P 500
55 thanks
Just another trading journal: PA, Wyckoff & Trends
38 thanks
Bigger Wins or Fewer Losses?
24 thanks
The Program
17 thanks
  #2 (permalink)
maryfromcolorado
Denver CO USA
 
Posts: 32 since Sep 2016
Thanks Given: 0
Thanks Received: 13

Use the function Nz. Tests for null or undefined if so sets to second value.

HaOpen = Nz(HaOpen, HaClose);

Reply With Quote
  #3 (permalink)
milkysahai001
Agra+India
 
Posts: 42 since Sep 2016
Thanks Given: 17
Thanks Received: 3



maryfromcolorado View Post
Use the function Nz. Tests for null or undefined if so sets to second value.

HaOpen = Nz(HaOpen, HaClose);



maryfromcolorado,

Not working. its asking to initialize HaOpen first.

Reply With Quote
  #4 (permalink)
maryfromcolorado
Denver CO USA
 
Posts: 32 since Sep 2016
Thanks Given: 0
Thanks Received: 13

I am just looking at documentation. It should work.

https://www.amibroker.com/guide/afl/nz.html

You can use the other function then

HaOpen = IIf( IsFinite( HaOpen), HaOpen, HaClose);

Isn't there an initialization section where you could set HaOpen to 0 and then test for that ?

Reply With Quote
Thanked by:
  #5 (permalink)
milkysahai001
Agra+India
 
Posts: 42 since Sep 2016
Thanks Given: 17
Thanks Received: 3


maryfromcolorado View Post
I am just looking at documentation. It should work.

https://www.amibroker.com/guide/afl/nz.html

You can use the other function then

HaOpen = IIf( IsFinite( HaOpen), HaOpen, HaClose);

Isn't there an initialization section where you could set HaOpen to 0 and then test for that ?


maryfromcolorado,

i had previously tried :
Value1 = IIf(IsNull(Ref(HaOpen, -1)), HaClose, Ref(HaOpen, -1));
HaOpen = Value1 + smooth * (HaClose - Value1);

but again the initialization issue.

when referring to the previous value of HaOpen it is taking the value of whatever i am initializing it to.

say, if i initialize it as HaOpen = HaClose; then in the next line of HaOpen =Nz(Ref (HaOpen, -1) )+ smooth * (HaClose - Nz(Ref(HaOpen, -1))); it takes the value of HaClose everytime HaOpen is referred to and likewise with zero.

Reply With Quote
  #6 (permalink)
maryfromcolorado
Denver CO USA
 
Posts: 32 since Sep 2016
Thanks Given: 0
Thanks Received: 13

Sorry I don't know enough about AmiBroker to help further without a lot of investigation.

Reply With Quote
  #7 (permalink)
milkysahai001
Agra+India
 
Posts: 42 since Sep 2016
Thanks Given: 17
Thanks Received: 3


maryfromcolorado View Post
Sorry I don't know enough about AmiBroker to help further without a lot of investigation.


maryfromcolorado,

its okay. thanks for your inputs.

Reply With Quote
  #8 (permalink)
johny
Melbourne, Australia
 
Posts: 20 since Jun 2010
Thanks Given: 0
Thanks Received: 6

You can't use a variable before it is initialized because the values in it would be junk.

The only way to do what you want is a loop.

HaOpen[0] = HaClose[0];
for(i = 1; i < BarCount; i++)
{
HaOpen[i] = HaOpen[i -1] + smooth * (HaClose[i] - HaOpen[i -1]);
}

Reply With Quote
Thanked by:




Last Updated on May 10, 2017


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts