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 JTizz, Today, 01:20 PM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by omermirza, Today, 12:39 PM
      1 response
      11 views
      0 likes
      Last Post NinjaTrader_Jim  
      Started by mballagan, Today, 01:02 PM
      0 responses
      5 views
      0 likes
      Last Post mballagan  
      Started by larkmail, Today, 12:30 PM
      1 response
      5 views
      0 likes
      Last Post NinjaTrader_Kate  
      Started by Danila, Today, 11:08 AM
      1 response
      11 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X