Current location | Thread information | |
![]() ![]() ![]() ![]() ![]() ![]() |
Last Activity 10/5/2024 12:51 AM 7 replies, 2555 viewings |
|
|
Printer friendly version |
^ Top | |||
Daniel Wilson![]() Member ![]() Posts: 45 Joined: 3/7/2006 Location: Moses Lake, WA ![]() |
Does anyone have an OmniLanguage code for when an indicator is crossing below or crossing above a value? All I can find now is > or < but not the specific act of "crossing" above or below the value. -Daniel Wilson | ||
^ Top | |||
Jim Dean![]() Sage ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3433 Joined: 3/13/2006 Location: L'ville, GA ![]() |
Hi, Daniel You need to do two tests ... the condition for the prior bar vs the condition for the current bar. For example: if C[1] < SMA(20)[1] and C > SMA(20) then ... code for long crossover actions elseif C[1] > SMA(20)[1] and C < SMA(20) then ... code for short crossover actions end if [Edited by Jim Dean on 12/26/2018 9:30 AM] | ||
^ Top | |||
Daniel Wilson![]() Member ![]() Posts: 45 Joined: 3/7/2006 Location: Moses Lake, WA ![]() |
Thank you Jim! | ||
^ Top | |||
beech pilot![]() Member ![]() Posts: 36 Joined: 11/1/2018 Location: Visalia ![]() |
hello say i wanted rsi(14) crossing above 0 . how would i write that in a formula for a filter | ||
^ Top | |||
Jim Dean![]() Sage ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3433 Joined: 3/13/2006 Location: L'ville, GA ![]() |
Use the same formula I gave initially, but substitute RSI(14) for "C", and 0 for "SMA(20)" and for "SMA(20)[1]" (since the value 0 is a constant that doesn't use the [n] syntax to reference it's value from n bars ago) ... I suggest you study the formula and think about how it works, so that you can solve similar problems, or simple variations of them on your own in the future ... reason: I think it's *very* important for traders to understand the "whys" and "hows" of their methodology, whenever possible. [Edited by Jim Dean on 12/30/2018 10:21 AM] | ||
^ Top | |||
beech pilot![]() Member ![]() Posts: 36 Joined: 11/1/2018 Location: Visalia ![]() |
ok what about if it is = 0 , sorry i am just not that great with omni language, i am just trying to get a column in the focus list as to when the BasingInd (250,2,14) is equal to the zero line or crossing the zero line ![]() | ||
^ Top | |||
Manfred![]() Veteran ![]() ![]() Posts: 210 Joined: 4/2/2006 Location: South Africa ![]() |
Hi, JD explained the concept just fine but being new am guessing you're looking for someone to help connect a few more of the dots :-) I dont have BasingInd() on my system so cannot test with that specifically. Also your initial example of RSI contradicts your later question of 0 crossing. RSI in its normal format ranges between 0 and 100 so you wont get zero crossings with that. Something like MACD indicator however, does have both positive and negative values so I'll use this for my worked example. Thus to show a zero crossing with MACD on your focus list do something like this: Right mouse click in focus list -> Add Omniscript column Give it a name - e.g. MACDzerocrossing or whatever you wish to call it In the Formula text box enter the Boolean condition you wish to test validity for. e.g. for a zero crossing from the downside to the upside and vice versa you'd need something like. ( MACD(12,26) > 0 AND MACD(12,26)[1] >= 0 ) OR ( MACD(12,26) < 0 AND MACD(12,26)[1] <= 0 ) In your case you probably just need to replace all instances of my MACD(12,26) above with your BasingInd(250,2,14) and in theory it should work. Anyway getting back to the MACD example, if you look at the attached png, you will see a 0 in the Omniscript column in the focuslist. This means the condition is true for the current bar. If it was false then the column would show -1. You can corroborate this by adding the same indicator to a chart and reading the value as shown on the example png. Assuming you use EOD daily data, I'll use the example of "today" and "yesterday" [1] below. For RT data substitute these terms with "current bar" and "previous bar", respectively. In English what this is doing is checking whether today's value of the indicator MACD(12,26) is greater than > 0 AND also whether yesterday's value for the indicator was greater than or equal to >=0 This fulfils the condition when the indicator crosses from below to *above* the 0 line. However, since the indicator could also conceivably cross from above to *below* the zero line you'll need to check for this too. This is the second part of the condition after the OR statement. You put OR there because you want either of the conditions to be valid and dont care which one - its a zero crossing either way. The rest of the condition is simply the reverse logic to the previous. i.e. you swap around the < and <= operators for the alternative crossover condition. You then encapsulate/group each check condition in additional parentheses ( ) so that each side of the OR operand is evaluated in full before the other side of the OR is tested for. In pseudocode it implies this: (Condition 1 part a AND Condition 1 part b) OR (Condition 2 part a AND Condition 2 part b) Stated another way: ( Indicator value today >0 AND Indicator value yesterday[1] >=0 ) OR ( Indicator value today <0 AND Indicator value yesterday[1] <=0 ) You will get invalid results on a zero crossing if you don't use this approach to group the logic statements. Hope this helps Cheers [Edited by Manfred on 1/12/2019 12:53 PM] ![]() | ||
^ Top | |||
Manfred![]() Veteran ![]() ![]() Posts: 210 Joined: 4/2/2006 Location: South Africa ![]() |
If it crucial to know when the condition is equal in addition to the crossover conditions simply add an additional OR statement to the condition formula. In my worked example that would be. ( MACD(12,26) > 0 AND MACD(12,26)[1] >= 0 ) OR ( MACD(12,26) < 0 AND MACD(12,26)[1] <= 0 ) OR MACD(12,26) = 0 |
|
|
Legend | Action | Notification | |||
Administrator
Forum Moderator |
Registered User
Unregistered User |
![]() |
Toggle e-mail notification |