NexusFi: Find Your Edge


Home Menu

 





Question going by tick


Discussion in NinjaTrader

Updated
    1. trending_up 2,616 views
    2. thumb_up 0 thanks given
    3. group 1 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 jeffbg123 
Chicago
 
Experience: Advanced
Platform: Other
Posts: 35 since Feb 2010
Thanks Given: 3
Thanks Received: 1

I am new to NinjaTrader but know C# and need some advice.

I want to run a strategy that relies on the previous 2 5000 tick bars. However I don't really want to do it by bar, I want to have a moving window of the last 5000 ticks and the 5000-10000th ticks. So what I was doing is just keeping a list of my own of these ticks.

 
Code
public class scalper : Strategy
{
List<double> barFar = new List<double>();
List<double> barNear = new List<double>();


.....
protected override void Initialize()
        {
            CalculateOnBarClose = false;
            EntryHandling        = EntryHandling.UniqueEntries;
        }

protected override void OnBarUpdate()
{
double curPrice = Close[0];
            numTicks++;
            
            barNear.Add(curPrice);
            
            while(barNear.Count > ticksTimeFrame)
            {
                barFar.Add(barNear[0]);
                barNear.RemoveAt(0);
            }
            
            while(barFar.Count > ticksTimeFrame)
            {
                barFar.RemoveAt(0);
            }
            
            List<double> barFarCopy = new List<double>(barFar);
            List<double> barNearCopy = new List<double>(barNear);
            
            if(barFar.Count == ticksTimeFrame && barNear.Count == ticksTimeFrame)
            {
                
                barFarCopy.Sort();
                barNearCopy.Sort();
                double barNearMid = Math.Min(barNearCopy[0], barNearCopy[barNearCopy.Count - 1]) + Math.Abs(barNearCopy[0] - barNearCopy[barNearCopy.Count - 1]);

                double barFarMid = Math.Min(barFarCopy[0], barFarCopy[barFarCopy.Count - 1]) + Math.Abs(barFarCopy[0] - barFarCopy[barFarCopy.Count - 1]);
Will this just keep the last 2 windows of ticks and find their middle price?

Thanks
-Jeff


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Warsh Drops Easing Bias, December Hike Now Above 50% -- …
Prediction Markets & Event Contracts
Without Pulisic, USA 61.5% Live vs. Australia -- France …
Prediction Markets & Event Contracts
Fed Hike Odds at 57% After Warsh: England Surges 12.9%, …
Prediction Markets & Event Contracts
Thanks Mike. Godspeed.
The Elite Circle
Ninjatrader users - good CONNECTIONs post and article fr …
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Want your NinjaTrader indicator created, free?
5 thanks
Denied 20K payouts: Alpha Futures
1 thanks
FootPrintV2 Chart for NT8
1 thanks
BERN ALGOS algo trading journal
1 thanks
Afternoon-close session
1 thanks
  #3 (permalink)
Richard
Dallas TX/USA
 
Posts: 153 since Jun 2009
Thanks Given: 33
Thanks Received: 285



jeffbg123 View Post
Will this just keep the last 2 windows of ticks and find their middle price?

well you generally don't need to copy and then sort 10k-sized lists on every tick when all you want is the average of their largest and smallest values. As a first step you can just scan the list and locate the high and low in O(n) time. If you'd like to do better than that, I've written up an algorithm for maintaining a sorted sliding window with expected O(n/2) performance, which is article #5 on this page: Move the Markets| Articles.

I guess I wasn't totally clear on if you wanted the median, or the midpoint. Assuming the latter, then you'd want (H+L)/2... but as far as I can tell your code doesn't do that. It seems to be calculating Min(L, L + Abs(L - H))... which would always evaluate to L.

Hope this helps.


Reply With Quote




Last Updated on March 5, 2010


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts