please help...
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
most recent cross and count
Collapse
X
-
most recent cross and count
Need help to a newbie. started coding an indicator to use in MA having 5,15,30 min columns. so far working fine with buy n sell signals. now on a buy or sell signal , need go back and find MRO on recent 5ema to 10sma cross below and count how many times a cci/stoch crossed above 20 from that point. need a little sample code .,
please help...Tags: None
-
Adam,
On a BarUpdate function I keep checking for some buy, sell signals.,(already coded and working)
here is what i need: Once it is met then I want to go back in time from that bar and find when this 5 and 10 ma crossed below/above. And once I find it, I want to know if the CCi made n number of crosses to change the status in MA with buy or sell.
here is the sample:
OnBarUpate()
{
If(RSI>60 && upCycleVariable==true){
//here is what I need
before return 1 make sure cci crossed 20, 3 times from the time 5,10 crossed below
return 1; // flag to update column to buy
}
else
return -1; //flag for sell
using this as indicator in MA on 5,15,30 min columns.
Hope I'm clear.
thanks.
Comment
-
kinshin,
I believe something like this would work for tracking CCI crossings since the last MA crossing.
This would go at the beginning of OnBarUpdate(), outside your if statement for order entry.
Code://If the MA's cross below reset the CCI crossing counter. if(CrossBelow(SMA(5),SMA(10))) { CCICrossings = 0; MACrossFlag = true; } else if(CrossAbove(SMA(5),SMA(10))) //Check if there is a cross above { MACrossFlag = false; } //Count the number of CCI crossings since the last MA cross below if(CrossBelow(CCI(Period),20)) { CCICrossings++; }
Code:// If there were 3 CCI crossings since the last MA cross below if(CCICrossings>=3 && MACrossFlag) { // do something }
Last edited by NinjaTrader_AdamP; 05-29-2012, 08:09 AM.Adam P.NinjaTrader Customer Service
Comment
-
Adam,
created the custom indicator for this same purpose and plotted on the charts and working gr8. But the indicator using in the MA has the same calculations., (infact the same method) but the results are way off. I even created public methods to access the the same variables from the one that was plotted on the chart. it returns half of the number of crosses, but never same. yes I am calling update() too.
Can you suggest any Ideas to fix this ??
thanks.
Comment
-
Adam,
first I need to get some basics.
1. When we reload/apply an indicator to the MA window, How do that indicator read the values ?.
meaning is it like "file reading" program, where it opens the file and start parsing the chunks ?
So to visually understand this: If I have a 15 min chart with 3 days of data in it, every time I hit reload script in MA, does it start from the left most candle from the 3rd day and ends up at right most candle of present day ?
2. What happens when we call update() function on a plotted indicator ? is it equivalent to a reload ?
thnx.
Comment
-
kinshin,
1. When we reload/apply an indicator to the MA window, How do that indicator read the values ?.
meaning is it like "file reading" program, where it opens the file and start parsing the chunks ?
So to visually understand this: If I have a 15 min chart with 3 days of data in it, every time I hit reload script in MA, does it start from the left most candle from the 3rd day and ends up at right most candle of present day ?
If you have a 15 min chart with 3 days of data, your understanding is correct here. There is a slight nuance though with the CalculateOnBarClose setting. If this is true, the calculation ends with the most current CLOSED bar, whereas with this setting false it would end with the most current open bar. Additionally, as the price updates for this open bar it would update the most recent calculation at myDataSeries[0], basically calling OnBarUpdate() tick-by-tick.
2. What happens when we call update() function on a plotted indicator ? is it equivalent to a reload ?
Please let me know if I may assist further.Adam P.NinjaTrader Customer Service
Comment
-
thanks Adam,
glad I asked about the basics. now I see what's going on. In the chart I have 60 days of "data to load" set. And my indicator in MA looking at 256 (by default) nothing in Initialize() set. But columns (5M,15M) of MA , the "#number of bars to look back" set to default 50. That's the reason for the different crossOver counts.
I changed it to 256 in MA columns.. Now everything is in sync., and working fine.
But here are the new questions:
1. Are MA and chart are independent of each other ? If yes, then what it means "use update() on unplotted indicator calls";
2. The setting "look back period" hardCoded in indicator gets overridden by what the column setting has in MA ? meaning which one takes the precedence ?
3. If I set lookback period infinte, what does it mean ? and how do I set the same setting in MA column ?
-kin
Comment
-
Kinshin,
1. Are MA and chart are independent of each other ? If yes, then what it means "use update() on unplotted indicator calls";
2. The setting "look back period" hardCoded in indicator gets overridden by what the column setting has in MA ? meaning which one takes the precedence ?
3. If I set lookback period infinte, what does it mean ? and how do I set the same setting in MA column ?Adam P.NinjaTrader Customer Service
Comment
-
with my ignorance I read "not plots" as unplotted on charts.
here is the thread replied by you:
So when I call update(), does it wake up the indicator every time to go thru the whole dataSeries objects with current bar ? Or the first call makes it active instance for that process ?
Comment
-
Hi kinshin9,
OnBarUpdate() isn't something you call. It's an event that's raised when a new bar is received. Indicators then process all logic within their OnBarUpdate() section during this event
Update() calls have a very specific use, related to exposing non-plot values from another indicator. This is shown here:
How are you using Update() within your own script?Ryan M.NinjaTrader Customer Service
Comment
-
Ryan,
it's a general question about the basics, as of now I'm not using update(). What I meant about "calling update()" is , I saw this "update()" was used right before accessing a public variable via public method
in an outside indicator. so in general terms I'm referencing this event as call() within that public method.
Hope I didn;t confuse.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by zstheorist, Today, 07:52 PM
|
0 responses
7 views
0 likes
|
Last Post
by zstheorist
Today, 07:52 PM
|
||
Started by pmachiraju, 11-01-2023, 04:46 AM
|
8 responses
150 views
0 likes
|
Last Post
by rehmans
Today, 06:44 PM
|
||
Started by mattbsea, Today, 05:44 PM
|
0 responses
6 views
0 likes
|
Last Post
by mattbsea
Today, 05:44 PM
|
||
Started by RideMe, 04-07-2024, 04:54 PM
|
6 responses
33 views
0 likes
|
Last Post
by RideMe
Today, 05:31 PM
|
||
Started by tkaboris, Today, 05:13 PM
|
0 responses
6 views
0 likes
|
Last Post
by tkaboris
Today, 05:13 PM
|
Comment