![]() |
|
|||||||
| Automated Trading Support for automated trading systems using NinjaScript. Support for our ATI (Automated Trading Interface) used to link an external application such as TradeStation and eSignal to NinjaTrader. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Sep 2008
Posts: 483
Thanks: 0
Thanked 2 times in 2 posts
|
Hi all,
I am looking for help with the following. I have an oscillator that has a zero line and can go from 10.000000 to -10.000000. What I want to do is calculate the amount of the move between bars, or rather how much did the oscillator oscillate. Say for example I was using Oscillator and I wanted to make a decision based on how much it moved between the value as of the current bar for the osc, to the value of the osc 3 bars ago? I am basically doing something like: (this works fine provided my osc values are both above zero) if (Oscillator(PoFast, PoSlow, PoSmooth)[0] > Oscillator(PoFast, PoSlow, PoSmooth)[3] && Oscillator(PoFast, PoSlow, PoSmooth)[0] - Oscillator(PoFast, PoSlow, PoSmooth)[3] > .1 ...then do something... Now I am pretty sure that this is Freshman math, but I was busy doing more important things, lol. Can someone give me the structure for finding the difference between the values of the osc for given bars? Will pay in beer. |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,555
Thanks: 261
Thanked 1,013 times in 994 posts
|
r2kTrader, not sure I follow - if you have the Oscillator as a dataseries you can easily calculate the difference from current bar to x bars back. Or are you looking for some kind of 'pivot detection' algorithm placed on the oscillator? Then I would check into the code of the Swing indicator that would do this on price.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Sep 2008
Posts: 483
Thanks: 0
Thanked 2 times in 2 posts
|
I thought this through using my scientific calculator, lol, and this is what I came up with. My only kickback was when dealing with negative numbers. I know subtraction is obviously the way to find the difference, but it was the result that was skewing my results.
So I decided that converting the negative number to an absolute would do the trick (I think, looking for some eyes/help). My logic is as follows, I do the opposite for short side: 1. is osc value from current bar greater than osc value from 3 bars ago, if true, then #2 2. subtract value of osc from 3 bars ago from osc value value of current bar. (I added the Math.abs to convert the result to a whole number so that I can simply base a decision based on the amount of the difference. I already know if its higher, so the result should be the difference) 3. if variance is great than x, then do something. if (Oscillator(PoFast, PoSlow, PoSmooth)[0] > Oscillator(PoFast, PoSlow, PoSmooth)[3] && Math.Abs(Oscillator(PoFast, PoSlow, PoSmooth)[0] - Oscillator(PoFast, PoSlow, PoSmooth)[3]) > 0 |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,555
Thanks: 261
Thanked 1,013 times in 994 posts
|
Just an idea, maybe simpler: try using the absolute value of the x bar momentum of your oscillator for your decisions.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#5 | |
|
Senior Member
Join Date: Sep 2008
Posts: 483
Thanks: 0
Thanked 2 times in 2 posts
|
Quote:
Thanks for the reply. Couldn't that skew my results if say my values were as follows? 1 bar ago (1BA)= -.2 Current bar (CB) = .3 Wouldn't I get a value of 1 if I did something like: Abs(CB) - Abs(1BA) = .3 - .2 = 1 Whereas: Abs(CB- 1BA) = .3 - -.2 = 5 I could REALLY use a definitive answer on this and I am increasing the answer bounty to 2 beers, microbrewed! I want to know the different between the moves of old bars to new bars on my osc and then make a decision based on the deviation or rather the amount of the move. |
|
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,555
Thanks: 261
Thanked 1,013 times in 994 posts
|
I guess you would need to chart the alternatives and then check the needed requirements visually, AbsValue would just affect the sign, not the rounding.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#7 | |
|
Senior Member
Join Date: Sep 2008
Posts: 483
Thanks: 0
Thanked 2 times in 2 posts
|
Quote:
So based on my prior post, is my code/logic correct? Also, sidenote, this is an NT related question. As it stands, I am running this calc on every bar update, but I only want to run this calc on bar close. Is there a code snippet to do this? Bear in mind, I want my strategy NOT to calcOnBarClose, but I don't want to reiterate this snippet every update. Would I setup a bool and then nest the rest of the code inside that test? Thanks |
|
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,555
Thanks: 261
Thanked 1,013 times in 994 posts
|
r2kTrader, yes I believe this would do it for you - you can use FirstTickOfBar to do this only on the close then, just keep in mind to reference one bar back further to make up for calling it on the open of the next bar...
Code:
if (FirstTickOfBar)
{
do your on bar close calculations
}
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#9 | |
|
Senior Member
Join Date: Oct 2008
Location: Dallas, TX
Posts: 682
Thanks: 0
Thanked 2 times in 2 posts
|
Quote:
dosomething; Would allow rest of strategy to update each tick, and 'dosomething' only on bar close. Mike |
|
|
|
|
|
|
#10 |
|
Senior Member
Join Date: Oct 2008
Location: Dallas, TX
Posts: 682
Thanks: 0
Thanked 2 times in 2 posts
|
doh! Bertrand is speedy fast
![]() Mike |
|
|
|
|
|
#11 |
|
Senior Member
Join Date: Sep 2008
Posts: 483
Thanks: 0
Thanked 2 times in 2 posts
|
Pete's Wicked Ale for the both of you!
Thank you very much guys. So all things being equal Betrand, my logic of using Abs as per my description is correct? I will be able to calculate the difference between the value of osc from one bar to the other bar and by apply Abs on the result, I will avoid skewing the value of the difference and only convert it to a whole number if it is a negative value? |
|
|
|
|
|
#12 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
r2kTrader,
I am not sure where you got the idea that Math.Abs converts to whole numbers. Math.Abs just does absolute values. It doesn't change it to a whole number in the process. Math.Abs(-0.2) = 0.2 for example.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#13 | |
|
Senior Member
Join Date: Sep 2008
Posts: 483
Thanks: 0
Thanked 2 times in 2 posts
|
Quote:
Let me rephrase. I meant positive, not whole. :-( |
|
|
|
|
|
|
#14 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
Then that is correct. You will get appropriate positive values for comparison.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#15 |
|
Senior Member
Join Date: Sep 2008
Posts: 483
Thanks: 0
Thanked 2 times in 2 posts
|
Josh,
Will this work? private double[] values = Oscillator(PoFast, PoSlow, PoSmooth); private double currentBar = values[0]; private double oneBarAgo = values[3]; if (currentBar > oneBarAgo && Math.Abs(currentBar - oneBarAgo) > .25) { // do something } |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| 3/10-Oscillator | gerryk | Indicator Development | 10 | 06-20-2012 11:35 AM |
| Elliptic Oscillator. | Drakmyre | Indicator Development | 12 | 01-06-2009 10:21 AM |
| Forcast oscillator | pgabriel | Indicator Development | 1 | 12-21-2008 02:37 PM |
| Request: Bill Williams Awesome Oscillator & Accelerator Oscillator | jeremymgp | Indicator Development | 26 | 11-04-2008 08:41 PM |
| Volume Oscillator | ohowie | Historical NinjaTrader 6.5 Beta Threads | 5 | 03-07-2008 12:15 AM |