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 cmtjoancolmenero, Yesterday, 03:58 PM
      9 responses
      35 views
      0 likes
      Last Post cmtjoancolmenero  
      Started by DayTradingDEMON, Today, 09:28 AM
      4 responses
      23 views
      0 likes
      Last Post DayTradingDEMON  
      Started by geddyisodin, Yesterday, 05:20 AM
      9 responses
      50 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by George21, Today, 10:07 AM
      1 response
      15 views
      0 likes
      Last Post NinjaTrader_ChristopherJ  
      Started by Stanfillirenfro, Today, 07:23 AM
      9 responses
      24 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X