Current location  Thread information  
OmniTrader Professional Forum
OmniLanguage Discussion Keeping a total at a point in time 
Last Activity 11/19/2018 6:30 PM 3 replies, 821 viewings 


Printer friendly version 
^ Top  
John Crowley Member Posts: 6 Joined: 6/17/2016 User Profile  I'm trying to create an indicator that gives me a total of various conditions A simple example is if the low of the bar is greater than a moving average, assign it a value of 1 and if the MACD is greater than 0 also assign it a value of 1 so when the two conditions are met, I should get a value of 2 if 1 condition is met, 1 and if none, then a 1 for each value if I enter the parameters in the colour chart, I can see clearly where both are met (I love the way you can quickly test conditons) yet trying to put this into language is where its falling down the script is very clear, im either 1 or 1. I'm not trying to add onto or subtract a running total, its a total at any point in time when i write this for just one indicator, everything is fine. as soon as I add a second if statement, its not adding as i would expect. I shouldn't have a value of zero. could somebody help in my logic? [Edited by John Crowley on 9/13/2017 6:29 AM] Attached file : colour script.JPG (32KB  55 downloads) Attached file : T script.JPG (28KB  51 downloads) Attached file : T indicator.JPG (82KB  57 downloads)  
^ Top  
Jim Dean Sage Posts: 3147 Joined: 3/13/2006 Location: L'ville, GA User Profile  I've written a LOT about "boolean math" in the Tradetight.org forum ... go there and do a Search for that term. But here's a quick answer for you. Here's a direct link to make it easy: click here You asked for a way to plot or utilize this rule: If the low of the bar is greater than a moving average, assign it a value of 1 and if the MACD is greater than 0 also assign it a value of 1 so when the two conditions are met, I should get a value of 2 Let's say the MA is EMA(14), and the MACD is MACD(12,26). The first query asks "is the Low greater than the MA" ... the formula for this: L > EMA(14) ... will return true (a value of 1) or false (a value of 0) The second query asks "is the MACD greater than zero" ... formula is: MACD(12,26) > 0 ... again, will return true (a value of 1) or false (a value of 0) You can combine these in two ways ... one uses Boolean logic, and the other uses Boolean math: Boolean logic: #indicator dim rules as integer if L > EMA(14) and MACD(12,26) > 0 then rules = 2 elseif L > EMA(14) or MACD(12,26) > 0 then rules = 1 else rules = 0 end if return rules Of course you need OLang to implement this. It could be done in OScript (ie a quick indicator or color chart, etc) using the "iif(condition,true,false)" rule, but that's sort of messy so I won't go into it further. The most "elegant" way to solve this is using Boolean math. That's a term I invented (afaik) to describe booleanlogic mixed with algebraic operations. Note above that true= 1 and false= 0. This means we can "add" (or subtract or multiply or many other things) two boolean expressions. The key to doing this is simple: wrap each boolean expression in parentheses, then plug those expressions into a math formula, thus: ( L > EMA(14) ) + ( MACD(12,26) > 0 ) ... this returns a value of 0, 1 or 2 (since True = 1) If you want positive values, simply insert minus signs in the formula: ( L > EMA(14) )  ( MACD(12,26) > 0 ) You can PLOT that formula as a Quick Indicator and you will see a stairstepwave with values of 0, 1, 2 HOMEWORK: Play with this using other functions, other boolean rules, and other algebra. It's amazing what you can do if you just experiment! [Edited by Jim Dean on 9/13/2017 6:49 AM]  
^ Top  
John Crowley Member Posts: 6 Joined: 6/17/2016 User Profile  Thanks for the extremely quick reply Jim I can't express how much "experimenting" ive been doing over the last few days the immediate logic below is precisely what I was looking for in this scenario of two indicators, I will now go back and see if i can figure out the "or" statement as this has been the key and apply it to something more complex. Ultimately I want to consider 5 different elements and i will visit the tradetight site thanks again [Edited by John Crowley on 9/13/2017 7:06 AM]  
^ Top  
Jim Dean Sage Posts: 3147 Joined: 3/13/2006 Location: L'ville, GA User Profile  I feel your pain ;~) ... but otoh, it's sort of enjoyable to ferret out solutions on your own, if your curiosity makes you a glutton for punishment, that is. The TT forum is all about finding answers and methods to things that aren't "canned". In my opinion, traders should fully understand every component of a strategy they are using to grow their account. For me, this means writing everything from scratch, using OLang (which is surprisingly powerful if you handle it wisely). But a huge part of this is just *looking* at how the "primitive" components of the strategy plot out on the chart ... and wiggling the formulae (or its exposed parameters) around to see how modifying them might improve things. You *don't* have to be a programmer to do this! I just posted an example of this on another OT thread that was asking about the SEB function ... and reposted that in the TT forum. Click here if you're interested. [Edited by Jim Dean on 9/13/2017 7:20 AM] 


Legend  Action  Notification  
Administrator
Forum Moderator 
Registered User
Unregistered User 
EMail this thread to a friend 
Toggle email notification 