Пример #1
0
        public static int getSlope(NinjaTrader.Indicator.Indicator ind, DataSeries series, int index)
        {
            if (!series.ContainsValue(3))
            {
                return(0);
            }

            return((int)(((180 / Math.PI) * (Math.Atan((series.Get(index) - ((series.Get(index + 1) + series.Get(index + 2)) / 2)) / 1.5 / ind.TickSize))) * -1));
        }
Пример #2
0
        public static int getSlope(Strategy strat, DataSeries series, int index)
        {
            if (!series.ContainsValue(3))
            {
                return(0);
            }

            return((int)(((180 / Math.PI) * (Math.Atan((series.Get(index) - ((series.Get(index + 1) + series.Get(index + 2)) / 2)) / 1.5 / strat.TickSize))) * -1));
        }
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            double value1 = 0.0;
            double value2 = 0.0;

            o.Update();
            h.Update();
            l.Update();
            c.Update();

            for (int i = 0; i < len; ++i)
            {
                value1 += (c.filtered(i) - o.filtered(i));
                value2 += (h.filtered(i) - l.filtered(i));
            }

            if (value2 != 0.0)
            {
                unsmoothed.Set(100.0 * value1 / value2);
            }
            else
            {
                if ((CurrentBar > 1) && unsmoothed.ContainsValue(1))
                {
                    unsmoothed.Set(unsmoothed[1]);
                }
                else
                {
                    unsmoothed.Set(0);
                }
            }

            if (weightma == null)
            {
                weightma = WMA(unsmoothed, smoothing);
                expma    = EMA(weightma.Value, trigger);
            }

            ECO.Set(weightma[0]);
            TriggerLine.Set(expma[0]);
            Histogram.Set(weightma[0] - expma[0]);
        }
Пример #4
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if(BarsInProgress==6){
                DateTime dt=Times[6][0];
                TimeSpan ts=dt.TimeOfDay;
                //log("*** "+ts+"==="+tw);
                if(vv||tw==null||ts.CompareTo(tw)<=0){
                    vv=false;
                    tw=ts;
                    log("==================INIT spreadDataSeriesAsk");
                    spreadAsks=new Stack<int>();
                    //spreadDataSeriesAsk = new DataSeries(this);
                    //spreadDataSeriesBid = new DataSeries(this);
                }

            }

            if(BarsInProgress==3)
                t=Times[3][0];
            if(active==false){
                if (CurrentBars[1] < 1 || CurrentBars[2] < 1)
                    return;
                active=true;

            }
            /*if(virgin){
                int spread_ask=(int)(Closes[3][0]*4)-(int)(Closes[6][0]);
                int spread_bid=(int)(Closes[4][0]*4)-(int)(Closes[5][0]);
                top=spread_ask+Target;
                bottom=spread_bid-Target;
                PrintWithTimeStamp(name+" SET RANGE TOP:"+top+", BOTTOM:"+bottom);
                log(" SET RANGE TOP:"+top+", BOTTOM:"+bottom);
                virgin=false;
            }*/
                if(BarsInProgress==6){
                    int spread_ask=(int)(Closes[3][0]*4)-(int)(Closes[6][0]);
                //	int spread_bid=(int)(Closes[4][0]*4)-(int)(Closes[5][0]);
                    total++;

                    //log("ask<"+RuntimeHelpers.GetHashCode(spreadDataSeriesAsk)+">"+spread_ask);
                    spreadDataSeriesAsk.Set(spread_ask);

                    spreadAsks.Push(spread_ask);
                    spreadDataSeriesAsk=new DataSeries(this);
                    //[]=Stack<int> stackAsks=new Stack<int>();
                    int[] ar=spreadAsks.ToArray();
                    for(int i=Math.Min(ar.GetUpperBound(0),mAPeriod+6);i>=0;i--){
                        spreadDataSeriesAsk.Set(i,ar[i]);
                    }

                    if(CurrentBars[6]>mAPeriod){
                        //if(CurrentBars[6]>mAPeriod){
                        //	sma=SMA(spreadDataSeriesAsk,mAPeriod)[0];
                            int x=1;
                            String p="SMA["+sma+"]=";
                            trade_active=false;
                            String pp=Times[BarsInProgress]+"VALUES["+BarsInProgress+"]:";
                            for(int i=0;i<mAPeriod;i++){
                                if(spreadDataSeriesAsk.ContainsValue(i))
                                pp+="i="+i+":"+spreadDataSeriesAsk[i]+";";
                            }
                            //log(pp+"  "+"MAX="+MAX(spreadDataSeriesAsk,6)[1]+";MIN="+MIN(spreadDataSeriesAsk,6)[1]);
                            sma=SMA(spreadDataSeriesAsk,6)[0];

                            if(Math.Abs(MAX(spreadDataSeriesAsk,rangePeriod)[1]-MIN(spreadDataSeriesAsk,rangePeriod)[1])<range){
                                while(x<6){

                                    double d=SMA(spreadDataSeriesAsk,6)[x];
                                    if(d==0.0)
                                        break;
                                    p+=d+";";
                                    /*if(Math.Abs(d-sma)<breakSMA&&Math.Abs(spread_ask-d)>breakSpread){
                                        active=false;
                                        break;
                                    }*/
                                    if(sma<=d+breakSMA||spread_ask<d+breakSpread)
                                        break;
                                    x++;
                                }
                                if(x==6){

                                //	log(p);
                                    dir=1;

                                    while (x>0){

                                        if(spread_ask-breakSpread<spreadDataSeriesAsk[x+1])
                                            break;
                                        x--;
                                    }
                                    if(x==0)
                                        trade_active=true;
                                }
                                else{
                                    x=1;
                                    p="SMA["+sma+"]=";
                                    while(x<6){

                                        double d=SMA(spreadDataSeriesAsk,6)[x];
                                        if(d==0.0)
                                        break;
                                        p+=d+";";
                                        /*if(Math.Abs(d-sma)<breakSMA&&Math.Abs(spread_ask-d)>breakSpread){
                                            active=false;
                                            break;
                                        }*/
                                        if(sma>=d-breakSMA||spread_ask>d-breakSpread)
                                            break;
                                        x++;
                                    }
                                    if(x==6){
                                        //log(p);
                                        dir=-1;
                                        while (x>0){

                                            if(spread_ask-breakSpread<spreadDataSeriesAsk[x+1])
                                                break;
                                            x--;
                                        }
                                    if(x==0)
                                        trade_active=true;

                                    }
                                }
                        //	}
                            /*
                            if(active){
                                if(spread_ask>SMA(spreadDataSeriesAsk,mAPeriod)[1])
                                    dir=1;
                                else
                                    dir=-1;
                            }*/

                            //log(p);

                        }
                    }
                    //double r=ROC(Spread_SMA,2)[0];
                    //Spread_ROC.Set(v+r*100);
            //	}
            }
            if(Historical&&!tradingLive){ // when backtesting to the trades
                processTick(Closes[3][0],Closes[4][0],Closes[5][0],Closes[6][0]);
            }
        }
Пример #5
0
 public static int GetSlope(NinjaTrader.Strategy.Strategy strat, DataSeries series, int index)
 {
     return !series.ContainsValue(3) ? 0 : (int)((57.295779513082323 * Math.Atan(((series.Get(index) - ((series.Get(index + 1) + series.Get(index + 2)) / 2.0)) / 1.5) / strat.TickSize)) * -1.0);
 }
Пример #6
0
 public static int GetSlope(Indicator ind, DataSeries series, int index)
 {
     return !series.ContainsValue(3) ? 0 : (int)((57.295779513082323 * Math.Atan(((series.Get(index) - ((series.Get(index + 1) + series.Get(index + 2)) / 2.0)) / 1.5) / ind.TickSize)) * -1.0);
 }
Пример #7
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            var ed = extdat.getExtraData(0, Bars, CurrentBar);

            if (ed == null)
            {
                return;
            }

            if (CurrentBar != lastSeenBar)
            {
                for (int i = 0; i < 4; ++i)
                {
                    pol[i] = ol[i];         // remember previous bar value...
                    phl[i] = hl[i];
                    pll[i] = ll[i];
                    pcl[i] = cl[i];
                }
                lastSeenBar = CurrentBar;
            }


            // update all the Laguerre numbers....
            ol[0] = (1 - gamma) * ed.dOpen + gamma * pol[0];
            hl[0] = (1 - gamma) * ed.dHigh + gamma * phl[0];
            ll[0] = (1 - gamma) * ed.dLow + gamma * pll[0];
            cl[0] = (1 - gamma) * ed.dClose + gamma * pcl[0];
            for (int i = 1; i < 4; ++i)
            {
                ol[i] = -gamma * ol[i - 1] + pol[i - 1] + gamma * pol[i];
                hl[i] = -gamma * hl[i - 1] + phl[i - 1] + gamma * phl[i];
                ll[i] = -gamma * ll[i - 1] + pll[i - 1] + gamma * pll[i];
                cl[i] = -gamma * cl[i - 1] + pcl[i - 1] + gamma * pcl[i];
            }

            double value1 = 0.0;
            double value2 = 0.0;

            for (int i = 0; i < 4; ++i)
            {
                value1 += (cl[i] - ol[i]);
                value2 += (hl[i] - ll[i]);
            }

            if (value2 != 0.0)
            {
                unsmoothed.Set(100.0 * value1 / value2);
            }
            else
            {
                if ((CurrentBar > 1) && unsmoothed.ContainsValue(1))
                {
                    unsmoothed.Set(unsmoothed[1]);
                }
                else
                {
                    unsmoothed.Set(0);
                }
            }

            if (weightma == null)
            {
                weightma = WMA(unsmoothed, smoothing);
                expma    = EMA(weightma.Value, trigger);
            }

            ECO.Set(weightma[0]);
            TriggerLine.Set(expma[0]);
            Histogram.Set(weightma[0] - expma[0]);
        }
Пример #8
0
        protected override void OnBarUpdate()
        {
            double f;
            double s;

            if (CurrentBar <= Math.Max(FastAverage, SlowAverage))
            {
                return;
            }
            switch (FastAverageType)
            {
            case MovingAverageType.EMA:
                f = EMA(_fastInput, FastAverage)[0];
                break;

            case MovingAverageType.SMA:
                f = SMA(_fastInput, FastAverage)[0];
                break;

            case MovingAverageType.TMA:
                f = TMA(_fastInput, FastAverage)[0];
                break;

            case MovingAverageType.WMA:
                f = WMA(_fastInput, FastAverage)[0];
                break;

            case MovingAverageType.VWMA:
                f = VWMA(_fastInput, FastAverage)[0];
                break;

            default:
                f = HMA(_fastInput, FastAverage)[0];
                break;
            }

            FastMA.Set(f);

            switch (SlowAverageType)
            {
            case MovingAverageType.EMA:
                s = EMA(_slowInput, SlowAverage)[0];
                break;

            case MovingAverageType.SMA:
                s = SMA(_slowInput, SlowAverage)[0];
                break;

            case MovingAverageType.TMA:
                s = TMA(_slowInput, SlowAverage)[0];
                break;

            case MovingAverageType.WMA:
                s = WMA(_slowInput, SlowAverage)[0];
                break;

            case MovingAverageType.VWMA:
                s = VWMA(_slowInput, SlowAverage)[0];
                break;

            default:
                s = HMA(_slowInput, SlowAverage)[0];
                break;
            }
            SlowMA.Set(s);

            if (High[0] < SlowMA[0] &&
                High[0] < FastMA[0])
            {
                if (Math.Min(SlowMA[0], FastMA[0]) - High[0] > pipsOffset)
                {
                    trendDataSeries[0] = -1.1;
                }
                else
                if (trendDataSeries.ContainsValue(1))
                {
                    trendDataSeries[0] = trendDataSeries[1];
                }
            }
            else if (Low[0] > SlowMA[0] &&
                     Low[0] > FastMA[0])
            {
                if (Low[0] - Math.Max(SlowMA[0], FastMA[0]) > pipsOffset)
                {
                    trendDataSeries[0] = 1.1;
                }
                else
                if (trendDataSeries.ContainsValue(1))
                {
                    trendDataSeries[0] = trendDataSeries[1];
                }
            }
            else
            {
                if (trendDataSeries.ContainsValue(1))
                {
                    trendDataSeries[0] = trendDataSeries[1];
                }
            }

            if (trendDataSeries.ContainsValue(0))
            {
                //plot
                if (trendDataSeries[0] > 1)
                {
                    DrawDiamond(CurrentBar + "dot", false, 0, High[0] + 25 * TickSize, Color.Green);
                }
                else if (trendDataSeries[0] < -1)
                {
                    DrawDiamond(CurrentBar + "dot", false, 0, Low[0] - 25 * TickSize, Color.Red);
                }
            }
        }
Пример #9
0
 public static int GetSlope(NinjaTrader.Strategy.Strategy strat, DataSeries series, int index)
 {
     return(!series.ContainsValue(3) ? 0 : (int)((57.295779513082323 * Math.Atan(((series.Get(index) - ((series.Get(index + 1) + series.Get(index + 2)) / 2.0)) / 1.5) / strat.TickSize)) * -1.0));
 }
Пример #10
0
 public static int GetSlope(Indicator ind, DataSeries series, int index)
 {
     return(!series.ContainsValue(3) ? 0 : (int)((57.295779513082323 * Math.Atan(((series.Get(index) - ((series.Get(index + 1) + series.Get(index + 2)) / 2.0)) / 1.5) / ind.TickSize)) * -1.0));
 }