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!
See more
See less

Partner 728x90

Collapse

Strategy By Tick

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Strategy By Tick

    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

    #2
    Jeff,

    Unfortunately we will not be able to evaluate your code if it will work properly or not.

    Bear in mind though, your technique likely would not work for historical bars.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      I just want to know if I am using a proper technique or if there is something seriously wrong. This is my first time coding in NinjaTrader.


      Why won't it work historically?

      Thanks
      -Jeff

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by kujista, Today, 06:23 AM
      5 responses
      15 views
      0 likes
      Last Post kujista
      by kujista
       
      Started by f.saeidi, Today, 10:19 AM
      0 responses
      4 views
      0 likes
      Last Post f.saeidi  
      Started by traderqz, Yesterday, 09:06 AM
      2 responses
      16 views
      0 likes
      Last Post traderqz  
      Started by traderqz, Today, 12:06 AM
      3 responses
      6 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by RideMe, 04-07-2024, 04:54 PM
      5 responses
      28 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Working...
      X