Example #1
0
 void ProcessBar(ZCandlestick bar, bool displayIndicator, bool displayDebug)
 {
     if (m_bars.ContainsKey(bar.time))   // this is a bar that is already in our list (should be an update of the last/latest bar)
     {
         var lastBar = m_bars.Last().Value;
         if (bar.time == lastBar.time)
         {
             m_bars[bar.time] = bar;
             if (displayDebug)
             {
                 cout("{0}> update the LAST (latest) bar in our list: {1}", m_pair, bar.ToString());
             }
             m_macdLive.UpdateLastTick((double)lastBar.close);
             CheckIndicator(m_macdLive, false, displayIndicator);
         }
     }
     else    // otherwise, add this NEW bar to our list AND update the indicator with the previous last bar in our list
     {
         if (m_bars.Count > 0)
         {
             var lastBar = m_bars.Last().Value;
             if (displayDebug)
             {
                 cout("{0}> updating indicator with LAST bar in our list: {1}", m_pair, lastBar.ToString());
             }
             m_macd.ReceiveTick((double)lastBar.close);
             CheckIndicator(m_macd, true, displayIndicator);
         }
         m_macdLive.ReceiveTick((double)bar.close);
         CheckIndicator(m_macdLive, false, displayIndicator);
         m_bars.Add(bar.time, bar);
         if (displayDebug)
         {
             cout("{0}> added to bar list: {1}", m_pair, bar.ToString());
         }
     }
 }
        void ProcessBar(ZCandlestick bar, bool displayIndicator)
        {
            int indicator = 0;

            if (m_bars.ContainsKey(bar.time))   // this is a bar that is already in our list (should be an update of the last/latest bar)
            {
                var lastBar = m_bars.Last().Value;
                if (bar.time == lastBar.time)
                {
                    m_bars[bar.time] = bar;
                    if (m_displayDebug)
                    {
                        cout("{0}> update the 'real-time' indicator LAST (latest) bar in our list: {1}", PairId, bar.ToString());
                    }
                    m_macdLive.UpdateLastTick((double)lastBar.close);
                    indicator = CheckIndicator(m_macdLive, displayIndicator);
                    // not a completed bar, so do NOT execute a trade
                }
            }
            else    // otherwise, add this NEW bar to our list AND update the indicator with the previous last bar in our list
            {
                if (m_bars.Count > 0)
                {
                    var lastBar = m_bars.Last().Value;
                    if (m_displayDebug)
                    {
                        cout("{0}> update the 'bar-complete' indicator with LAST COMPLETE bar in our list: {1}", PairId, lastBar.ToString());
                    }
                    m_macd.ReceiveTick((double)lastBar.close);
                    indicator = CheckIndicator(m_macd, displayIndicator);
                    // this IS a complete bar, so make a trade
                    if (indicator == -1)                                // indicator = SHORT
                    {
                        if (m_pos > 0)                                  // CHECK TO SEE IF WE CROSSED positive-to-negative
                        {
                            TradeSell(lastBar.time.ToDateTimeString(), lastBar.close);
                        }
                        else if (m_pos == 0)                            // if no position, then set our initial pos (DON'T trade)
                        {
                            m_pos = -1;
                        }
                    }
                    else if (indicator == +1)                           // indicator = LONG
                    {
                        if (m_pos < 0)                                  // CHECK TO SEE IF WE CROSSED positive-to-negative
                        {
                            TradeBuy(lastBar.time.ToDateTimeString(), lastBar.close);
                        }
                        else if (m_pos == 0)                            // if no position, then set our initial pos (DON'T trade)
                        {
                            m_pos = +1;
                        }
                    }
                }
                m_macdLive.ReceiveTick((double)bar.close);
                indicator = CheckIndicator(m_macdLive, displayIndicator);
                // not a completed bar, so do NOT execute a trade
                m_bars.Add(bar.time, bar);
                if (m_displayDebug)
                {
                    cout("{0}> added to bar list: {1}", m_pair, bar.ToString());
                }
            }
        }