Beispiel #1
0
        public void BuildStatsOnBacktestFinished(List <Position> positionsMaster)
        {
            //// Dictionary<U,V> has no .AsReadonly() (List<T> has it)
            //var positionsMasterByEntryBarSafeCopy = this.Executor.ExecutionDataSnapshot.PositionsMasterByEntryBar;
            //var positionsMasterByExitBarSafeCopy = this.Executor.ExecutionDataSnapshot.PositionsMasterByExitBar;

            //this.DEBUGGING_PositionsMaster = positionsMaster;
            //this.DEBUGGING_PositionsMasterByEntryBarSafeCopy = positionsMasterByEntryBarSafeCopy;
            //this.DEBUGGING_PositionsMasterByExitBarSafeCopy = positionsMasterByExitBarSafeCopy;

            //this.SliceLong.BuildStatsOnBacktestFinished(positionsMasterByEntryBarSafeCopy, positionsMasterByExitBarSafeCopy);
            //this.SliceShort.BuildStatsOnBacktestFinished(positionsMasterByEntryBarSafeCopy, positionsMasterByExitBarSafeCopy);
            //this.SlicesShortAndLong.BuildStatsOnBacktestFinished(positionsMasterByEntryBarSafeCopy, positionsMasterByExitBarSafeCopy);
            //this.SliceBuyHold.BuildStatsOnBacktestFinished(positionsMasterByEntryBarSafeCopy, positionsMasterByExitBarSafeCopy);

            ReporterPokeUnit pokeUnit = new ReporterPokeUnit(null);

            List <Position> positionsClosed = new List <Position>(this.Executor.ExecutionDataSnapshot.PositionsMaster);

            foreach (Position posOpen in this.Executor.ExecutionDataSnapshot.PositionsOpenNow)
            {
                if (positionsClosed.Contains(posOpen) == false)
                {
#if DEBUG
                    Debugger.Break();
#endif
                    continue;
                }
                positionsClosed.Remove(posOpen);
            }
            pokeUnit.PositionsOpened = this.Executor.ExecutionDataSnapshot.PositionsOpenNow;
            pokeUnit.PositionsClosed = positionsClosed;
            this.BuildStatsIncrementallyOnEachBarExecFinished(pokeUnit);
        }
Beispiel #2
0
 public void BuildStatsIncrementallyOnEachBarExecFinished(ReporterPokeUnit pokeUnit)
 {
     Dictionary <int, List <Position> > posByEntry = pokeUnit.PositionsOpenedByBarFilled;
     Dictionary <int, List <Position> > posByExit  = pokeUnit.PositionsClosedByBarFilled;
     int absorbedLong  = this.SliceLong.BuildStatsIncrementallyOnEachBarExecFinished(posByEntry, posByExit);
     int absorbedShort = this.SliceShort.BuildStatsIncrementallyOnEachBarExecFinished(posByEntry, posByExit);
     int absorbedBoth  = this.SlicesShortAndLong.BuildStatsIncrementallyOnEachBarExecFinished(posByEntry, posByExit);
     int absorbedBH    = this.SliceBuyHold.BuildStatsIncrementallyOnEachBarExecFinished(posByEntry, posByExit);
 }
Beispiel #3
0
 public void BuildIncrementalAllReports(ReporterPokeUnit pokeUnit)
 {
     if (this.ChartFormManager.ChartForm.InvokeRequired)
     {
         this.ChartFormManager.ChartForm.BeginInvoke((MethodInvoker) delegate { this.BuildIncrementalAllReports(pokeUnit); });
         return;
     }
     foreach (Reporter rep in this.ReporterShortNamesUserInvoked.Values)
     {
         rep.BuildIncrementalAfterPositionsChangedInRealTime(pokeUnit);
     }
 }
        public void PositionArrowsRealtimeAdd(ReporterPokeUnit pokeUnit)
        {
            this.PositionArrowsBacktestAdd(pokeUnit.PositionsOpened);
            this.PositionArrowsBacktestAdd(pokeUnit.PositionsClosed);
//		NO_NEED_TO_CACHE_OPENING_ALERT_BITMAP_FOR_JUST_CLOSED_POSITIONS AlertArrow.Bitmap is dynamic for EntryAlerts until the position is closed;
//			foreach (AlertArrow eachNewClosed in pokeUnit.PositionsClosed) {
//				if (this.AlertArrowsListByBar.ContainsKey[eachNewClosed.EntryBarIndex] == false) {
//
//				}
//				List<AlertArrow> alertArrowsSameBarEntry = this.AlertArrowsListByBar[eachNewClosed.EntryBarIndex];
//				foreach (AlertArrow eachArrowToResetBitmap in alertArrowsSameBarEntry) {
//					if (eachArrowToResetBitmap.AlertArrow != eachNewClosed) return;
//					eachArrowToResetBitmap.BitmapResetDueToPositionClose;
//				}
//			}
        }
        public void PendingRealtimeAdd(ReporterPokeUnit pokeUnit)
        {
            Debugger.Break();                   //should I NOT assign this.AlertsPendingHistorySafeCopy=alertsPendingHistorySafeCopy;?
            if (null == pokeUnit.QuoteGeneratedThisUnit)
            {
                Debugger.Break();
                return;
            }
            if (null == pokeUnit.QuoteGeneratedThisUnit.ParentStreamingBar)
            {
                Debugger.Break();
                return;
            }
            int barIndex = pokeUnit.QuoteGeneratedThisUnit.ParentStreamingBar.ParentBarsIndex;

            this.AlertsPendingHistorySafeCopy.Add(barIndex, pokeUnit.AlertsNew);
        }
        public void ConsumeQuoteOfStreamingBar(Quote quote)
        {
            //Bar barLastFormed = quoteToReach.ParentStreamingBar;
            ExecutionDataSnapshot snap = this.backtester.Executor.ExecutionDataSnapshot;

            foreach (Indicator indicator in snap.Indicators.Values)
            {
                try {
                    indicator.OnNewStreamingQuote(quote);
                } catch (Exception ex) {
                    Debugger.Break();
                }
            }

            if (snap.AlertsPending.Count > 0)
            {
                var dumped = snap.DumpPendingAlertsIntoPendingHistoryByBar();
                if (dumped > 0)
                {
                    //string msg = "here is at least one reason why dumping on fresh quoteToReach makes sense"
                    //    + " if we never reach this breakpoint the remove dump() from here"
                    //    + " but I don't see a need to invoke it since we dumped pendings already after OnNewBarCallback";
                    string msg = "DUMPED_BEFORE_SCRIPT_EXECUTION_ON_NEW_BAR_OR_QUOTE";
                }
                int pendingCountPre = this.backtester.Executor.ExecutionDataSnapshot.AlertsPending.Count;
                int pendingFilled   = this.backtester.Executor.MarketSimStreaming.SimulatePendingFill(quote);
                int pendingCountNow = this.backtester.Executor.ExecutionDataSnapshot.AlertsPending.Count;
                if (pendingCountNow != pendingCountPre - pendingFilled)
                {
                    string msg = "NOT_ONLY it looks like AnnihilateCounterparty worked out!";
                }
                if (pendingCountNow > 0)
                {
                    string msg = "pending=[" + pendingCountNow + "], it must be prototype-induced 2 closing TP & SL";
                }
            }
            //this.backtester.Executor.Script.OnNewQuoteCallback(quoteToReach);
            ReporterPokeUnit pokeUnit = this.backtester.Executor.ExecuteOnNewBarOrNewQuote(quote);
        }
Beispiel #7
0
        public int InvokeOnceHooksForOrderStateAndDelete(Order order, ReporterPokeUnit pokeUnit)
        {
            int hooksInvoked = 0;

            lock (this.hooksLock) {
                foreach (OrderPostProcessorStateHook hook in this.hooks)
                {
                    string msg = "processing hook [" + hook + "] ";
                    if (hook.InvokedThusCanBeDeleted)
                    {
                        continue;
                    }
                    if (hook.Order != order)
                    {
                        continue;
                    }
                    if (hook.OrderState != order.State)
                    {
                        continue;
                    }

                    hook.CurrentlyExecuting = true;
                    hook.Delegate(order, pokeUnit);
                    hook.CurrentlyExecuting      = false;
                    hook.InvokedThusCanBeDeleted = true;
                    msg += " ... done";

                    hooksInvoked++;
                }
                int hooksRemoved = this.RemoveAllInvoked();
                if (hooksRemoved != hooksInvoked)
                {
                    string msg = "hooksRemoved[" + hooksRemoved + "] != hooksInvoked[" + hooksInvoked + "]; I don't wanna be stuck on threading issues...";
                    throw new Exception(msg);
                }
            }
            return(hooksInvoked);
        }
 public void PositionsRealtimeAdd(ReporterPokeUnit pokeUnit)
 {
     if (pokeUnit.PositionsOpened != null && pokeUnit.PositionsOpened.Count > 0)
     {
         lock (lockPositionsOpened) {
             if (this.PositionsOpenedCloneCanBeZeriofiedAfterPickup == null)
             {
                 this.PositionsOpenedCloneCanBeZeriofiedAfterPickup = new List <Position>();
             }
             foreach (Position eachNewOpened in pokeUnit.PositionsOpened)
             {
                 if (this.PositionsOpenedCloneCanBeZeriofiedAfterPickup.Contains(eachNewOpened))
                 {
                     continue;
                 }
                 this.PositionsOpenedCloneCanBeZeriofiedAfterPickup.Add(eachNewOpened);
             }
         }
     }
     if (pokeUnit.PositionsClosed != null && pokeUnit.PositionsClosed.Count > 0)
     {
         lock (lockPositionsClosed) {
             if (this.PositionsClosedCloneCanBeZeriofiedAfterPickup == null)
             {
                 this.PositionsClosedCloneCanBeZeriofiedAfterPickup = new List <Position>();
             }
             foreach (Position eachNewClosed in pokeUnit.PositionsClosed)
             {
                 if (this.PositionsClosedCloneCanBeZeriofiedAfterPickup.Contains(eachNewClosed))
                 {
                     continue;
                 }
                 this.PositionsClosedCloneCanBeZeriofiedAfterPickup.Add(eachNewClosed);
             }
         }
     }
 }
Beispiel #9
0
 public override void BuildIncrementalAfterPositionsChangedInRealTime(ReporterPokeUnit pokeUnit)
 {
 }
Beispiel #10
0
 public override void BuildIncrementalAfterPositionsChangedInRealTime(ReporterPokeUnit pokeUnit)
 {
     Debugger.Break();
     this.reversePositionsCalcCumulativesDumpToTitleAndOLV();
 }
Beispiel #11
0
        public virtual void BuildIncrementalAfterPositionsChangedInRealTime(ReporterPokeUnit pokeUnit)
        {
            string msg = "DERIVED_REPORTERS_MUST_IMPLEMENT BuildIncrementalAfterPositionsChangedInRealTime(ReporterPokeUnit)" + this.TabText + "/" + this.GetType();

            throw new NotImplementedException(msg);
        }
Beispiel #12
0
 public virtual void PendingRealtimeAdd(ReporterPokeUnit pokeUnit)
 {
     throw new NotImplementedException();
 }
Beispiel #13
0
 public override void PendingRealtimeAdd(ReporterPokeUnit pokeUnit)
 {
     this.ScriptExecutorObjects.PendingRealtimeAdd(pokeUnit);
 }
Beispiel #14
0
 public override void PositionsRealtimeAdd(ReporterPokeUnit pokeUnit)
 {
     this.ScriptExecutorObjects.PositionArrowsRealtimeAdd(pokeUnit);
 }