Ejemplo n.º 1
0
        void OnEntryPositions(IndicatorEventArgs e)
        {
            //New entry with no poistions for both legs
            if (HasPosition(0) <= 0 && HasPosition(1) <= 0)
            {
                string key = ctxPairSpdDaily.KeyLastDay;                //giSpdRs.GetDateStrByDateTime(Times[0][0]); //
                if (key == null)
                {
                    Print(string.Format("ctxPairSpdDaily.KeyLastDay CurrentBars={0}, BarsInProgress={1}, Times[][0]={2}",
                                        CurrentBars[BarsInProgress], BarsInProgress, Times[BarsInProgress][0]));
                    return;
                }
                CtxPairSpd ctxps = ctxPairSpdDaily.GetDayCtx(key);
                if (ctxps == null)
                {
                    return;
                }
                else
                {
                    int    quant1 = base.GetTradeQuantity(0, CapRatio1);
                    int    quant2 = base.GetTradeQuantity(1, CapRatio2);
                    string sig    = e.IndSignal.SignalName;
                    Print(String.Format("{0}:OnEntryPositions quant1={1}, quant2={2}: Spread={3}, Upper={4}, Lower={5}",
                                        CurrentBars[BarsInProgress], quant1, quant2, giSpdRs.Spread[0], giSpdRs.Upper[0], giSpdRs.Lower[0]));
                    if (TrendDirection.Down.ToString().Equals(ctxps.TrendDirection) &&
                        PositionInBand.Lower.ToString().Equals(ctxps.PositionInBand) &&
                        sig == giSpdRs.SignalName_AboveStdDev)
                    {
                        if (MktPosition1 != MarketPosition.Long && MktPosition2 != MarketPosition.Short)
                        {
                            EnterShort(0, quant1, giSpdRs.SignalName_EntryShortLeg1);
                            EnterLong(1, quant2, giSpdRs.SignalName_EntryLongLeg2);
                        }
                    }
                    else if (TrendDirection.Up.ToString().Equals(ctxps.TrendDirection) &&
                             PositionInBand.Upper.ToString().Equals(ctxps.PositionInBand) &&
                             sig == giSpdRs.SignalName_BelowStdDev)
                    {
                        if (MktPosition1 != MarketPosition.Short && MktPosition2 != MarketPosition.Long)
                        {
                            EnterLong(0, quant1, giSpdRs.SignalName_EntryLongLeg1);
                            EnterShort(1, quant2, giSpdRs.SignalName_EntryShortLeg2);
                        }
                    }
                }


//				if(MktPosition1 == MarketPosition.Long) {
//					EnterLong(0, quant1, giSpdRs.SignalName_EntryLongLeg1);
//				} else if(MktPosition1 == MarketPosition.Short) {
//					EnterShort(0, quant1, giSpdRs.SignalName_EntryShortLeg1);
//				}

//				if(MktPosition2 == MarketPosition.Long) {
//					EnterLong(1, quant2, giSpdRs.SignalName_EntryLongLeg2);
//				} else if(MktPosition2 == MarketPosition.Short) {
//					EnterShort(1, quant2, giSpdRs.SignalName_EntryShortLeg2);
//				}
            }
        }