Creating TrueFalse Function - futures io
futures io futures trading



Creating TrueFalse Function


Discussion in EasyLanguage Programming

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




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Creating TrueFalse Function

(login for full post details)
  #1 (permalink)
Lübeck, Germany
 
Experience: Intermediate
Platform: NinjaTrader, MT4
Broker: FXCM, Interactive Brokers, Oanda
Trading: Forex
 
JGSmith's Avatar
 
Posts: 151 since Aug 2013
Thanks: 61 given, 55 received

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

 
Best Threads (Most Thanked)
in the last 7 days on futures io
Selling Options on Futures?
109 thanks
Battlestations: Show us your trading desks!
108 thanks
Rank your Futures vs Stocks trading priority
55 thanks
Want your NinjaTrader indicator created, free?
27 thanks
Whats this confusion with margins?
21 thanks
 
(login for full post details)
  #3 (permalink)
 
 
Posts: 2,230 since Apr 2013
Thanks: 409 given, 1,471 received


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
The following user says Thank You to ABCTG for this post:
 
(login for full post details)
  #4 (permalink)
Lübeck, Germany
 
Experience: Intermediate
Platform: NinjaTrader, MT4
Broker: FXCM, Interactive Brokers, Oanda
Trading: Forex
 
JGSmith's Avatar
 
Posts: 151 since Aug 2013
Thanks: 61 given, 55 received


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
 
(login for full post details)
  #5 (permalink)
Lübeck, Germany
 
Experience: Intermediate
Platform: NinjaTrader, MT4
Broker: FXCM, Interactive Brokers, Oanda
Trading: Forex
 
JGSmith's Avatar
 
Posts: 151 since Aug 2013
Thanks: 61 given, 55 received

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
 
(login for full post details)
  #6 (permalink)
 
 
Posts: 2,230 since Apr 2013
Thanks: 409 given, 1,471 received

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
 
(login for full post details)
  #7 (permalink)
Lübeck, Germany
 
Experience: Intermediate
Platform: NinjaTrader, MT4
Broker: FXCM, Interactive Brokers, Oanda
Trading: Forex
 
JGSmith's Avatar
 
Posts: 151 since Aug 2013
Thanks: 61 given, 55 received


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


futures io Trading Community Platforms and Indicators EasyLanguage Programming > Creating TrueFalse Function


Last Updated on September 5, 2013


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
 

Importance of Finding Your Own Way w/Adam Grimes

Elite only
 

Journal Challenge w/Jigsaw

April
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts