Announcement

Collapse
No announcement yet.

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 twitch251, Today, 05:14 PM
      0 responses
      1 view
      0 likes
      Last Post twitch251  
      Started by robforee2, Today, 05:07 PM
      0 responses
      1 view
      0 likes
      Last Post robforee2  
      Started by blar58, Today, 03:16 PM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_Melissa  
      Started by alcorr247, Today, 02:52 PM
      2 responses
      7 views
      0 likes
      Last Post robforee2  
      Started by Radano, Today, 02:30 PM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_ChrisL  
      Working...
      X