Question going by tick - futures io
futures io futures trading



Question going by tick


Discussion in NinjaTrader

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




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Question going by tick

(login for full post details)
  #1 (permalink)
Chicago
 
Experience: Advanced
Platform: Other
 
Posts: 35 since Feb 2010
Thanks: 3 given, 1 received

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 futures io?
Neurological explanations for trading Success
Psychology and Money Management
NT8 indicator to simulate a Funding Evaluation where to …
NinjaTrader
Indicators for pair trading MES and M2K
Platforms and Indicators
Automatic pattern research with NT
Elite Algorithmic NinjaTrader Trading
Work with historical tcks data on MUltichart NET PowerLa …
MultiCharts
 
Best Threads (Most Thanked)
in the last 7 days on futures io
Battlestations: Show us your trading desks!
111 thanks
Selling Options on Futures?
109 thanks
Rank your Futures vs Stocks trading priority
37 thanks
Want your NinjaTrader indicator created, free?
26 thanks
Bitcoin storage wallet recommendations
18 thanks
 
(login for full post details)
  #3 (permalink)
Dallas TX/USA
 
 
Posts: 154 since Jun 2009
Thanks: 33 given, 283 received



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


futures io Trading Community Platforms and Indicators NinjaTrader > Question going by tick


Last Updated on March 5, 2010


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
 

Importance of Finding Your Own Way w/Adam Grimes

Elite only
 

Journal Challenge w/Jigsaw

April
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts