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

Help Programming Scanning Critera?

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

    Help Programming Scanning Critera?

    Hello Everyone,
    I'm trying to test the Ninjatrader scanner to see if it will work with my system. I have no idea how to program in Ninjascript and hardly know any C programming, so I was hoping somebody may be able to make a couple of the scripts for me. The criteria I'm trying to scan for is:
    1. Average Volume
    2. Relative Volume
    3. Trading outside the first 15 minute bar
    4. Inside bar on the 15/30/60 minute chart (simultaneously)


    I'd really appreciate if I could get some help with this, as I can't get through one line of code without being thrown a bunch of errors.

    #2
    Hi TheProfitcy,

    Let me know if there are any errors you'd like assistance with. Also,this thread will remain open for the community to respond to.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      It depends

      You can add it to a market analyzer but that wont tie directly into your strategy,

      You mentioned that you are trying out Python in a PM to me, you could build a global function in Python and call it from ninjatrader's C# via IronPy.

      Or you could write code directly into a indicator or strategy; but it is going to slow your system down making it very hard to backtest.

      This might help get you started its a CSI indicator that ranks CSI. Adding it to a strategy should be strait forward; trade if rank is 1 or whatever your threshold is.

      Code:
      #region Using declarations
      using System;
      using System.ComponentModel;
      using System.Diagnostics;
      using System.Drawing;
      using System.Drawing.Drawing2D;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Data;
      using NinjaTrader.Gui.Chart;
      #endregion
      
      
      namespace NinjaTrader.Indicator
      {
        
          [Description("Ranks Commodity based on its CSI score")]
          public class CSIRank : Indicator
          {
              #region Variables
      		
      		//CSI Parameters
      		private int period = 14;
      		private double MarginRequirement = 2500;
      		
      		
      		private int Minutes = 120;
      		private double[] rCSI = new double[8];  //Holds the calculated CSI of each Commodity
      		//private int[] RankByBars = new int[6];  //Holds the CSI rank of each bar object by barsArray index
      		//private int[] BarsByRank = new int[6];  //Holds the barsArray index by CSI Rank
              private int RankCount = 0;
      		private DataSeries RankCSI;
      		
      		//Commodity List
      		private string symbol1 = "CL ##-##";
      		private string symbol2 = "GC ##-##";
      		private string symbol3 = "6A ##-##";
      		private string symbol4 = "ZN ##-##";
      		private string symbol5 = "HG ##-##";
      		private string symbol6 = "NG ##-##";
      		private string symbol7 = "ZC ##-##";
      		
              #endregion
      
              
              protected override void Initialize()
              {
                  Overlay	= true;
      			CalculateOnBarClose = true;
      			//BarsRequired = 100;
      			
      			//Add Commodities
      			Add(PeriodType.Minute, Minutes);
      			Add(symbol1,PeriodType.Minute, Minutes);
      			Add(symbol2,PeriodType.Minute, Minutes);
      			Add(symbol3,PeriodType.Minute, Minutes);
      			Add(symbol4,PeriodType.Minute, Minutes);
      			Add(symbol5,PeriodType.Minute, Minutes);
      			Add(symbol6,PeriodType.Minute, Minutes);
      			Add(symbol7,PeriodType.Minute, Minutes);
      			
      			RankCSI = new DataSeries(this);
      			
              }
      
              
              protected override void OnBarUpdate()
              {
      			if (BarsInProgress != 0) return;
      			if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired)
      				{Print("No Data"); return;}
      		
      			//Check to make sure there is enough bars 
      //			if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired) return;
      //            if(BarsArray[1].CurrentBar <= BarsRequired) return;
      //			if(BarsArray[2].CurrentBar <= BarsRequired) return;
      //			if(BarsArray[3].CurrentBar <= BarsRequired) return;
      //			if(BarsArray[4].CurrentBar <= BarsRequired) return;
      //			if(BarsArray[5].CurrentBar <= BarsRequired) return;
      //			if(BarsArray[6].CurrentBar <= BarsRequired) return;
      //			if(BarsArray[7].CurrentBar <= BarsRequired) return;
      //			
      			//Calculate Rank of each commodity
      			
      			
      			for(int i = 0; i < 8; i++) // calculate rank of i-th SPDR
      				{
      					rCSI[i] = Math.Round(CSI(BarsArray[i+1],MarginRequirement,period).csi1[0],2);
      				}
      				
      				Print(" " + BarsArray[1].Instrument.FullName + " " + rCSI[0]);
      				Print(" " + BarsArray[2].Instrument.FullName + " " + rCSI[1]);
      				Print(" " + BarsArray[3].Instrument.FullName + " " + rCSI[2]);
      				Print(" " + BarsArray[4].Instrument.FullName + " " + rCSI[3]);
      				Print(" " + BarsArray[5].Instrument.FullName + " " + rCSI[4]);
      				Print(" " + BarsArray[6].Instrument.FullName + " " + rCSI[5]);
      				Print(" " + BarsArray[7].Instrument.FullName + " " + rCSI[6]);
      				Print(" " + BarsArray[8].Instrument.FullName + " " + rCSI[7]);
      				
      			RankCount = 1;	
      			for(int j = 0; j < 8; j++)
      			{
      
      
      					if(rCSI[j] > rCSI[0])
      					{
      						RankCount++;
      						Print(RankCount);
      					}
      						
      					
      
      			}
      			
      			RankCSI[0] = (RankCount);
      			DrawTextFixed("CSIr", "CSI Rank: " + RankCSI[0], TextPosition.TopRight);
      			
              }
      
      
      	       
              #endregion
          }
      }
      Good luck, PM like earlier if you get stuck

      Cheers,

      Sody

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by kujista, Today, 06:23 AM
      0 responses
      1 view
      0 likes
      Last Post kujista
      by kujista
       
      Started by traderqz, Yesterday, 04:32 PM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by f.saeidi, Today, 05:56 AM
      1 response
      4 views
      0 likes
      Last Post Jltarrau  
      Started by Jltarrau, Today, 05:57 AM
      0 responses
      4 views
      0 likes
      Last Post Jltarrau  
      Started by Stanfillirenfro, Yesterday, 09:19 AM
      7 responses
      52 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Working...
      X