NexusFi: Find Your Edge


Home Menu

 





Creating TrueFalse Function


Discussion in EasyLanguage Programming

Updated
    1. trending_up 4,846 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 6 posts
    2. attach_file 1 attachments




 
Search this Thread

Creating TrueFalse Function

  #1 (permalink)
 
JGSmith's Avatar
 JGSmith 
Lübeck, Germany
 
Experience: Intermediate
Platform: NinjaTrader, MT4
Broker: FXCM, Interactive Brokers, Oanda
Trading: Forex
Posts: 151 since Aug 2013
Thanks Given: 61
Thanks Received: 55

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.

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trade idea based off three indicators.
Traders Hideout
What broker to use for trading palladium futures
Commodities
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
MC PL editor upgrade
MultiCharts
ZombieSqueeze
Platforms and Indicators
 
  #3 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629


JGSmith,

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.



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.


Regards,
ABCTG

Follow me on Twitter Reply With Quote
Thanked by:
  #4 (permalink)
 
JGSmith's Avatar
 JGSmith 
Lübeck, Germany
 
Experience: Intermediate
Platform: NinjaTrader, MT4
Broker: FXCM, Interactive Brokers, Oanda
Trading: Forex
Posts: 151 since Aug 2013
Thanks Given: 61
Thanks Received: 55


ABCTG View Post
For a true/false type you simply have to change the return type.

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.

 
Code
Inputs:
	SMA( TrueFalse ) ,
	maLength ( Numeric ) ,
	kcLength ( Numeric ) ,
	kcATR (numeric ) ,
	AroonUpLength( numeric ) ;
	

condition1 =  SMA = True ;
condition3 = __AroonUp( AroonUpLength ) = 100 ;
condition4 = Close > Open ;
condition5 = Close > KeltnerChannel( close , kcLength , kcATR ) ;
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.

Hopefully my questions makes sense.

Started this thread Reply With Quote
  #5 (permalink)
 
JGSmith's Avatar
 JGSmith 
Lübeck, Germany
 
Experience: Intermediate
Platform: NinjaTrader, MT4
Broker: FXCM, Interactive Brokers, Oanda
Trading: Forex
Posts: 151 since Aug 2013
Thanks Given: 61
Thanks Received: 55

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.

Started this thread Reply With Quote
  #6 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

JGSmith,

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.

Regards,
ABCTG



JGSmith View 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.

 
Code
Inputs:
	SMA( TrueFalse ) ,
	maLength ( Numeric ) ,
	kcLength ( Numeric ) ,
	kcATR (numeric ) ,
	AroonUpLength( numeric ) ;
	

condition1 =  SMA = True ;
condition3 = __AroonUp( AroonUpLength ) = 100 ;
condition4 = Close > Open ;
condition5 = Close > KeltnerChannel( close , kcLength , kcATR ) ;
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.

Hopefully my questions makes sense.


Follow me on Twitter Reply With Quote
  #7 (permalink)
 
JGSmith's Avatar
 JGSmith 
Lübeck, Germany
 
Experience: Intermediate
Platform: NinjaTrader, MT4
Broker: FXCM, Interactive Brokers, Oanda
Trading: Forex
Posts: 151 since Aug 2013
Thanks Given: 61
Thanks Received: 55


ABCTG View Post
JGSmith,

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.

 
Code
Inputs:
	SMA( TrueFalse ) , 
	maLength ( Numeric ) ,
	kcLength ( Numeric ) ,
	kcATR (numeric ) ,
	AroonUpLength( numeric ) ;
	
Condition1 = SMA = True ;
Condition2 = SMA = False ;

__PracticeFunctionForStrategy( Condition1 , maLength , kcLength , kcATR , AroonUpLength ) = 
	__AroonUp( AroonUpLength ) = 100 and
	Close > Average( Close , maLength ) and
	Close > Open and
	Close > KeltnerChannel(close , kcLength , kcATR ) ;

__PracticeFunctionForStrategy( condition2 , maLength , kcLength , kcATR , AroonUpLength ) =
	__AroonUp( AroonUpLength ) = 100 and 
	Close > Open and
	Close > KeltnerChannel(close , kcLength , kcATR ) ;
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:

 
Code
If __PracticeFunctionForStrategy( Condition1 , maLength , kcLength , kcATR , AroonUpLength ) = True 
then Buy....etc.
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:

 
Code
If __PracticeFunctionForStrategy( Condition2 , maLength , kcLength , kcATR , AroonUpLength ) = True 
then Buy....etc.
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 )

Started this thread Reply With Quote




Last Updated on September 5, 2013


© 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