Ejemplo n.º 1
0
    public void Remake(short[] layout, int startIndex = 0)
    {
        int indexToBuild = startIndex;

        for (int i = 0; i < floors.Count; i++)
        {
            TunnelFloor floor = floors[indexToBuild];
            floor.ClearCube();

            if ((layout[i] & (short)FloorType.Bad) != 0)
            {
                floor.SetFirewall(firewallMaterial);
            }
            else
            {
                floor.SetToDefault();
            }

            if ((layout[i] & (short)FloorType.HasCube) != 0)
            {
                floor.MakeDataCube();
            }

            HelperMethods.CyclicalIncrement(ref indexToBuild, floors.Count);
        }
    }
Ejemplo n.º 2
0
    void Start()
    {
        floors = new List <TunnelFloor>();

        for (int i = 0; i < FirewallLaneManager.NUM_LANES; i++)
        {
            float   angle      = i * (360 / FirewallLaneManager.NUM_LANES);
            Vector3 spawnPoint = new Vector3(radius * Mathf.Cos(angle * Mathf.Deg2Rad),
                                             radius * Mathf.Sin(angle * Mathf.Deg2Rad),
                                             0);
            TunnelFloor newFloor = Instantiate(floorPrefab, transform);
            newFloor.transform.localPosition = spawnPoint;
            newFloor.transform.localRotation = Quaternion.Euler(0, 0, angle);
            floors.Add(newFloor);
        }

        floors[0].buffer = buffers.red;
        floors[1].buffer = buffers.red;
        floors[8].buffer = buffers.red;

        floors[2].buffer = buffers.green;
        floors[3].buffer = buffers.green;
        floors[4].buffer = buffers.green;

        floors[5].buffer = buffers.blue;
        floors[6].buffer = buffers.blue;
        floors[7].buffer = buffers.blue;

        RemakeBlank();
    }
Ejemplo n.º 3
0
 void DetermineFloorHasDataCubeRandom(TunnelFloor floor, float probability)
 {
     if (Random.Range(0f, 1f) < probability)
     {
         floor.MakeDataCube();
     }
 }
Ejemplo n.º 4
0
        internal void Initialize()
        {
            TunnelStatus = enTunnelStatus.Inactive;
            LastVolume   = tmBot.LotToVolume(tmBot.config.StartingLotSize);
            if (tmBot.config != null)
            {
                if (!tmBot.config.SessionDates.Enabled)                 // if SessionDates is not enabled
                {
                    TunnelStatus = enTunnelStatus.Pending;
                    if (tmBot.config.OpenCycleMethod == enOpenCycleMethod.AlwaysBuy || (tmBot.config.OpenCycleMethod == enOpenCycleMethod.RememberLastProfitable && LastTradeType == TradeType.Buy))
                    {
                        tmBot.ExecuteMarketOrderAsync(cAlgo.API.TradeType.Buy, tmBot.Symbol.Name, LastVolume, TMLabel + GetPositionIndexNumber() + PositionSessionNumber, InitialPositionOpened);
                    }
                    else if (tmBot.config.OpenCycleMethod == enOpenCycleMethod.AlwaysSell || (tmBot.config.OpenCycleMethod == enOpenCycleMethod.RememberLastProfitable && LastTradeType == TradeType.Sell))
                    {
                        tmBot.ExecuteMarketOrderAsync(cAlgo.API.TradeType.Sell, tmBot.Symbol.Name, LastVolume, TMLabel + GetPositionIndexNumber() + PositionSessionNumber, InitialPositionOpened);
                    }
                    else if (tmBot.config.OpenCycleMethod == enOpenCycleMethod.Trap && tmBot.Positions.Count == 0)
                    {
                        var HalfHeight = Math.Abs(tmBot.config.TunnelHeight / 2);
                        TunnelCeiling = tmBot.ShiftPrice(tmBot.Symbol.Ask, HalfHeight);
                        tmBot.Print("Tunnel Ceiling set at {0}", TunnelCeiling.ToString());
                        TunnelFloor = tmBot.ShiftPrice(tmBot.Symbol.Bid, -HalfHeight);
                        tmBot.Print("Tunnel Floor set at {0}", TunnelFloor.ToString());
                        TunnelCenter = tmBot.ShiftPrice(TunnelFloor, (int)Math.Ceiling((double)(tmBot.config.TunnelHeight / 2)));
                        tmBot.Print("Tunnel Center set at {0}", TunnelCenter.ToString());

                        TunnelChartObjects.DrawMainLines(tmBot, TunnelFloor, TunnelCeiling, TunnelCenter);
                        TunnelChartObjects.DrawMainLinesHistory(tmBot, TunnelFloor, TunnelCeiling, TunnelCenter, TMLabel + PositionSessionNumber);
                        TunnelChartObjects.DrawDirection(tmBot, Direction);

                        tmBot.PlaceStopOrderAsync(TradeType.Buy, tmBot.Symbol.Name, LastVolume, TunnelCeiling, TMLabel + GetPositionIndexNumber() + PositionSessionNumber, TrapStarted);
                        tmBot.PlaceStopOrderAsync(TradeType.Sell, tmBot.Symbol.Name, LastVolume, TunnelFloor, TMLabel + GetPositionIndexNumber() + PositionSessionNumber, TrapStarted);
                    }
                    else
                    {
                        tmBot.Print("Open Cycle Method: '{0}' is not implemented", tmBot.config.OpenCycleMethod.ToString());
                    }
                }
                else
                {
                    ParsedSessionDates = GetParsedSessionDates();
                    if (ParsedSessionDates.Count > 0)
                    {
                        tmBot.Print("Session Dates found {0} records. The next is at: {1:dd MMM yyyy HH:mm:ss}.", ParsedSessionDates.Count, ParsedSessionDates.First().ActualDate);
                    }
                    else
                    {
                        tmBot.Print("No more Session Dates.");
                    }
                }
            }
            else
            {
                throw new InvalidOperationException("Configuration is not properly loaded.");
            }
        }
Ejemplo n.º 5
0
        internal void TickCheck()
        {
            if (TunnelStatus == enTunnelStatus.Running || TunnelStatus == enTunnelStatus.PendingOrders)
            {
                //when it's a trap, and out of the validity period
                if (tmBot.config.OpenCycleMethod == enOpenCycleMethod.Trap && tmPositions.Count() == 0 && tmBot.config.Trap.Validity != TimeSpan.Zero && tmBot.TimeInUtc >= CurrentSessionDate.ActualStartDate.Add(tmBot.config.Trap.Validity).ToUniversalTime())
                {
                    tmBot.Print("Validity period is over now at: {0:dd MMM yyyy HH:mm:ss}, closing all and repeating stuff.", CurrentSessionDate.ActualStartDate.Add(tmBot.config.Trap.Validity));
                    EndTunnel();
                }
                //when using SmartBucket
                if (TunnelStatus == enTunnelStatus.Running && UsesAnySmartBucket && IsSmartBucketInCycle && JustPassedCenterTunnel)
                {
                    RetreatTunnel();
                }
                if (TunnelStatus == enTunnelStatus.Running && OnTarget)
                {
                    EndTunnel();
                }
            }
            else if (TunnelStatus == enTunnelStatus.Inactive)
            {
                if (tmBot.config.OpenCycleMethod == enOpenCycleMethod.Trap && ((UseSessionDates && IsWithinCurrentSessionTime) || (!UseSessionDates && IsTrapTime)))
                {
                    TunnelStatus   = enTunnelStatus.PendingActivation;
                    SessionNumber += 1;
                    //executing for Trap method
                    var HalfHeight = Math.Abs(TunnelHeight / 2);
                    TunnelCeiling = tmBot.ShiftPriceInPips(tmBot.Symbol.Ask, HalfHeight);
                    tmBot.Print("Tunnel Ceiling set at {0}", TunnelCeiling.ToString());
                    TunnelFloor = tmBot.ShiftPriceInPips(tmBot.Symbol.Bid, -HalfHeight);
                    tmBot.Print("Tunnel Floor set at {0}", TunnelFloor.ToString());
                    TunnelCenter = TunnelCeiling.FindCenterAgainst(TunnelFloor, tmBot.Symbol.Digits);
                    tmBot.Print("Tunnel Center set at {0}", TunnelCenter.ToString());

                    TunnelChartObjects.DrawMainLines(tmBot, TunnelFloor, TunnelCeiling, TunnelCenter);
                    TunnelChartObjects.DrawMainLinesHistory(tmBot, TunnelFloor, TunnelCeiling, TunnelCenter, TMLabel + PositionSessionNumber);
                    TunnelChartObjects.DrawDirection(tmBot, Direction);

                    LastVolume = tmBot.LotToVolume(StartingLotSize);

                    tmBot.PlaceStopOrderAsync(TradeType.Buy, tmBot.Symbol.Name, LastVolume, TunnelCeiling, TMLabel + GetPositionIndexNumber() + PositionSessionNumber, TrapStarted);
                    tmBot.PlaceStopOrderAsync(TradeType.Sell, tmBot.Symbol.Name, LastVolume, TunnelFloor, TMLabel + GetPositionIndexNumber() + PositionSessionNumber, TrapStarted);
                }
                else if (UseSessionDates && IsWithinCurrentSessionTime && tmBot.config.OpenCycleMethod != enOpenCycleMethod.Trap)
                {
                    TunnelStatus   = enTunnelStatus.PendingActivation;
                    SessionNumber += 1;
                    LastVolume     = tmBot.LotToVolume(StartingLotSize);

                    tmBot.ExecuteMarketOrderAsync(CurrentSessionDate.SessionTradeType, GetSymbolName(CurrentSessionDate), LastVolume, TMLabel + GetPositionIndexNumber() + PositionSessionNumber, InitialPositionOpened);
                }
            }
        }
Ejemplo n.º 6
0
 void DetermineFloorIsFirewallRandom(TunnelFloor floor, float probability)
 {
     if (Random.Range(0f, 1f) < probability)
     {
         floor.SetFirewall(firewallMaterial);
     }
     else
     {
         floor.SetToDefault();
     }
 }
Ejemplo n.º 7
0
        private void InitialPositionOpened(TradeResult result)
        {
            if (result.IsSuccessful)
            {
                if ((tmBot.config.SessionDates.Enabled && ParsedSessionDates.First().SessionTradeType == TradeType.Buy) || tmBot.config.OpenCycleMethod == enOpenCycleMethod.AlwaysBuy || (tmBot.config.OpenCycleMethod == enOpenCycleMethod.RememberLastProfitable && LastTradeType == TradeType.Buy))
                {
                    TunnelCeiling = result.Position.EntryPrice;
                    tmBot.Print("Tunnel Ceiling set at {0}", TunnelCeiling.ToString());
                    TunnelFloor = tmBot.ShiftPrice(TunnelCeiling, (int)tmBot.config.TunnelHeight * -1);
                    tmBot.Print("Tunnel Floor set at {0}", TunnelFloor.ToString());
                    TunnelCenter = tmBot.ShiftPrice(TunnelFloor, (int)Math.Ceiling((double)(tmBot.config.TunnelHeight / 2)));
                    tmBot.Print("Tunnel Center set at {0}", TunnelCenter.ToString());

                    TunnelChartObjects.DrawMainLines(tmBot, TunnelFloor, TunnelCeiling, TunnelCenter);
                    TunnelChartObjects.DrawDirection(tmBot, Direction);

                    LastVolume = result.Position.VolumeInUnits * tmBot.config.LotMultiplier;

                    tmBot.PlaceStopOrderAsync(TradeType.Sell, tmBot.config.SessionDates.Enabled ? GetSymbolName(ParsedSessionDates.First()) : tmBot.Symbol.Name, LastVolume, TunnelFloor, TMLabel + GetPositionIndexNumber() + PositionSessionNumber, AnotherOrderPlaced);
                }
                else if ((tmBot.config.SessionDates.Enabled && ParsedSessionDates.First().SessionTradeType == TradeType.Sell) || tmBot.config.OpenCycleMethod == enOpenCycleMethod.AlwaysSell || (tmBot.config.OpenCycleMethod == enOpenCycleMethod.RememberLastProfitable && LastTradeType == TradeType.Sell))
                {
                    TunnelFloor = result.Position.EntryPrice;
                    tmBot.Print("Tunnel Floor set at {0}", TunnelFloor.ToString());
                    TunnelCeiling = tmBot.ShiftPrice(TunnelFloor, (int)tmBot.config.TunnelHeight);
                    tmBot.Print("Tunnel Ceiling set at {0}", TunnelCeiling.ToString());
                    TunnelCenter = tmBot.ShiftPrice(TunnelFloor, (int)Math.Ceiling((double)(tmBot.config.TunnelHeight / 2)));
                    tmBot.Print("Tunnel Center set at {0}", TunnelCenter.ToString());

                    TunnelChartObjects.DrawMainLines(tmBot, TunnelFloor, TunnelCeiling, TunnelCenter);
                    TunnelChartObjects.DrawDirection(tmBot, Direction);

                    LastVolume = result.Position.VolumeInUnits * tmBot.config.LotMultiplier;

                    tmBot.PlaceStopOrderAsync(TradeType.Buy, tmBot.config.SessionDates.Enabled ? GetSymbolName(ParsedSessionDates.First()) : tmBot.Symbol.Name, LastVolume, TunnelCeiling, TMLabel + GetPositionIndexNumber() + PositionSessionNumber, AnotherOrderPlaced);
                }
                Statistics.SetMaxBounce(tmBot.Positions.Count + 1, tmBot.Time);
            }
            else
            {
                tmBot.Print("FAILED: Order failed to place at InitialPositionOpened, reason: '" + (result.Error.HasValue ? result.Error.Value.ToString() : "no valid error") + "'.");
            }
        }
Ejemplo n.º 8
0
        internal void TickCheck()
        {
            //this is when Session Dates is enabled
            if (tmBot.config.SessionDates.Enabled && ParsedSessionDates != null && TunnelStatus == enTunnelStatus.Inactive)
            {
                if (tmBot.config.OpenCycleMethod == enOpenCycleMethod.Trap)                 //for Trap
                {
                    if (ParsedSessionDates.Count > 0 && tmBot.TimeInUtc >= ParsedSessionDates.First().ActualDate.ToUniversalTime() && tmBot.TimeInUtc <= ParsedSessionDates.First().ActualDate.ToUniversalTime().Add(tmBot.config.SessionDates.Interval))
                    {
                        TunnelStatus   = enTunnelStatus.Pending;
                        SessionNumber += 1;
                        //executing for Trap method
                        var HalfHeight = Math.Abs(tmBot.config.TunnelHeight / 2);
                        TunnelCeiling = tmBot.ShiftPrice(tmBot.Symbol.Ask, HalfHeight);
                        tmBot.Print("Tunnel Ceiling set at {0}", TunnelCeiling.ToString());
                        TunnelFloor = tmBot.ShiftPrice(tmBot.Symbol.Bid, -HalfHeight);
                        tmBot.Print("Tunnel Floor set at {0}", TunnelFloor.ToString());
                        TunnelCenter = tmBot.ShiftPrice(TunnelFloor, (int)Math.Ceiling((double)(tmBot.config.TunnelHeight / 2)));
                        tmBot.Print("Tunnel Center set at {0}", TunnelCenter.ToString());

                        TunnelChartObjects.DrawMainLines(tmBot, TunnelFloor, TunnelCeiling, TunnelCenter);
                        TunnelChartObjects.DrawMainLinesHistory(tmBot, TunnelFloor, TunnelCeiling, TunnelCenter, TMLabel + PositionSessionNumber);
                        TunnelChartObjects.DrawDirection(tmBot, Direction);

                        LastVolume = tmBot.LotToVolume(tmBot.config.StartingLotSize);

                        tmBot.PlaceStopOrderAsync(TradeType.Buy, tmBot.Symbol.Name, LastVolume, TunnelCeiling, TMLabel + GetPositionIndexNumber() + PositionSessionNumber, TrapStarted);
                        tmBot.PlaceStopOrderAsync(TradeType.Sell, tmBot.Symbol.Name, LastVolume, TunnelFloor, TMLabel + GetPositionIndexNumber() + PositionSessionNumber, TrapStarted);
                    }
                }
                else
                {
                    if (ParsedSessionDates.Count > 0 && tmBot.TimeInUtc >= ParsedSessionDates.First().ActualDate.ToUniversalTime() && tmBot.TimeInUtc <= ParsedSessionDates.First().ActualDate.ToUniversalTime().Add(tmBot.config.SessionDates.Interval))
                    {
                        TunnelStatus   = enTunnelStatus.Pending;
                        SessionNumber += 1;
                        LastVolume     = tmBot.LotToVolume(tmBot.config.StartingLotSize);

                        tmBot.ExecuteMarketOrderAsync(ParsedSessionDates.First().SessionTradeType, GetSymbolName(ParsedSessionDates.First()), LastVolume, TMLabel + GetPositionIndexNumber() + PositionSessionNumber, InitialPositionOpened);
                    }
                }
            }

            if (tmBot.config.RunningCycleMethod == enRunningCycleMethod.NormalSmartBucket && JustPassedCenterTunnel)
            {
                RetreatTunnel();
            }

            if (OnTarget)
            {
                EndTunnel();
                Initialize();

                /*
                 * var lastTrans = (GetLatestTransDate() - tmBot.TimeInUtc);
                 *
                 * if (lastTrans.TotalDays >= 1 || (lastTrans.TotalDays < 1 && GetLatestTransDate().DayOfWeek != tmBot.TimeInUtc.DayOfWeek)) {
                 * }
                 */
            }
        }
Ejemplo n.º 9
0
        internal void Initialize()
        {
            tmBot.Print("»»»»»»»» Initializing...");
            TunnelStatus = enTunnelStatus.Inactive;
            LastVolume   = tmBot.LotToVolume(StartingLotSize);
            if (tmBot.config != null)
            {
                if (!tmBot.config.SessionDates.Enabled)                 // if SessionDates is not enabled
                {
                    TunnelStatus = enTunnelStatus.PendingActivation;
                    if (tmBot.config.OpenCycleMethod == enOpenCycleMethod.AlwaysBuy || (tmBot.config.OpenCycleMethod == enOpenCycleMethod.RememberLastProfitable && LastTradeType == TradeType.Buy))
                    {
                        tmBot.ExecuteMarketOrderAsync(TradeType.Buy, tmBot.Symbol.Name, LastVolume, TMLabel + GetPositionIndexNumber() + PositionSessionNumber, InitialPositionOpened);
                    }
                    else if (tmBot.config.OpenCycleMethod == enOpenCycleMethod.AlwaysSell || (tmBot.config.OpenCycleMethod == enOpenCycleMethod.RememberLastProfitable && LastTradeType == TradeType.Sell))
                    {
                        tmBot.ExecuteMarketOrderAsync(TradeType.Sell, tmBot.Symbol.Name, LastVolume, TMLabel + GetPositionIndexNumber() + PositionSessionNumber, InitialPositionOpened);
                    }
                    else if (tmBot.config.OpenCycleMethod == enOpenCycleMethod.Trap)
                    {
                        if (tmPositions.Count() == 0 && IsTrapTime)
                        {
                            int HalfHeight = Math.Abs(TunnelHeight / 2);
                            TunnelCeiling = tmBot.ShiftPriceInPips(tmBot.Symbol.Ask, HalfHeight);
                            tmBot.Print("Tunnel Ceiling set at {0}", TunnelCeiling.ToString());
                            TunnelFloor = tmBot.ShiftPriceInPips(tmBot.Symbol.Bid, -HalfHeight);
                            tmBot.Print("Tunnel Floor set at {0}", TunnelFloor.ToString());

                            TunnelCenter = TunnelCeiling.FindCenterAgainst(TunnelFloor, tmBot.Symbol.Digits);
                            tmBot.Print("Tunnel Center set at {0}", TunnelCenter.ToString());

                            TunnelChartObjects.DrawMainLines(tmBot, TunnelFloor, TunnelCeiling, TunnelCenter);
                            TunnelChartObjects.DrawMainLinesHistory(tmBot, TunnelFloor, TunnelCeiling, TunnelCenter, TMLabel + PositionSessionNumber);
                            TunnelChartObjects.DrawDirection(tmBot, Direction);

                            tmBot.PlaceStopOrderAsync(TradeType.Buy, tmBot.Symbol.Name, LastVolume, TunnelCeiling, TMLabel + GetPositionIndexNumber() + PositionSessionNumber, TrapStarted);
                            tmBot.PlaceStopOrderAsync(TradeType.Sell, tmBot.Symbol.Name, LastVolume, TunnelFloor, TMLabel + GetPositionIndexNumber() + PositionSessionNumber, TrapStarted);
                        }
                        else
                        {
                            tmBot.Print("BollingerBandsDistance: {0}", BollingerBandsDistance);
                            TunnelStatus = enTunnelStatus.Inactive;
                        }
                    }
                    else
                    {
                        tmBot.Print("Open Cycle Method: '{0}' is not implemented", tmBot.config.OpenCycleMethod.ToString());
                        TunnelStatus = enTunnelStatus.Inactive;
                    }
                }
                else
                {
                    // if SessionDates is enabled
                    ParsedSessionDates = GetParsedSessionDates();
                    CurrentSessionDate = UseSessionDates ? ParsedSessionDates.First() : null;

                    if (ParsedSessionDates.Count > 0)
                    {
                        tmBot.Print("Session Dates found {0} records. The next is at: {1:dd MMM yyyy HH:mm:ss}.", ParsedSessionDates.Count, CurrentSessionDate.ActualStartDate);
                    }
                    else
                    {
                        tmBot.Print("No more Session Dates.");
                    }
                }
            }
            else
            {
                throw new InvalidOperationException("Configuration is not properly loaded.");
            }
        }