protected override void CalcBar()
        {
            var m_avg   = m_AverageFC[0];
            var m_shift = NumAtrs * this.AverageTrueRange(Length);

            m_LowerBand.Value = m_avg - m_shift;
            if (Bars.CurrentBar > 1 && Price.CrossesUnder(m_LowerBand, ExecInfo.MaxBarsBack))
            {
                m_bSetupSE.Value    = true;
                m_CrossingLow.Value = Bars.Low[0];
            }
            else
            {
                if (m_bSetupSE.Value &&
                    (PublicFunctions.DoubleGreater(Price[0], m_avg) ||
                     PublicFunctions.DoubleLessEquals(Bars.Low[0], m_CrossingLow.Value - Bars.Point)))
                {
                    m_bSetupSE.Value = false;
                }
            }
            if (m_bSetupSE.Value)
            {
                m_KltChSE.Send(m_CrossingLow.Value - Bars.Point);
            }
        }
Example #2
0
        protected override void CalcBar()
        {
            m_MP.Value = StrategyInfo.MarketPosition;

            if (m_MP.Value > 0)
            {
                if (m_MP[1] <= 0)
                {
                    m_StopPrice.Value = Bars.Low[0] - this.AverageTrueRange(AtrLength) * NumAtrs;
                    m_AF.Value        = AccfactorStep;
                    m_TradeHH.Value   = Bars.High[0];
                }
                else
                {
                    if (PublicFunctions.DoubleGreater(Bars.High[0], m_TradeHH.Value))
                    {
                        m_TradeHH.Value = Bars.High[0];
                    }
                    m_StopPrice.Value += m_AF.Value * (m_TradeHH.Value - m_StopPrice.Value);
                    if (PublicFunctions.DoubleGreater(m_TradeHH.Value, m_TradeHH[1]) &&
                        PublicFunctions.DoubleLess(m_AF.Value, AccFactorLimit))
                    {
                        m_AF.Value += PublicFunctions.Min(AccfactorStep, AccFactorLimit - m_AF.Value);
                    }
                }
                if (PublicFunctions.DoubleGreater(m_StopPrice.Value, Bars.Low[0]))
                {
                    m_StopPrice.Value = Bars.Low[0];
                }
                m_ParTrLX.Send(m_StopPrice.Value);
            }
        }
Example #3
0
        protected override void CalcBar()
        {
            var m_fastavg = price.Average(fastlength);
            var m_slowavg = price.Average(slowlength);

            if (PublicFunctions.DoubleGreater(m_fastavg, m_slowavg))
            {
                Plot1.Set(0, Bars.High[0], upcolor);
                Plot2.Set(0, Bars.Low[0], upcolor);
                Alerts.Alert("FastAvg above SlowAvg");
            }
            else
            {
                if (PublicFunctions.DoubleLess(m_fastavg, m_slowavg))
                {
                    Plot1.Set(0, Bars.High[0], dncolor);
                    Plot2.Set(0, Bars.Low[0], dncolor);
                    Alerts.Alert("FastAvg below SlowAvg");
                }
                else
                {
                    Plot1.Reset();
                }
            }
        }
 protected override void CalcBar()
 {
     CurSpecOrdersMode = ESpecOrdersMode.PerContract;
     if (StrategyInfo.MarketPosition != 0)
     {
         if (PublicFunctions.DoubleGreater(ProfitTargetPct, 0))
         {
             GenerateProfitTarget(this.EntryPrice() * ProfitTargetPct);  //bk price * (1+tp)
         }
         if (PublicFunctions.DoubleGreater(StopLossPct, 0))
         {
             GenerateStopLoss(this.EntryPrice() * StopLossPct);
         }
     }
     else
     {
         if (PublicFunctions.DoubleGreater(ProfitTargetPct, 0))
         {
             GenerateProfitTarget(Bars.Close[0] * ProfitTargetPct);    //c *(1+tp);
         }
         if (PublicFunctions.DoubleGreater(StopLossPct, 0))
         {
             GenerateStopLoss(Bars.Close[0] * StopLossPct);
         }
     }
 }
        protected override void CalcBar()
        {
            CurSpecOrdersMode = IsPerContractOption ? ESpecOrdersMode.PerContract : ESpecOrdersMode.PerPosition;

            if (PublicFunctions.DoubleGreater(ProfitTargetAmt, 0))
            {
                GenerateProfitTarget(ProfitTargetAmt);
            }
            if (PublicFunctions.DoubleGreater(StopLossAmt, 0))
            {
                GenerateStopLoss(StopLossAmt);
            }
            if (PublicFunctions.DoubleGreater(BreakEvenFloorAmt, 0))
            {
                GenerateBreakEven(BreakEvenFloorAmt);
            }
            if (PublicFunctions.DoubleGreater(DollarTrailingAmt, 0))
            {
                GenerateDollarTrailing(DollarTrailingAmt);
            }
            if (PublicFunctions.DoubleGreater(PctTrailingFloorAmt, 0) &&
                PublicFunctions.DoubleGreater(PctTrailingPct, 0))
            {
                GeneratePercentTrailing(PctTrailingFloorAmt, PctTrailingPct);
            }
            if (IsSetExitOnClose)
            {
                GenerateExitOnClose();
            }
        }
 protected override void StartCalc()
 {
     criteria =
         new Lambda <Boolean>(
             _bb => (PublicFunctions.DoubleLess(Bars.High[_bb], Bars.High[(1 + _bb)]) &&
                     PublicFunctions.DoubleGreater(Bars.Low[_bb], Bars.Low[(1 + _bb)])));
 }
 protected override void CalcBar()
 {
     if (m_InitialPass &&
         ((Bars.Info.Resolution.Type.IsDayBased() &&
           Bars.Time[0].Date == PrevBarTime.Date) ||
          Bars.Time[0] == PrevBarTime))
     {
         if (IsLongOrder)
         {
             if (PublicFunctions.DoubleGreater(MyEntryPrice, OpenPriceEntryBar))
             {
                 m_StopBuy.Send(MyEntryPrice, Quantity);
             }
             else
             {
                 m_LimitBuy.Send(MyEntryPrice, Quantity);
             }
         }
         else
         {
             if (PublicFunctions.DoubleLess(MyEntryPrice, OpenPriceEntryBar))
             {
                 m_StopShort.Send(MyEntryPrice, Quantity);
             }
             else
             {
                 m_LimitShort.Send(MyEntryPrice, Quantity);
             }
         }
     }
     if (m_InitialPass && Bars.LastBarOnChart)
     {
         m_InitialPass = false;
     }
 }
 protected override void CalcBar()
 {
     if (PublicFunctions.DoubleGreater(Bars.Low[0], Bars.High[1]))
     {
         m_GapUp.Send();
     }
 }
Example #9
0
        protected override void CalcBar()
        {
            int current_position = Math.Sign(StrategyInfo.MarketPosition);

            // we arn't flat
            if (current_position != 0)
            {
                // we changed between long/short, reset count
                if (current_position != previous_position)
                {
                    count       = 0;
                    entry_price = this.EntryPrice();
                }

                if (PublicFunctions.DoubleGreater(Bars.Close[0], entry_price) && current_position == -1)
                {
                    count += 1;
                }

                if (count == NumProfitCloses)
                {
                    m_LossClsSX.Send();
                }
            }

            previous_position = current_position;
        }
 protected override void CalcBar()
 {
     m_avgexp.Value = m_xaverage1[0];
     if (((displace >= 0) ||
          Bars.CurrentBar > Math.Abs(displace)))
     {
         Plot1.Set(displace, m_avgexp.Value);
         if ((displace <= 0))
         {
             if (((PublicFunctions.DoubleGreater(price[0], m_avgexp.Value) &&
                   PublicFunctions.DoubleGreater(m_avgexp.Value, m_avgexp[1])) &&
                  PublicFunctions.DoubleLessEquals(m_avgexp[1], m_avgexp[2])))
             {
                 Alerts.Alert("Indicator turning up");
             }
             else
             {
                 if (((PublicFunctions.DoubleLess(price[0], m_avgexp.Value) &&
                       PublicFunctions.DoubleLess(m_avgexp.Value, m_avgexp[1])) &&
                      PublicFunctions.DoubleGreaterEquals(m_avgexp[1], m_avgexp[2])))
                 {
                     Alerts.Alert("Indicator turning down");
                 }
             }
         }
     }
 }
 protected override void CalcBar()
 {
     m_pctchg.Value = 100 * Bars.Close.PercentChange(length, 0);
     Plot1.Set(0, m_pctchg.Value);
     Plot2.Set(0, hialert);
     Plot3.Set(0, loalert);
     if (PublicFunctions.DoubleGreater(m_pctchg.Value, hialert))
     {
         Plot1.Colors[0] = upcolor;
     }
     else
     {
         if (PublicFunctions.DoubleLess(m_pctchg.Value, loalert))
         {
             Plot1.Colors[0] = dncolor;
         }
     }
     if (this.CrossesOver(m_pctchg, hialert))
     {
         Alerts.Alert("Bullish alert");
     }
     else
     {
         if (this.CrossesUnder(m_pctchg, loalert))
         {
             Alerts.Alert("Bearish alert");
         }
     }
 }
 protected override void CalcBar()
 {
     if (PublicFunctions.DoubleGreater(price[0], price[1]))
     {
         ++m_ups_cnt.Value;
     }
     else
     {
         m_ups_cnt.Value = 0;
     }
     if (PublicFunctions.DoubleLess(price[0], price[1]))
     {
         ++m_downs_cnt.Value;
     }
     else
     {
         m_downs_cnt.Value = 0;
     }
     if (m_ups_cnt.Value >= ConsecutiveBarsUp)
     {
         m_ConsUpLE.Send();
     }
     if (m_downs_cnt.Value >= ConsecutiveBarsDown)
     {
         m_ConsDnSE.Send();
     }
 }
 protected override void CalcBar()
 {
     m_ccivalue.Value = Bars.CCI(length);
     Plot1.Set(0, m_ccivalue.Value);
     Plot2.Set(0, overbought);
     Plot3.Set(0, oversold);
     if (PublicFunctions.DoubleGreater(m_ccivalue.Value, overbought))
     {
         Plot1.Colors[0] = overbcolor;
     }
     else
     {
         if (PublicFunctions.DoubleLess(m_ccivalue.Value, oversold))
         {
             Plot1.Colors[0] = overscolor;
         }
     }
     if (this.CrossesOver(m_ccivalue, oversold))
     {
         Alerts.Alert("Indicator exiting oversold zone");
     }
     else
     {
         if (this.CrossesUnder(m_ccivalue, overbought))
         {
             Alerts.Alert("Indicator exiting overbought zone");
         }
     }
 }
        protected override void CalcBar()
        {
            var m_formula = m_rsi1[0];

            if (Environment.IsRealTimeCalc)
            {
                if ((m_barnum.Value != Bars.CurrentBar))
                {
                    m_formulaopen.Value = m_formula;
                    m_formulahigh.Value = m_formula;
                    m_formulalow.Value  = m_formula;
                    m_barnum.Value      = Bars.CurrentBar;
                }
                if (PublicFunctions.DoubleGreater(m_formula, m_formulahigh.Value))
                {
                    m_formulahigh.Value = m_formula;
                }
                if (PublicFunctions.DoubleLess(m_formula, m_formulalow.Value))
                {
                    m_formulalow.Value = m_formula;
                }
                Plot1.Set(0, m_formulaopen.Value);
                Plot2.Set(0, m_formulahigh.Value);
                Plot3.Set(0, m_formulalow.Value);
                Plot4.Set(0, m_formula);
            }
            if (plotbaseline1)
            {
                Plot5.Set(0, baseline1);
            }
            if (plotbaseline2)
            {
                Plot6.Set(0, baseline2);
            }
        }
 protected override void CalcBar()
 {
     m_moneyflowval.Value = Bars.MoneyFlow(length);
     Plot1.Set(0, m_moneyflowval.Value);
     Plot2.Set(0, overbought);
     Plot3.Set(0, oversold);
     if (PublicFunctions.DoubleGreater(m_moneyflowval.Value, overbought))
     {
         Plot1.Colors[0] = overbcolor;
     }
     else
     {
         if (PublicFunctions.DoubleLess(m_moneyflowval.Value, oversold))
         {
             Plot1.Colors[0] = overscolor;
         }
     }
     if (((Bars.Close.LowestBar(alertlength) == 0) &&
          PublicFunctions.DoubleGreater(m_moneyflowval.LowestBar(alertlength), 0)))
     {
         Alerts.Alert("Bullish divergence - new low not confirmed");
     }
     else
     {
         if (((Bars.Close.HighestBar(alertlength) == 0) &&
              PublicFunctions.DoubleGreater(m_moneyflowval.HighestBar(alertlength), 0)))
         {
             Alerts.Alert("Bearish divergence - new high not confirmed");
         }
     }
 }
        protected override void CalcBar()
        {
            EResolution resolution = Bars.Info.Resolution.Type;

            if (resolution < EResolution.Day || EResolution.Volume == resolution ||
                EResolution.Second == resolution || resolution > EResolution.Quarter)
            {
                var m_totalticks = (Bars.UpTicks[0] + Bars.DownTicks[0]);
                if (PublicFunctions.DoubleGreater(m_totalticks, 0))
                {
                    m_volratio.Value = ((100
                                         * (Bars.UpTicks[0] - Bars.DownTicks[0]))
                                        / ((m_totalticks)));
                }
                else
                {
                    m_volratio.Value = 0;
                }
                m_volratioavg.Value = m_xaverage1[0];
                Plot1.Set(0, m_volratioavg.Value);
                Plot2.Set(0, 0);
                Plot1.Colors[0] = m_normgradientcolor1[0];
                if (this.CrossesOver(m_volratioavg, upvolalertpct))
                {
                    Alerts.Alert("UpVol alert");
                }
                else
                {
                    if (this.CrossesUnder(m_volratioavg, dnvolalertpct))
                    {
                        Alerts.Alert("DnVol alert");
                    }
                }
            }
        }
        protected override void CalcBar()
        {
            var m_fastavg = m_averagefc1[0];
            var m_medavg  = m_averagefc2[0];
            var m_slowavg = m_averagefc3[0];

            if (displace >= 0 || Bars.CurrentBar > Math.Abs(displace))
            {
                Plot1.Set(displace, m_fastavg);
                Plot2.Set(displace, m_medavg);
                Plot3.Set(displace, m_slowavg);
                if ((displace <= 0))
                {
                    m_condition1.Value = ((PublicFunctions.DoubleGreater(price[0], m_fastavg) &&
                                           PublicFunctions.DoubleGreater(m_fastavg, m_medavg)) &&
                                          PublicFunctions.DoubleGreater(m_medavg, m_slowavg));
                    if ((m_condition1.Value &&
                         (m_condition1[1] == false)))
                    {
                        Alerts.Alert("Bullish alert");
                    }
                    else
                    {
                        m_condition2.Value = ((PublicFunctions.DoubleLess(price[0], m_fastavg) &&
                                               PublicFunctions.DoubleLess(m_fastavg, m_medavg)) &&
                                              PublicFunctions.DoubleLess(m_medavg, m_slowavg));
                        if ((m_condition2.Value &&
                             (m_condition2[1] == false)))
                        {
                            Alerts.Alert("Bearish alert");
                        }
                    }
                }
            }
        }
Example #18
0
 protected override void CalcBar()
 {
     m_MP.Value = 0;
     if (StrategyInfo.MarketPosition > 0)
     {
         m_MP.Value = 1;
     }
     if (StrategyInfo.MarketPosition < 0)
     {
         m_MP.Value = -1;
     }
     if (m_MP.Value != 0)
     {
         if (m_MP[1] != m_MP.Value)
         {
             m_cnt.Value        = 0;
             m_EntryPrice.Value = this.EntryPrice();
         }
         if (PublicFunctions.DoubleGreater(Bars.Close[0], m_EntryPrice.Value) &&
             PublicFunctions.DoubleGreater(m_MP.Value, 0))
         {
             ++m_cnt.Value;
         }
         if (m_cnt.Value == NumProfitCloses)
         {
             m_PftClsLX.Send();
         }
     }
 }
Example #19
0
        protected override void CalcBar()
        {
            var m_formula2 = Bars.Close.Average(9);

            if ((Bars.LastBarOnChart && (Bars.Status != EBarState.Close)))
            {
                if (Bars.CurrentBar > m_mycurrentbar.Value)
                {
                    m_crossovers.Value   = 0;
                    m_mycurrentbar.Value = Bars.CurrentBar;
                }
                if ((PublicFunctions.DoubleGreater(formula1[0], m_formula2) && m_lastbelow.Value))
                {
                    m_crossovers.Value = (m_crossovers.Value + 1);
                    m_lastbelow.Value  = false;
                }
                else
                {
                    if (PublicFunctions.DoubleLess(formula1[0], m_formula2))
                    {
                        m_lastbelow.Value = true;
                    }
                }
                Plot1.Set(0, m_crossovers.Value);
            }
        }
 protected override void CalcBar()
 {
     m_chaikinoscval.Value = m_chaikinosc1[0];
     Plot1.Set(0, m_chaikinoscval.Value);
     Plot2.Set(0, 0);
     if ((Color.Empty != upcolor && Color.Empty != dncolor))
     {
         var m_colorlevel = m_normgradientcolor1[0];
         if ((m_applicationtype == 1))
         {
             Plot1.Colors[0] = m_colorlevel;
         }
         else
         {
             if (m_applicationtype > 1)
             {
                 Plot1.Colors[0] = gridforegroundcolor;
                 Plot1.BGColor   = m_colorlevel;
             }
         }
     }
     if (((Bars.Close.LowestBar(alertlength) == 0) &&
          PublicFunctions.DoubleGreater(m_chaikinoscval.LowestBar(alertlength), 0)))
     {
         Alerts.Alert("Bullish divergence - new low not confirmed");
     }
     else
     {
         if (((Bars.Close.HighestBar(alertlength) == 0) &&
              PublicFunctions.DoubleGreater(m_chaikinoscval.HighestBar(alertlength), 0)))
         {
             Alerts.Alert("Bearish divergence - new high not confirmed");
         }
     }
 }
Example #21
0
        protected override void CalcBar()
        {
            var m_value1 = m_pennant1[0];

            if ((m_value1 == 1))
            {
                m_color.Value = (m_color.Value == color2) ? color1 : color2;
                if (drawlines)
                {
                    var mLengthminus1 = (length - 1);
                    m_tlhi.Value =
                        DrwTrendLine.Create(new ChartPoint(Bars.Time[mLengthminus1], m_otlhistartpr.Value),
                                            new ChartPoint(Bars.Time[0], m_otlhiendpr.Value));
                    m_tlhi.Value.ExtLeft  = false;
                    m_tlhi.Value.ExtRight = false;
                    m_tlhi.Value.Color    = m_color.Value;
                    m_tllo.Value          =
                        DrwTrendLine.Create(new ChartPoint(Bars.Time[mLengthminus1], m_otllostartpr.Value),
                                            new ChartPoint(Bars.Time[0], m_otlloendpr.Value));
                    m_tllo.Value.ExtLeft  = false;
                    m_tllo.Value.ExtRight = false;
                    m_tllo.Value.Color    = m_color.Value;
                }
            }
            else
            {
                if (((m_value1 == 2) ||
                     (m_value1 == 3)))
                {
                    if (drawlines)
                    {
                        m_tlhi.Value.Size = ((2));
                        m_tllo.Value.Size = ((2));
                    }
                    if ((m_value1 == 2))
                    {
                        Plot1.Set(0, Bars.High[0]);
                    }
                    else
                    {
                        if ((m_value1 == 3))
                        {
                            Plot2.Set(0, Bars.Low[0]);
                        }
                    }
                }
            }
            if (drawextensions)
            {
                if (PublicFunctions.DoubleGreater(m_otlhiendpr.Value, 0))
                {
                    Plot3.Set(0, m_otlhiendpr.Value, m_color.Value);
                }
                if (PublicFunctions.DoubleGreater(m_otlloendpr.Value, 0))
                {
                    Plot4.Set(0, m_otlloendpr.Value, m_color.Value);
                }
            }
        }
 protected override void CalcBar()
 {
     if (PublicFunctions.DoubleGreater(Bars.High[0], Bars.High.Highest(Length, 1)) &&
         PublicFunctions.DoubleLess(Bars.Close[0], Bars.Close[1]))
     {
         m_KeyRevSE.Send();
     }
 }
 protected override void CalcBar()
 {
     if (PublicFunctions.DoubleLess(Bars.Low[0], Bars.Low.Lowest(Length, 1)) && //C<LL, buy low
         PublicFunctions.DoubleGreater(Bars.Close[0], Bars.Close[1]))     //C>C-1
     {
         m_KeyRevLE.Send();
     }
 }
Example #24
0
 protected override void CalcBar()
 {
     if (PublicFunctions.DoubleGreater(Bars.High[0], Bars.High.Highest(length, 1)))
     {
         Plot1.Set(0, Bars.High[0]);
         Alerts.Alert();
     }
 }
 protected override void CalcBar()
 {
     if ((PublicFunctions.DoubleGreater(Bars.High[0], Bars.High[1]) &&
          PublicFunctions.DoubleLess(Bars.Low[0], Bars.Low[1])))
     {
         Plot1.Set(0, Bars.Close[0]);
         Alerts.Alert();
     }
 }
Example #26
0
        protected override void CalcBar()
        {
            Ratio.Value = Bars.CloseValue / BarsOfData(2).CloseValue;
            if (Bars.CurrentBar < Length)
            {
                return;
            }
            double contracts = this.PortfolioEquity() * PercentEquity / 100;

            if (Bars.CurrentBar > 1)
            {
                if (PublicFunctions.DoubleLess(m_expAvgRatioVal + m_stdDevRatioVal, Ratio.Value))
                {
                    if (!PublicFunctions.DoubleEquals(m_cur_pos, -1))
                    {
                        m_cur_pos = -1;
                        m_short.Send((int)contracts);
                    }
                }
                else
                if (PublicFunctions.DoubleGreater(m_expAvgRatioVal - m_stdDevRatioVal, Ratio.Value))
                {
                    if (!PublicFunctions.DoubleEquals(m_cur_pos, 1))
                    {
                        m_cur_pos = 1;
                        m_long.Send((int)contracts);
                    }
                }
                else
                {
                    m_cur_pos = 0;
                    m_lx.Send();
                    m_sx.Send();
                }
            }

            m_expAvgRatioVal = m_expAvgRatio.Value;
            m_stdDevRatioVal = Ratio.StandardDeviationCustom(Length, 1);

            if (Environment.ApplicationCode == EApplicationCode.Portfolio)
            {
                int slaveIdx = this.GetFirstStrategyIndexBySymbolName(BarsOfData(2).Info.Name);
                if (slaveIdx < 0)
                {
                    ExecControl.Abort(@"specified slave trader on instrument ""{0}"" not found", BarsOfData(2).Info.Name);
                }

                double money = Math.Abs(m_cur_pos * contracts) * Bars.CloseValue * Bars.Info.BigPointValue;

                if (PublicFunctions.DoubleGreater(money, 0))
                {
                    money = this.FromSymbolToPortfolioCurrency(money);
                }

                PortfolioStrategies[slaveIdx].PortfolioData[MasterMoney] = -m_cur_pos * money;
            }
        }
Example #27
0
 protected override void CalcBar()
 {
     if (PublicFunctions.DoubleGreater(Bars.High[0], m_highesthi.Value))
     {
         Plot1.Set(0, Bars.High[0]);
         Alerts.Alert();
         m_highesthi.Value = Bars.High[0];
     }
 }
 protected override void CalcBar()
 {
     m_Stochastic.Call();
     if (Bars.CurrentBar > 2 &&
         m_oSlowK.CrossesUnder(m_oSlowD, ExecInfo.MaxBarsBack) &&
         PublicFunctions.DoubleGreater(m_oSlowK.Value, OverBought))
     {
         m_StochSE.Send();
     }
 }
 protected override void CalcBar()
 {
     if (PublicFunctions.DoubleGreater(Bars.High[0], Bars.High[1]) &&
         PublicFunctions.DoubleLess(Bars.Low[0], Bars.Low[1]))
     {
         if (PublicFunctions.DoubleLess(Bars.Close[0], Bars.Open[0]))
         {
             m_OutBarSE.Send();
         }
     }
 }
        protected override void CalcBar()
        {
            m_mom.Value = Price.Momentum(Length);
            double m_accel = m_mom.Momentum(1);

            if (PublicFunctions.DoubleGreater(m_mom.Value, 0) &&
                PublicFunctions.DoubleGreater(m_accel, 0))
            {
                m_MomLE.Send(Bars.High[0] + Bars.Point);
            }
        }