Пример #1
0
 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()
        {
            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.DoubleLess(Bars.Close[0], entry_price) && current_position == 1)
                {
                    count += 1;
                }

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

            previous_position = current_position;
        }
 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.DoubleLess(Bars.Close[0], m_EntryPrice.Value) &&
             PublicFunctions.DoubleLess(m_MP.Value, 0))
         {
             ++m_cnt.Value;
         }
         if (m_cnt.Value == NumProfitCloses)
         {
             m_PftClsSX.Send();
         }
     }
 }
Пример #4
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);
            }
        }
 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_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");
                        }
                    }
                }
            }
        }
Пример #8
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()
 {
     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;
     }
 }
Пример #10
0
        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);
            }
        }
Пример #11
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()
 {
     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 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()
 {
     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()
 {
     if (PublicFunctions.DoubleLess(Bars.High[0], Bars.Low[1]))   //H <L-1
     {
         m_GapDn.Send();
     }
 }
        protected override void CalcBar()
        {
            double m_avg   = m_AverageFC[0];
            double m_shift = NumAtrs * this.AverageTrueRange(Length);

            m_UpperBand.Value = m_avg + m_shift;   //UB


            if (Bars.CurrentBar > 1 && Price.CrossesOver(m_UpperBand, ExecInfo.MaxBarsBack)) //CROSS(C,HB);
            {
                m_bSetupLE.Value     = true;
                m_CrossingHigh.Value = Bars.High[0];  //HH
            }
            else
            {
                if (m_bSetupLE.Value &&
                    (PublicFunctions.DoubleLess(Price[0], m_avg) ||   //C<MA
                     PublicFunctions.DoubleGreaterEquals(Bars.High[0], m_CrossingHigh.Value + Bars.Point)))
                {
                    m_bSetupLE.Value = false;
                }
            }
            if (m_bSetupLE.Value)
            {
                m_KltChLE.Send(m_CrossingHigh.Value + Bars.Point);
            }
        }
 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();
     }
 }
 protected override void CalcBar()
 {
     if (PublicFunctions.DoubleLess(Bars.Low[0], Bars.Low.Lowest(length, 1)))
     {
         Plot1.Set(0, Bars.Low[0]);
         Alerts.Alert();
     }
 }
 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();
     }
 }
Пример #20
0
 protected override void CalcBar()
 {
     if (PublicFunctions.DoubleLess(Bars.Low[0], m_lowestlo))
     {
         Plot1.Set(0, Bars.Low[0]);
         Alerts.Alert();
         m_lowestlo = Bars.Low[0];
     }
 }
Пример #21
0
 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();
     }
 }
Пример #22
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;
            }
        }
Пример #23
0
 protected override void CalcBar()
 {
     if (tlRef != null && tlRef.Exist)
     {
         if (Bars.Time[0] >= m_BeginTime && PublicFunctions.DoubleLess(Bars.High[0], tlRef.PriceValue(Bars.Time[0])))
         {
             m_BuyOrder.Send(tlRef.PriceValue(Bars.TimeNextBar()));
         }
     }
 }
 protected override void CalcBar()
 {
     m_Stochastic.Call();
     if (Bars.CurrentBar > 2 &&
         m_oSlowK.CrossesOver(m_oSlowD, ExecInfo.MaxBarsBack) &&
         PublicFunctions.DoubleLess(m_oSlowK.Value, OverSold))
     {
         m_StochLE.Send();
     }
 }
Пример #25
0
 protected override void CalcBar()
 {
     if (PublicFunctions.DoubleLess(Bars.High[0], Bars.High[1]) &&       // H<H-1
         PublicFunctions.DoubleGreater(Bars.Low[0], Bars.Low[1]))        //L>L-1
     {
         if (PublicFunctions.DoubleGreater(Bars.Close[0], Bars.Open[0])) //C>O
         {
             m_InsBarLE.Send();
         }
     }
 }
Пример #26
0
 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.DoubleLess(m_mom.Value, 0) &&
                PublicFunctions.DoubleLess(m_accel, 0))
            {
                m_MomSE.Send(Bars.Low[0] - Bars.Point);
            }
        }
Пример #28
0
 protected override void CalcBar()
 {
     if (PublicFunctions.DoubleLess(Bars.High[0], Bars.Low[1]))
     {
         Plot1.Set(0, Bars.Low[0]);
         Alerts.Alert();
     }
     else
     {
         Plot1.Reset();
     }
 }
Пример #29
0
 protected override void CalcBar()
 {
     if (PublicFunctions.DoubleLess(price[0], m_averagefc1[0]))
     {
         Plot1.Set(0, Bars.High[0]);
         Plot2.Set(0, Bars.Low[0]);
         Alerts.Alert();
     }
     else
     {
         Plot1.Reset();
     }
 }
 protected override void CalcBar()
 {
     if ((PublicFunctions.DoubleLess(Bars.Low[0], Bars.Low.Lowest(length, 1)) &&
          PublicFunctions.DoubleGreater(Bars.Close[0], Bars.Close[1])))
     {
         Plot1.Set(0, Bars.Low[0]);
         Alerts.Alert();
     }
     else
     {
         Plot1.Reset();
     }
 }