Ejemplo n.º 1
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            double data;
            string datastr;

            if (Historical)
            {
                return;
            }

            for (int i = 0; i <= NinjaTrader.Cbi.Globals.Accounts.Count - 1; i++)
            {
                Print("Account: " + NinjaTrader.Cbi.Globals.Accounts[i].Name);
                Print("Netliq: " + NinjaTrader.Cbi.Globals.Accounts[i].GetAccountValue(AccountItem.NetLiquidation, Currency.UsDollar));
                if ((NinjaTrader.Cbi.Globals.Accounts[i].Name.CompareTo(accountName)) == 0)
                {
                    //data = Convert.ToDouble(NinjaTrader.Cbi.Globals.Accounts[i].GetAccountValue(AccountItem.NetLiquidation, Currency.UsDollar));
                    Plot0.Set(NinjaTrader.Cbi.Globals.Accounts[i].GetAccountValue(AccountItem.NetLiquidation, Currency.UsDollar).Value);

                    datastr = Convert.ToString(Time[0]) + "," + Convert.ToString((NinjaTrader.Cbi.Globals.Accounts[i].GetAccountValue(AccountItem.NetLiquidation, Currency.UsDollar).Value));

                    Print(datastr);

                    // Save it to file
                    using (FileStream fs = new FileStream(fileName, FileMode.Append, FileAccess.Write))
                        using (StreamWriter sw = new StreamWriter(fs))
                        {
                            sw.WriteLine(datastr);
                        }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.

            if (CurrentBar < 1)
            {
                return;
            }

            // get the openinng price of a stock from the daily
            openingPriceStock = Opens[0][0];
            //Print(openingPriceStock);

            currentPriceStock = Closes[0][0];
            //Print(currentPriceStock);

            openingPriceIndex = Opens[1][0];
            //Print(openingPriceIndex);

            currentPriceIndex = Closes[1][0];
            //Print(currentPriceIndex);

            Plot0.Set((currentPriceStock / openingPriceStock) / (currentPriceIndex / openingPriceIndex));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.
            if (CurrentBar < 6)
            {
                return;
            }

            decimal price0 = (decimal)(High[0] - Low[0]);
            decimal price1 = (decimal)(High[1] - Low[1]);
            decimal price2 = (decimal)(High[2] - Low[2]);
            decimal price3 = (decimal)(High[3] - Low[3]);
            decimal price4 = (decimal)(High[4] - Low[4]);
            decimal price5 = (decimal)(High[5] - Low[5]);
            decimal price6 = (decimal)(High[6] - Low[6]);


            price0 = decimal.Round(price0, 2, MidpointRounding.AwayFromZero);
            price1 = decimal.Round(price1, 2, MidpointRounding.AwayFromZero);
            price2 = decimal.Round(price2, 2, MidpointRounding.AwayFromZero);
            price3 = decimal.Round(price3, 2, MidpointRounding.AwayFromZero);
            price4 = decimal.Round(price4, 2, MidpointRounding.AwayFromZero);
            price5 = decimal.Round(price5, 2, MidpointRounding.AwayFromZero);
            price6 = decimal.Round(price6, 2, MidpointRounding.AwayFromZero);


            if ((price0 < price1) && (price0 < price2) && (price0 < price3) && (price0 < price4) && (price0 < price5) && (price0 < price6))
            {
                Plot0.Set(1);
            }
        }
Ejemplo n.º 4
0
 protected override void OnBarUpdate()
 {
     // Use this method for calculating your indicator values. Assign a value to each
     // plot below by replacing 'Close[0]' with your own formula.
     Plot0.Set(Close[0]);
     Plot1.Set(Close[0]);
     Plot3.Set(Close[0]);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // Calculate the volume average
            double _average = SMA(VOL(), period)[0];

            //double _volume = VOL()[0];

            Plot0.Set(_average);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // Calculate the range of the current bar and se the value

            myDataSeries.Set(Close[0] - Open[0]);



            Plot0.Set(SMA(sMAPeriod)[0] + myDataSeries[0]);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.

            // get the slope of the linear regression
            seriesOfLinReg.Set(LinRegSlope(9)[0]);

            // plot the SMA of the linear regression slope and multiply by 100
            Plot0.Set(((SMA(seriesOfLinReg, 20)[0]) * 100));
        }
 protected override void OnBarUpdate()
 {
     // Use this method for calculating your indicator values. Assign a value to each
     // plot below by replacing 'Close[0]' with your own formula.
     if (vixDataSet.ContainsKey(Time[0].ToShortDateString()))
     {
         //Print(Time[0].ToString() + "    " + vixDataSet[Time[0].ToShortDateString()]);
         //double close = vixDataSet[Time[0].ToShortDateString()];
         Plot0.Set(vixDataSet[Time[0].ToShortDateString()]);
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.
            //Plot0.Set(Close[0]);

            if (CurrentBar > Period)
            {
                Plot0.Set((Bollinger(deviation, Period).Upper[0] - Bollinger(deviation, Period).Lower[0]) / SMA(20)[0]);
            }
            else
            {
                Plot0.Set(0);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (CurrentBar < 5)
            {
                return;
            }


            if (MACD(12, 26, 9).Diff[0] >= MACD(12, 26, 9).Diff[1])
            {
                if ((MACD(12, 26, 9).Diff[1] < MACD(12, 26, 9).Diff[2]) & (MACD(12, 26, 9).Diff[2] < MACD(12, 26, 9).Diff[3]) & (MACD(12, 26, 9).Diff[3] < MACD(12, 26, 9).Diff[4]) & (MACD(12, 26, 9).Diff[4] < MACD(12, 26, 9).Diff[5]))
                {
                    Plot5.Set(MACD(12, 26, 9).Diff[0]);
                }

                else
                {
                    Plot5.Set(0);
                    Plot1.Set(MACD(12, 26, 9).Diff[0]);
                }
            }

            else
            {
                Plot1.Set(0);
            }

            if (MACD(12, 26, 9).Diff[0] < MACD(12, 26, 9).Diff[1])
            {
                if ((MACD(12, 26, 9).Diff[1] >= MACD(12, 26, 9).Diff[2]) & (MACD(12, 26, 9).Diff[2] >= MACD(12, 26, 9).Diff[3]) & (MACD(12, 26, 9).Diff[3] >= MACD(12, 26, 9).Diff[4]) & (MACD(12, 26, 9).Diff[4] >= MACD(12, 26, 9).Diff[5]))
                {
                    Plot4.Set(MACD(12, 26, 9).Diff[0]);
                }

                else
                {
                    Plot4.Set(0);
                    Plot0.Set(MACD(12, 26, 9).Diff[0]);
                }
            }

            else
            {
                Plot0.Set(0);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // Do not calculate if we don't have enough bars
            if (CurrentBar < Period)
            {
                return;
            }

            double sum = 0;

            for (int barsAgo = 0; barsAgo < Period; barsAgo++)
            {
                sum = sum + Input[barsAgo];
            }


            Plot0.Set(sum / Period);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.
            if (CurrentBar < 1)
            {
                return;
            }

            if ((High[0] > High[1]) & (Open[0] > Close[0]) & (Close[0] < Close[1]))
            {
                Plot0.Set(1);
            }

            if ((Low[0] < Low[1]) & (Close[0] > Open[0]) & (Close[0] > Close[1]))
            {
                Plot1.Set(1);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.
            // Plot0.Set(Close[0]);
            if (CurrentBar < 1)
            {
                return;
            }

            starttime = Time[1];

            durationtime = Time[0] - starttime;
            totalseconds = (int)durationtime.TotalSeconds;


            if (totalseconds > myInput0)
            {
                totalseconds = myInput0;
                secperbar.Set(totalseconds);

                if (drawSMA)
                {
                    Plot0.Set(SMA(secperbar, sMAPeriod)[0]);
                }
                Plot1.Set(totalseconds);

//				PlotColors[0][0] = Color.Red;
                PlotColors[1][0] = Color.Red;
            }
            else
            {
                secperbar.Set(totalseconds);

                if (drawSMA)
                {
                    Plot0.Set(SMA(secperbar, sMAPeriod)[0]);
                }

                Plot1.Set(totalseconds);
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.

            if (CurrentBar < 1)
            {
                return;
            }

            if ((EMA(fastEMA)[0] > EMA(slowEMA)[0]) & !(EMA(fastEMA)[1] > EMA(slowEMA)[1]))
            {
                Plot0.Set(1); //blue
            }

            if ((EMA(slowEMA)[0] > EMA(fastEMA)[0]) & !(EMA(slowEMA)[1] > EMA(fastEMA)[1]))
            {
                Plot1.Set(1); //red
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.
            if (CurrentBar < 4)
            {
                return;
            }


            if ((High[2] >= High[0]) && (High[2] >= High[1]) && (High[2] >= High[3]) && (High[2] >= High[4]))
            {
                Plot0.Set(2, 1);
                return;
            }


            if ((Low[2] <= Low[0]) && (Low[2] <= Low[1]) && (Low[2] <= Low[3]) && (Low[2] <= Low[4]))
            {
                Plot1.Set(2, 1);
                return;
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            double total_position_usd = 0.0;

            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.
            Plot0.Set(Close[0]);
            for (int i = 0; i <= NinjaTrader.Cbi.Globals.Accounts.Count - 1; i++)
            {
                //Print("Account: " + NinjaTrader.Cbi.Globals.Accounts[i].Name);

                //Print("Cashvalue: " + NinjaTrader.Cbi.Globals.Accounts[i].GetAccountValue(AccountItem.CashValue, Currency.UsDollar));

                if ((NinjaTrader.Cbi.Globals.Accounts[i].Name.CompareTo("U1465027")) == 0)
                {
                    for (int j = 0; j <= NinjaTrader.Cbi.Globals.Accounts[i].Positions.Count - 1; j++)
                    {
                        Print("Position: " + NinjaTrader.Cbi.Globals.Accounts[i].Positions.Count);
                        Print("Position: " + NinjaTrader.Cbi.Globals.Accounts[i].Positions[j].Instrument);
                        //total_position_usd += NinjaTrader.Cbi.Globals.Accounts[i].Positions[j]  //need position value, but none available!!!!
                    }
                }
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.
            if (CrossAbove(anaAwesomeOscillator(5, false, 34, 3).Oscillator, ZeroLine, 1))
            {
                DrawSquare("My square" + CurrentBar, false, 0, 0, Color.Orange);
                Alert("MyAlert6", NinjaTrader.Cbi.Priority.High, "AnaAwesome CrossAbove0", "Alert1.wav", 10, Color.White, Color.Black);
                Print("CrossAbove");
                Print(Instrument.FullName);
                Print("," + Time[0] + " " + Close[0]);
                Plot0.Set(Close[0]);
            }

            // Condition set 2
            if (CrossBelow(anaAwesomeOscillator(5, false, 34, 3).Oscillator, ZeroLine, 1))
            {
                DrawSquare("My square" + CurrentBar, false, 0, 0, Color.Magenta);
                Alert("MyAlert7", NinjaTrader.Cbi.Priority.High, "AnaAwesome Crossed Below 0", "Alert2.wav", 10, Color.White, Color.Black);
                Print("CrossBelow");
                Print(Instrument.FullName);
                Print("," + Time[0] + " " + Close[0]);
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.
            //Plot0.Set(Close[0]);

            /* The squeeze takes advantage of quiet periods in the market when the volatility
             * has decreased significantly and the market is building up energy for its next major
             * move higher or lower. Period of low volatility are identified as the times when the bands
             * "move closer together". How do we know that the current narrowness is really narrow enough
             * to qualify as low volatility? By adding Keltner Channels and momentum index oscillator
             * as per mentioned in John Carter's book Mastering the Trade.
             *
             * While Bolling Bands expand and contract as the markets alter between periods of high and
             * low volatility, the Keltner Channels stay in more of a steady range. The momentum index
             * oscillator is used to estimate the direction.
             *
             * How does this Setup work?
             * The quite period is identified whent he Bollinger Bands narrow in width to the point that
             * they are actually trading inside of the Keltner Channels. This marks a period of reduced
             * volatility and signals that the market is taking a significant breather, building up steam
             * for its next move. The trade signal occurs when the Bollinger Bands then move back outside
             * the Keltner Channels. Use 12 period momentum index oscillator to determine whether to go
             * long or short. If the oscillator is above 0 when this happens, GO LONG; if it id below 0 then
             * GO SHORT.
             *
             * Usually the moves are explosive when the BB Width is lowest over past 6 months which comes to
             * across 126 days and hence we need more than 126 price data bars.
             *
             */

            if (CurrentBar > 127)
            {
                /* if (bBandWidth < 0)
                 * {
                 *      bBandWidth=0;
                 * }*/

                if (KeltnerChannel(kCDeviation, Period).Upper[0] > Bollinger(bBDeviation, Period).Upper[0] &&
                    KeltnerChannel(kCDeviation, Period).Lower[0] < Bollinger(bBDeviation, Period).Lower[0] &&
                    (BollingerBandWidth2(bBDeviation, Period)[0] == MIN(BollingerBandWidth2(bBDeviation, Period), 126)[0])) //BollingerBandWidth(bBdeviation,Period)[0] > bollingerWidth)
                {
                    Plot0.Set(1);                                                                                           //This is just a warning signal to be ready
                    blnFlag = true;
                }
                else if (blnFlag &&
                         KeltnerChannel(kCDeviation, Period).Upper[0] <= Bollinger(bBDeviation, Period).Upper[0] &&
                         KeltnerChannel(kCDeviation, Period).Lower[0] >= Bollinger(bBDeviation, Period).Lower[0])
                {
                    Plot0.Set(Momentum(momentumPeriod)[0] > 0? 2:-2);                    // +ve buy & -ve short
                    blnFlag = false;
                }
                else
                {
                    Plot0.Set(0);
                }
            }
            else
            {
                Plot0.Set(0);
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.


            if (CurrentBar < 30)
            {
                return;
            }


            if ((Low[0] <= DonchianChannel(14)[0]) & (Low[1] > DonchianChannel(14)[1]))
            {
                Plot1.Set(1);
            }


            if ((High[0] >= DonchianChannel(14)[0]) & (High[1] < DonchianChannel(14)[1]))
            {
                Plot0.Set(1);
            }

            int up   = 0;
            int down = 0;
            int y    = 0;

            for (int x = 1; x <= 100; x++)
            {
                if ((Low[x] <= DonchianChannel(14)[x]) & (Low[x + 1] > DonchianChannel(14)[x + 1]))
                {
                    up = 1;
                    y  = x;
                    break;
                }


                if ((High[x] >= DonchianChannel(14)[x]) & (High[x + 1] < DonchianChannel(14)[x + 1]))
                {
                    down = 1;
                    y    = x;
                    break;
                }
            }


            int firstup   = 0;
            int firstdown = 0;


            for (int x = 0; x <= 100; x++)
            {
                if ((up == 1) & (High[x] > High[x + 1]))
                {
                    if (x >= y)
                    {
                        break;
                    }

                    if (x != 0)
                    {
                        firstup = 1;
                        break;
                    }

                    /*
                     * if (!(x < y))
                     * {
                     *  break;
                     * }*/
                }


                if ((down == 1) & (Low[x] < Low[x + 1]))
                {
                    if (x >= y)
                    {
                        break;
                    }

                    if (x != 0)
                    {
                        firstdown = 1;
                        break;
                    }

                    /*
                     * if (!(x < y))
                     * {
                     *  break;
                     * }*/
                }
            }

            if ((firstup == 0) & (up == 1) & (High[0] > High[1]))
            {
                Plot3.Set(1);
            }

            if ((firstdown == 0) & (down == 1) & (Low[0] < Low[1]))
            {
                Plot2.Set(1);
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.
            if (CurrentBar < 10)
            {
                return;
            }

            if (High[2] < High[3] && High[1] < High[3])
            {
                // Fractal type 1
                if (High[5] < High[3] && High[4] < High[3])
                {
                    upFractal = High[3];
                }

                // Fractal type 2
                else if (High[6] < High[3] && High[5] < High[3] && High[4] == High[3])
                {
                    upFractal = High[3];
                }

                // Fractal type 3, 4
                else if (High[7] < High[3] && High[6] < High[3] && High[5] == High[3] && High[4] <= High[3])
                {
                    upFractal = High[3];
                }

                // Fractal type 5
                else if (High[8] < High[3] && High[7] < High[3] && High[6] == High[3] && High[5] < High[3] && High[4] == High[3])
                {
                    upFractal = High[3];
                }

                // Fractal type 6
                else if (High[8] < High[3] && High[7] < High[3] && High[6] == High[3] && High[5] == High[3] && High[4] < High[3])
                {
                    upFractal = High[3];
                }

                // Fractal type 7
                else if (High[9] < High[3] && High[8] < High[3] && High[7] == High[3] && High[6] < High[3] && High[5] == High[3] && High[4] < High[3])
                {
                    upFractal = High[3];
                }
            }

            if (Low[2] > Low[3] && Low[1] > Low[3])
            {
                // Fractal type 1
                if (Low[5] > Low[3] && Low[4] > Low[3])
                {
                    downFractal = Low[3];
                }

                // Fractal type 2
                else if (Low[6] > Low[3] && Low[5] > Low[3] && Low[4] == Low[3])
                {
                    downFractal = Low[3];
                }

                // Fractal type 3, 4
                else if (Low[7] > Low[3] && Low[6] > Low[3] && Low[5] == Low[3] && Low[4] >= Low[3])
                {
                    downFractal = Low[3];
                }

                // Fractal type 5
                else if (Low[8] > Low[3] && Low[7] > Low[3] && Low[6] == Low[3] && Low[5] > Low[3] && Low[4] == Low[3])
                {
                    downFractal = Low[3];
                }

                // Fractal type 6
                else if (Low[8] > Low[3] && Low[7] > Low[3] && Low[6] == Low[3] && Low[5] == Low[3] && Low[4] > Low[3])
                {
                    downFractal = Low[3];
                }

                // Fractal type 7
                else if (Low[9] > Low[3] && Low[8] > Low[3] && Low[7] == Low[3] && Low[6] > Low[3] && Low[5] == Low[3] && Low[4] > Low[3])
                {
                    downFractal = Low[3];
                }
            }
            if (upFractal != 0)
            {
                Plot0.Set(upFractal);
            }
            if (downFractal != 0)
            {
                Plot1.Set(downFractal);
            }
            if (Math.Abs(Math.Abs(upFractalSeries[0]) - Math.Abs(upFractalSeries[1])) <= 0.0001)
            {
                upFractalSeries[0] = upFractalSeries[1];
            }
            else
            {
                upFractalSeries[0] = upFractal;
            }
            if (Math.Abs(Math.Abs(downFractalSeries[0]) - Math.Abs(downFractalSeries[1])) <= 0.0001)
            {
                downFractalSeries[0] = downFractalSeries[1];
            }
            else
            {
                downFractalSeries[0] = downFractal;
            }
        }