Now that I have turned the basic trading strategy into an easier to read indicator (Link: TALKING COW - YouTube), I now would like to turn it into a function in order to develop an automated trading strategy. (let me know if this should actually go in the previous thread - it seems like a brand new topic to me and that is why I am creating a new thread).
I understand the basic premise of creating numeric functions as I have done that in order to create the indicator. But taking all of this information that the indicator uses and turning it into a function seems a little bit more daunting.
Obviously, I have read the EasyLanguage Essentials portion on creating functions but that really did not help me so much.
Could someone help me break this down in to smaller, bite sized, bites? I am not asking anyone to do my work for me, but just help me to think about this correctly so that I can learn how to create this the best.
you could use a numeric return type for your function and return +1 for true and 0 for false.
For a true/false type you simply have to change the return type.
Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).
Another thing you can do is use multiple output functions, where you reference back values through inputs. Take a look at the pivot function for an example.
Here is the definition from a Tradestation function:
A multiple-output function has two types of parameters or "inputs" - input parameters
and input/output parameters. The values of the input parameters are passed into the
multiple-output function, but not modified by the function. The values of the input/
output parameters are passed into the multiple-output function, modified by it, and
the modified values are then inherited by - or output to - the calling routine.
The input/output parameters are often used for output purposes only, i.e., the
incoming values are ignored. The outputs are in addition to the function return. In
multiple-output functions, the function return is generally used to return an error
code, though sometimes the return may simply be a dummy value.
The input/output parameters are declared with a "ref" suffix (such as "numericref") in
the multiple-output function's declaration statements. For further clarity, the names
of the input/output parameters are generally prefixed with an "o" in the function as
well as in all the routines that call the function.
The following user says Thank You to ABCTG for this post:
Thank you. I have chosen to go with a TrueFalse function.
Here is the work that I have done so far with this now. It is loosely based on the indicator that was created in the other post referenced above.
I have gotten the function to compile so at least I have done something correct. I will post the code and then explain a bit of what I am trying to do.
My goal in writing this the way that I am is to make various elements optimizable.
Obviously, the ultimate strategy will say, "When each of these conditions are met, then buy..." and the conditions are probably self-explanatory in the code.
But the interesting thing in this code is the "SMA". That is a Simple Moving Average and I want to be able to test if using the SMA in this strategy actually makes a difference. Once I know if the SMA actually makes a difference then I can either just throw that condition away, or I can begin the process of determining if there is a better sma than another one. (hopefully, without over-optimizing).
The issue that I am now running into is that it seems that this function will work fine if the SMA is "true". But how can I still use this same function if the SMA was false? Or do I need to create an entirely new function for that? But it seems as though that would unnecasarily start eating up resources.
I forgot to mention that I want the reset element that was talked about in post #15 of here.
In that case it was for an indicator and making it to not plot the paintbar until it has "reset".
I would imagine that the code is a bit different in a function because I am not actually plotting anything - but the function would cease to be true if it has not reset it self. I have thought about a couple of ways to make that happen in the function, but it would never compile.
it should be possible to handle both SMA = true and SMA = false within this function. What happens in the code when SMA is true, as I can't see that from the piece you posted? What should happen if SMA is false?
Post the full function code if you can and your approach to the reset element, too. I will gladly take a look at it and see what needs to be changed.
The funny part, is that this was the entire code. lol. I am really working hard to get this figured out.
Today, when I should have been working on other things, my mind was on this thinking of how it possibly should be written. Here is what I have now. I will post the code and then comment.
As you can probably quickly figure out, this is not compiling now....but I have no idea why. The error shows that it has to do with the "=". This is where I start getting confused. Obviously there is nothing wrong an "=" in general because I have other functions that use it in order to define what the function is supposed to do.
Here is a bit more of my train of thought and that might help to explain why I am trying to do this in the way that I am.
All of this is geared toward automation and i think that I should be able to write something like:
That should, in my understanding, allow me to test the results using the SMA as part of the criteria for my buy signals.
Otherwise, I can, through the inputs, say that SMA = False and therefore:
This should allow me to test what the results are without the SMA and can then determine if one is more profitable than the other or if it simply does not matter (which I would then remove the SMA from the strategy so as to lower processing requirements)
Of course, it is quite possible that my mental logic is wrong and therefore my coding logic is equally, if not more, wrong.
Does this help to clarify what I am trying to do?
After we are through tackling this part, then I will start back with the "reset" so as to not overload my brain with too much information at one time...(I like small bite size pieces )
Last edited by JGSmith; September 5th, 2013 at 10:12 AM.
Reason: a bit more clarity