How to create a function returning a Bars object?
Author: Pavel12
Creation Date: 1/30/2012 2:34 PM
profile picture

Pavel12

#1
Hi, everyone.

I am going to create the Heiken Ashi indicator. I found one example on this forum, but in this example author
uses 4 functoins - one for each parameter. For one, function for HHClose calculation, function for HHOpen calculation etc.
I want to use one one function that should return Bars object, and i want to use this new Bars for other functions. For
instanse, calculate the ATR from this new Bars. Could you please help me with it. Bellow you can find an schematic example
of my code and information with error.

function Ashi (Bars bar)
{
Bars b_Bar;
b_Bar = bar;
b_Bar.Hight = bar.Hight + ... // Here i have an error, that i can't change Hight attribute. How i should modify my code.


}



Best regard,
Pavel
profile picture

Eugene

#2
A function returning a Bars object is no different from a method that returns a string, a boolean, instance of a class or anything for that matter. See any C# 101 book or online tutorial, as this is a prerequisite for programming in WealthScript.

P.S. Please take no more duplicate trials. Thanks for your understanding.
profile picture

Pavel12

#3
Thanks for the answer.
I read a book and i know how to return a Bars object. But i don't understand why the bellow code has an error and how i can fix it. Could you please help me?

---
Bars b_Ashi = new Bars (Bars);
b_Ashi.Hight[0] = 10;


I don't have an errors during the compilation, but i have an error during the execution: Index out of range. The follow construction doesn't help also:

b_Ashi.Hight = new DataSeries(Bars.Hight, "Ashi"); I have an error during the compilation.


profile picture

Eugene

#4
Your code contax obvious syntax errors i.e. Hight to say the least. Since it has a snowball chance in hell of compiling successfully, we need to look at the whole code.
profile picture

Pavel12

#5
I just want to understand how it works and don't write a program, just an example.


1) I use standard AA data from WealthLab ADow 30;
2) The code is

CODE:
Please log in to see this code.

I have the follow PrintDebug message:
Bars(AA,Daily,0,10604)
Bars(AA,Daily,0,0)

As i can see that b_Ashi doesn't contain any information from Bars and i don't know how to copy it.
profile picture

Eugene

#6
Of course it doesn't contain any information: you just instantiated a new, empty Bars object.

Check out the QuickRef example for Bars.SaveToFile. There's a self-contained code that builds, saves and charts a Heiken-Ashi Bars object.

To wrap it in a method returning a Bars object, all it takes a little bit of C# 101 skill.
profile picture

Pavel12

#7
Thanks a lot.


This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).