protected TradeAction EvalExpensiveCheap(CMarket market, TradeAction result)
        {
            if (result != TradeAction.Hold)
            {
                //var currentTrend = Trend();

                // sistema di sicurezza da testare
                decimal securitylimit = MainConfiguration.Configuration.SecurityLimit;

                // la velocità serve a modificare il limite per cui si valuta se un rezzo è expensive o cheap
                var speed = Math.Abs(this.CurrentMacdValue); //Math.Abs(Values.Derivative.CurrentSpeed);

                var gap = (LogTrade.BuyAt - market.Buy) / (1 + speed);
                if (result == TradeAction.Buy && market.Buy + gap >= securitylimit * LogTrade.BuyAt && LogTrade.BuyAt > 0 &&
                    this.CurrentTrend == TechnicalAnalysis.Trend.Raise)
                {
                    //LogTrade.Note += " expensive ";
                    //AnalyticsTools.Call("expensive");
                    return(TradeAction.Hold);
                }

                gap = (LogTrade.SellAt - market.Sell) / (1 + speed);
                if (result == TradeAction.Sell && market.Sell + gap <= securitylimit * LogTrade.SellAt &&
                    LogTrade.SellAt > 0 &&
                    this.CurrentTrend == TechnicalAnalysis.Trend.Fall)
                {
                    //LogTrade.Note += " cheap ";
                    //AnalyticsTools.Call("cheap");
                    return(TradeAction.Hold);
                }
            }
            return(result);
        }
Пример #2
0
        public void TestMarket()
        {
            string resp = " { \"id\":3230605824,\"name\":\"Dunbar Ring\",\"outpostType\":\"starport\",\"imported\":{ \"128049197\":\"Polymers\",\"128049199\":\"Semiconductors\",\"128049175\":\"Copper\",\"128049190\":\"Leather\",\"128672302\":\"CeramicComposites\",\"128673850\":\"HydrogenPeroxide\",\"128049172\":\"Uranium\",\"128049193\":\"SyntheticFabrics\",\"128049176\":\"Aluminium\",\"128049171\":\"Tantalum\",\"128673851\":\"LiquidOxygen\",\"128049170\":\"Gallium\",\"128049173\":\"Lithium\",\"128049226\":\"HazardousEnvironmentSuits\",\"128049191\":\"NaturalFabrics\",\"128049177\":\"Algae\",\"128049174\":\"Titanium\",\"128682044\":\"ConductiveFabrics\",\"128671118\":\"Osmium\",\"128049154\":\"Gold\",\"128673857\":\"CoolingHoses\",\"128049166\":\"Water\",\"128049162\":\"Cobalt\",\"128049153\":\"Palladium\",\"128049180\":\"Grain\",\"128049200\":\"Superconductors\",\"128049214\":\"Beer\",\"128673847\":\"Samarium\",\"128673845\":\"Praseodymium\",\"128049227\":\"Robotics\",\"128049215\":\"Wine\",\"128049169\":\"Indium\",\"128049183\":\"Fish\",\"128673856\":\"CMMComposite\",\"128049168\":\"Beryllium\",\"128049155\":\"Silver\",\"128049228\":\"AutoFabricators\",\"128673855\":\"InsulatingMembrane\",\"128673866\":\"ExhaustManifold\",\"128682046\":\"AdvancedMedicines\",\"128049182\":\"Animalmeat\",\"128673861\":\"EmergencyPowerCells\",\"128049188\":\"Tea\",\"128049178\":\"FruitAndVegetables\",\"128673873\":\"MicroControllers\",\"128049185\":\"SyntheticMeat\",\"128049240\":\"ConsumerTechnology\",\"128049152\":\"Platinum\",\"128049669\":\"ProgenitorCells\",\"128049189\":\"Coffee\",\"128673848\":\"LowTemperatureDiamond\",\"128049209\":\"PerformanceEnhancers\",\"128049235\":\"ReactiveArmour\",\"128049236\":\"NonLethalWeapons\",\"128668550\":\"Painite\",\"128672306\":\"BootlegLiquor\"},\"exported\":{ \"128049217\":\"PowerGenerators\",\"128049223\":\"MarineSupplies\",\"128672307\":\"GeologicalEquipment\",\"128049202\":\"HydrogenFuel\",\"128049221\":\"MineralExtractors\",\"128049248\":\"Scrap\",\"128049241\":\"Clothing\",\"128064028\":\"AtmosphericExtractors\",\"128673860\":\"HNShockMount\",\"128049238\":\"DomesticAppliances\",\"128066403\":\"Drones\",\"128049222\":\"CropHarvesters\",\"128049184\":\"FoodCartridges\",\"128049218\":\"WaterPurifiers\",\"128672308\":\"ThermalCoolingUnits\",\"128049210\":\"BasicMedicines\",\"128049244\":\"Biowaste\",\"128672309\":\"BuildingFabricators\",\"128672313\":\"SkimerComponents\",\"128049225\":\"ComputerComponents\",\"128682048\":\"SurvivalEquipment\",\"128049233\":\"PersonalWeapons\",\"128049216\":\"Liquor\"},\"services\":{ \"dock\":\"ok\",\"contacts\":\"ok\",\"exploration\":\"ok\",\"commodities\":\"ok\",\"refuel\":\"ok\",\"repair\":\"ok\",\"rearm\":\"ok\",\"outfitting\":\"ok\",\"shipyard\":\"ok\",\"crewlounge\":\"ok\",\"powerplay\":\"ok\",\"searchrescue\":\"ok\"},\"economies\":{ \"36\":{ \"name\":\"Industrial\",\"proportion\":1} },\"prohibited\":{ \"128049670\":\"CombatStabilisers\",\"128049212\":\"BasicNarcotics\",\"128049213\":\"Tobacco\",\"128049234\":\"BattleWeapons\",\"128667728\":\"ImperialSlaves\",\"128049243\":\"Slaves\",\"128049245\":\"ToxicWaste\"},\"commodities\":[{\"id\":128049202,\"name\":\"HydrogenFuel\",\"legality\":\"\",\"buyPrice\":113,\"sellPrice\":108,\"meanPrice\":110,\"demandBracket\":0,\"stockBracket\":1,\"stock\":150631,\"demand\":1,\"statusFlags\":[],\"categoryname\":\"Chemicals\",\"locName\":\"Hydrogen Fuel\"},{\"id\":128673850,\"name\":\"HydrogenPeroxide\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":782,\"meanPrice\":917,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":1997893,\"statusFlags\":[],\"categoryname\":\"Chemicals\",\"locName\":\"Hydrogen Peroxide\"},{\"id\":128673851,\"name\":\"LiquidOxygen\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":200,\"meanPrice\":263,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":1109553,\"statusFlags\":[],\"categoryname\":\"Chemicals\",\"locName\":\"Liquid oxygen\"},{\"id\":128049166,\"name\":\"Water\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":145,\"meanPrice\":120,\"demandBracket\":2,\"stockBracket\":0,\"stock\":0,\"demand\":233842,\"statusFlags\":[],\"categoryname\":\"Chemicals\",\"locName\":\"Water\"},{\"id\":128049241,\"name\":\"Clothing\",\"legality\":\"\",\"buyPrice\":215,\"sellPrice\":198,\"meanPrice\":286,\"demandBracket\":0,\"stockBracket\":1,\"stock\":59200,\"demand\":1,\"statusFlags\":[],\"categoryname\":\"Consumer Items\",\"locName\":\"Clothing\"},{\"id\":128049240,\"name\":\"ConsumerTechnology\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":7066,\"meanPrice\":6766,\"demandBracket\":2,\"stockBracket\":0,\"stock\":0,\"demand\":17720,\"statusFlags\":[],\"categoryname\":\"Consumer Items\",\"locName\":\"Consumer Technology\"},{\"id\":128049238,\"name\":\"DomesticAppliances\",\"legality\":\"\",\"buyPrice\":441,\"sellPrice\":418,\"meanPrice\":488,\"demandBracket\":0,\"stockBracket\":1,\"stock\":35349,\"demand\":1,\"statusFlags\":[],\"categoryname\":\"Consumer Items\",\"locName\":\"Domestic Appliances\"},{\"id\":128682048,\"name\":\"SurvivalEquipment\",\"legality\":\"\",\"buyPrice\":377,\"sellPrice\":357,\"meanPrice\":486,\"demandBracket\":0,\"stockBracket\":2,\"stock\":3625,\"demand\":1,\"statusFlags\":[],\"categoryname\":\"Consumer Items\",\"locName\":\"Survival Equipment\"},{\"id\":128049177,\"name\":\"Algae\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":233,\"meanPrice\":137,\"demandBracket\":2,\"stockBracket\":0,\"stock\":0,\"demand\":458745,\"statusFlags\":[],\"categoryname\":\"Foods\",\"locName\":\"Algae\"},{\"id\":128049182,\"name\":\"Animalmeat\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":1515,\"meanPrice\":1293,\"demandBracket\":2,\"stockBracket\":0,\"stock\":0,\"demand\":35316,\"statusFlags\":[],\"categoryname\":\"Foods\",\"locName\":\"Animal Meat\"},{\"id\":128049189,\"name\":\"Coffee\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":1515,\"meanPrice\":1280,\"demandBracket\":2,\"stockBracket\":0,\"stock\":0,\"demand\":8829,\"statusFlags\":[],\"categoryname\":\"Foods\",\"locName\":\"Coffee\"},{\"id\":128049183,\"name\":\"Fish\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":480,\"meanPrice\":407,\"demandBracket\":2,\"stockBracket\":0,\"stock\":0,\"demand\":98667,\"statusFlags\":[],\"categoryname\":\"Foods\",\"locName\":\"Fish\"},{\"id\":128049184,\"name\":\"FoodCartridges\",\"legality\":\"\",\"buyPrice\":57,\"sellPrice\":44,\"meanPrice\":105,\"demandBracket\":0,\"stockBracket\":2,\"stock\":46048,\"demand\":1,\"statusFlags\":[],\"categoryname\":\"Foods\",\"locName\":\"Food Cartridges\"},{\"id\":128049178,\"name\":\"FruitAndVegetables\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":358,\"meanPrice\":313,\"demandBracket\":2,\"stockBracket\":0,\"stock\":0,\"demand\":31857,\"statusFlags\":[],\"categoryname\":\"Foods\",\"locName\":\"Fruit and Vegetables\"},{\"id\":128049180,\"name\":\"Grain\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":229,\"meanPrice\":210,\"demandBracket\":2,\"stockBracket\":0,\"stock\":0,\"demand\":212624,\"statusFlags\":[],\"categoryname\":\"Foods\",\"locName\":\"Grain\"},{\"id\":128049185,\"name\":\"SyntheticMeat\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":246,\"meanPrice\":271,\"demandBracket\":2,\"stockBracket\":0,\"stock\":0,\"demand\":20600,\"statusFlags\":[],\"categoryname\":\"Foods\",\"locName\":\"Synthetic Meat\"},{\"id\":128049188,\"name\":\"Tea\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":1718,\"meanPrice\":1468,\"demandBracket\":2,\"stockBracket\":0,\"stock\":0,\"demand\":32039,\"statusFlags\":[],\"categoryname\":\"Foods\",\"locName\":\"Tea\"},{\"id\":128673856,\"name\":\"CMMComposite\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":6563,\"meanPrice\":5998,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":126860,\"statusFlags\":[],\"categoryname\":\"Industrial Materials\",\"locName\":\"CMM Composite\"},{\"id\":128672302,\"name\":\"CeramicComposites\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":328,\"meanPrice\":231,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":2053017,\"statusFlags\":[],\"categoryname\":\"Industrial Materials\",\"locName\":\"Ceramic Composites\"},{\"id\":128673857,\"name\":\"CoolingHoses\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":1570,\"meanPrice\":1658,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":431324,\"statusFlags\":[],\"categoryname\":\"Industrial Materials\",\"locName\":\"Micro-weave Cooling Hoses\"},{\"id\":128673855,\"name\":\"InsulatingMembrane\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":11609,\"meanPrice\":10937,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":80310,\"statusFlags\":[],\"categoryname\":\"Industrial Materials\",\"locName\":\"Insulating Membrane\"},{\"id\":128049197,\"name\":\"Polymers\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":272,\"meanPrice\":172,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":3009599,\"statusFlags\":[],\"categoryname\":\"Industrial Materials\",\"locName\":\"Polymers\"},{\"id\":128049199,\"name\":\"Semiconductors\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":1214,\"meanPrice\":968,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":2777622,\"statusFlags\":[],\"categoryname\":\"Industrial Materials\",\"locName\":\"Semiconductors\"},{\"id\":128049200,\"name\":\"Superconductors\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":7428,\"meanPrice\":6613,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":262877,\"statusFlags\":[],\"categoryname\":\"Industrial Materials\",\"locName\":\"Superconductors\"},{\"id\":128064028,\"name\":\"AtmosphericExtractors\",\"legality\":\"\",\"buyPrice\":307,\"sellPrice\":285,\"meanPrice\":357,\"demandBracket\":0,\"stockBracket\":1,\"stock\":45837,\"demand\":1,\"statusFlags\":[],\"categoryname\":\"Machinery\",\"locName\":\"Atmospheric Processors\"},{\"id\":128672309,\"name\":\"BuildingFabricators\",\"legality\":\"\",\"buyPrice\":892,\"sellPrice\":860,\"meanPrice\":986,\"demandBracket\":0,\"stockBracket\":2,\"stock\":9967,\"demand\":1,\"statusFlags\":[],\"categoryname\":\"Machinery\",\"locName\":\"Building Fabricators\"},{\"id\":128049222,\"name\":\"CropHarvesters\",\"legality\":\"\",\"buyPrice\":2099,\"sellPrice\":2029,\"meanPrice\":2022,\"demandBracket\":0,\"stockBracket\":1,\"stock\":32472,\"demand\":1,\"statusFlags\":[],\"categoryname\":\"Machinery\",\"locName\":\"Crop Harvesters\"},{\"id\":128673861,\"name\":\"EmergencyPowerCells\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":2625,\"meanPrice\":2348,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":50747,\"statusFlags\":[],\"categoryname\":\"Machinery\",\"locName\":\"Emergency Power Cells\"},{\"id\":128673866,\"name\":\"ExhaustManifold\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":2059,\"meanPrice\":1890,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":61848,\"statusFlags\":[],\"categoryname\":\"Machinery\",\"locName\":\"Exhaust Manifold\"},{\"id\":128672307,\"name\":\"GeologicalEquipment\",\"legality\":\"\",\"buyPrice\":1539,\"sellPrice\":1486,\"meanPrice\":1665,\"demandBracket\":0,\"stockBracket\":2,\"stock\":339769,\"demand\":1,\"statusFlags\":[],\"categoryname\":\"Machinery\",\"locName\":\"Geological Equipment\"},{\"id\":128673860,\"name\":\"HNShockMount\",\"legality\":\"\",\"buyPrice\":1608,\"sellPrice\":1553,\"meanPrice\":1584,\"demandBracket\":0,\"stockBracket\":2,\"stock\":54548,\"demand\":1,\"statusFlags\":[],\"categoryname\":\"Machinery\",\"locName\":\"HN Shock Mount\"},{\"id\":128049223,\"name\":\"MarineSupplies\",\"legality\":\"\",\"buyPrice\":4167,\"sellPrice\":4080,\"meanPrice\":3916,\"demandBracket\":0,\"stockBracket\":1,\"stock\":195344,\"demand\":1,\"statusFlags\":[],\"categoryname\":\"Machinery\",\"locName\":\"Marine Equipment\"},{\"id\":128049221,\"name\":\"MineralExtractors\",\"legality\":\"\",\"buyPrice\":497,\"sellPrice\":471,\"meanPrice\":444,\"demandBracket\":0,\"stockBracket\":1,\"stock\":95896,\"demand\":1,\"statusFlags\":[],\"categoryname\":\"Machinery\",\"locName\":\"Mineral Extractors\"},{\"id\":128049217,\"name\":\"PowerGenerators\",\"legality\":\"\",\"buyPrice\":428,\"sellPrice\":405,\"meanPrice\":459,\"demandBracket\":0,\"stockBracket\":2,\"stock\":299727,\"demand\":1,\"statusFlags\":[],\"categoryname\":\"Machinery\",\"locName\":\"Power Generators\"},{\"id\":128672313,\"name\":\"SkimerComponents\",\"legality\":\"\",\"buyPrice\":750,\"sellPrice\":724,\"meanPrice\":870,\"demandBracket\":0,\"stockBracket\":2,\"stock\":7552,\"demand\":1,\"statusFlags\":[],\"categoryname\":\"Machinery\",\"locName\":\"Skimmer Components\"},{\"id\":128672308,\"name\":\"ThermalCoolingUnits\",\"legality\":\"\",\"buyPrice\":162,\"sellPrice\":150,\"meanPrice\":260,\"demandBracket\":0,\"stockBracket\":2,\"stock\":33524,\"demand\":1,\"statusFlags\":[],\"categoryname\":\"Machinery\",\"locName\":\"Thermal Cooling Units\"},{\"id\":128049218,\"name\":\"WaterPurifiers\",\"legality\":\"\",\"buyPrice\":198,\"sellPrice\":182,\"meanPrice\":259,\"demandBracket\":0,\"stockBracket\":1,\"stock\":18772,\"demand\":1,\"statusFlags\":[],\"categoryname\":\"Machinery\",\"locName\":\"Water Purifiers\"},{\"id\":128682046,\"name\":\"AdvancedMedicines\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":1470,\"meanPrice\":1258,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":54458,\"statusFlags\":[],\"categoryname\":\"Medicines\",\"locName\":\"Advanced Medicines\"},{\"id\":128049210,\"name\":\"BasicMedicines\",\"legality\":\"\",\"buyPrice\":215,\"sellPrice\":199,\"meanPrice\":280,\"demandBracket\":0,\"stockBracket\":1,\"stock\":12017,\"demand\":1,\"statusFlags\":[],\"categoryname\":\"Medicines\",\"locName\":\"Basic Medicines\"},{\"id\":128049209,\"name\":\"PerformanceEnhancers\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":7491,\"meanPrice\":6811,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":22172,\"statusFlags\":[],\"categoryname\":\"Medicines\",\"locName\":\"Performance Enhancers\"},{\"id\":128049669,\"name\":\"ProgenitorCells\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":7467,\"meanPrice\":6772,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":33114,\"statusFlags\":[],\"categoryname\":\"Medicines\",\"locName\":\"Progenitor Cells\"},{\"id\":128049176,\"name\":\"Aluminium\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":428,\"meanPrice\":340,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":1316175,\"statusFlags\":[],\"categoryname\":\"Metals\",\"locName\":\"Aluminium\"},{\"id\":128049168,\"name\":\"Beryllium\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":8983,\"meanPrice\":8290,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":120620,\"statusFlags\":[],\"categoryname\":\"Metals\",\"locName\":\"Beryllium\"},{\"id\":128049162,\"name\":\"Cobalt\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":926,\"meanPrice\":648,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":304327,\"statusFlags\":[],\"categoryname\":\"Metals\",\"locName\":\"Cobalt\"},{\"id\":128049175,\"name\":\"Copper\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":629,\"meanPrice\":481,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":2395308,\"statusFlags\":[],\"categoryname\":\"Metals\",\"locName\":\"Copper\"},{\"id\":128049170,\"name\":\"Gallium\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":5800,\"meanPrice\":5138,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":1042990,\"statusFlags\":[],\"categoryname\":\"Metals\",\"locName\":\"Gallium\"},{\"id\":128049154,\"name\":\"Gold\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":10169,\"meanPrice\":9401,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":438246,\"statusFlags\":[],\"categoryname\":\"Metals\",\"locName\":\"Gold\"},{\"id\":128049169,\"name\":\"Indium\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":6547,\"meanPrice\":5732,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":153230,\"statusFlags\":[],\"categoryname\":\"Metals\",\"locName\":\"Indium\"},{\"id\":128049173,\"name\":\"Lithium\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":1944,\"meanPrice\":1598,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":875045,\"statusFlags\":[],\"categoryname\":\"Metals\",\"locName\":\"Lithium\"},{\"id\":128671118,\"name\":\"Osmium\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":9044,\"meanPrice\":9136,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":488374,\"statusFlags\":[],\"categoryname\":\"Metals\",\"locName\":\"Osmium\"},{\"id\":128049153,\"name\":\"Palladium\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":13957,\"meanPrice\":13295,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":339546,\"statusFlags\":[],\"categoryname\":\"Metals\",\"locName\":\"Palladium\"},{\"id\":128049152,\"name\":\"Platinum\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":19714,\"meanPrice\":19756,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":25371,\"statusFlags\":[],\"categoryname\":\"Metals\",\"locName\":\"Platinum\"},{\"id\":128673845,\"name\":\"Praseodymium\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":8411,\"meanPrice\":8604,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":255815,\"statusFlags\":[],\"categoryname\":\"Metals\",\"locName\":\"Praseodymium\"},{\"id\":128673847,\"name\":\"Samarium\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":7903,\"meanPrice\":8090,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":270615,\"statusFlags\":[],\"categoryname\":\"Metals\",\"locName\":\"Samarium\"},{\"id\":128049155,\"name\":\"Silver\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":5454,\"meanPrice\":4777,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":106214,\"statusFlags\":[],\"categoryname\":\"Metals\",\"locName\":\"Silver\"},{\"id\":128049171,\"name\":\"Tantalum\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":4540,\"meanPrice\":3965,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":1281759,\"statusFlags\":[],\"categoryname\":\"Metals\",\"locName\":\"Tantalum\"},{\"id\":128049174,\"name\":\"Titanium\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":1291,\"meanPrice\":1007,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":455491,\"statusFlags\":[],\"categoryname\":\"Metals\",\"locName\":\"Titanium\"},{\"id\":128049172,\"name\":\"Uranium\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":3132,\"meanPrice\":2707,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":1744640,\"statusFlags\":[],\"categoryname\":\"Metals\",\"locName\":\"Uranium\"},{\"id\":128673848,\"name\":\"LowTemperatureDiamond\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":57674,\"meanPrice\":57443,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":12686,\"statusFlags\":[],\"categoryname\":\"Minerals\",\"locName\":\"Low Temperature Diamonds\"},{\"id\":128668550,\"name\":\"Painite\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":45059,\"meanPrice\":40504,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":3172,\"statusFlags\":[],\"categoryname\":\"Minerals\",\"locName\":\"Painite\"},{\"id\":128049214,\"name\":\"Beer\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":149,\"meanPrice\":187,\"demandBracket\":2,\"stockBracket\":0,\"stock\":0,\"demand\":184052,\"statusFlags\":[],\"categoryname\":\"Narcotics\",\"locName\":\"Beer\"},{\"id\":128672306,\"name\":\"BootlegLiquor\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":283,\"meanPrice\":852,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":3144,\"statusFlags\":[],\"categoryname\":\"Narcotics\",\"locName\":\"Bootleg Liquor\"},{\"id\":128049216,\"name\":\"Liquor\",\"legality\":\"\",\"buyPrice\":540,\"sellPrice\":512,\"meanPrice\":589,\"demandBracket\":0,\"stockBracket\":1,\"stock\":244,\"demand\":1,\"statusFlags\":[],\"categoryname\":\"Narcotics\",\"locName\":\"Liquor\"},{\"id\":128049215,\"name\":\"Wine\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":246,\"meanPrice\":261,\"demandBracket\":2,\"stockBracket\":0,\"stock\":0,\"demand\":136661,\"statusFlags\":[],\"categoryname\":\"Narcotics\",\"locName\":\"Wine\"},{\"id\":128066403,\"name\":\"Drones\",\"legality\":\"\",\"buyPrice\":101,\"sellPrice\":100,\"meanPrice\":101,\"demandBracket\":0,\"stockBracket\":3,\"stock\":122639,\"demand\":1,\"statusFlags\":[],\"categoryname\":\"NonMarketable\"},{\"id\":128049228,\"name\":\"AutoFabricators\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":4274,\"meanPrice\":3732,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":86211,\"statusFlags\":[],\"categoryname\":\"Technology\",\"locName\":\"Auto-Fabricators\"},{\"id\":128049225,\"name\":\"ComputerComponents\",\"legality\":\"\",\"buyPrice\":441,\"sellPrice\":418,\"meanPrice\":514,\"demandBracket\":0,\"stockBracket\":1,\"stock\":3553,\"demand\":1,\"statusFlags\":[],\"categoryname\":\"Technology\",\"locName\":\"Computer Components\"},{\"id\":128049226,\"name\":\"HazardousEnvironmentSuits\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":325,\"meanPrice\":338,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":862648,\"statusFlags\":[],\"categoryname\":\"Technology\",\"locName\":\"H.E. Suits\"},{\"id\":128673873,\"name\":\"MicroControllers\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":6170,\"meanPrice\":5556,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":30232,\"statusFlags\":[],\"categoryname\":\"Technology\",\"locName\":\"Micro Controllers\"},{\"id\":128049227,\"name\":\"Robotics\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":2182,\"meanPrice\":1854,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":221255,\"statusFlags\":[],\"categoryname\":\"Technology\",\"locName\":\"Robotics\"},{\"id\":128682044,\"name\":\"ConductiveFabrics\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":672,\"meanPrice\":507,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":487752,\"statusFlags\":[],\"categoryname\":\"Textiles\",\"locName\":\"Conductive Fabrics\"},{\"id\":128049190,\"name\":\"Leather\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":292,\"meanPrice\":205,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":2236839,\"statusFlags\":[],\"categoryname\":\"Textiles\",\"locName\":\"Leather\"},{\"id\":128049191,\"name\":\"NaturalFabrics\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":491,\"meanPrice\":439,\"demandBracket\":2,\"stockBracket\":0,\"stock\":0,\"demand\":616051,\"statusFlags\":[],\"categoryname\":\"Textiles\",\"locName\":\"Natural Fabrics\"},{\"id\":128049193,\"name\":\"SyntheticFabrics\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":193,\"meanPrice\":211,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":1382163,\"statusFlags\":[],\"categoryname\":\"Textiles\",\"locName\":\"Synthetic Fabrics\"},{\"id\":128049244,\"name\":\"Biowaste\",\"legality\":\"\",\"buyPrice\":13,\"sellPrice\":10,\"meanPrice\":63,\"demandBracket\":0,\"stockBracket\":1,\"stock\":6849,\"demand\":1,\"statusFlags\":[],\"categoryname\":\"Waste \",\"locName\":\"Biowaste\"},{\"id\":128049248,\"name\":\"Scrap\",\"legality\":\"\",\"buyPrice\":27,\"sellPrice\":23,\"meanPrice\":49,\"demandBracket\":0,\"stockBracket\":2,\"stock\":132615,\"demand\":1,\"statusFlags\":[],\"categoryname\":\"Waste \",\"locName\":\"Scrap\"},{\"id\":128049236,\"name\":\"NonLethalWeapons\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":2120,\"meanPrice\":1834,\"demandBracket\":2,\"stockBracket\":0,\"stock\":0,\"demand\":2524,\"statusFlags\":[],\"categoryname\":\"Weapons\",\"locName\":\"Non-Lethal Weapons\"},{\"id\":128049233,\"name\":\"PersonalWeapons\",\"legality\":\"\",\"buyPrice\":4168,\"sellPrice\":4080,\"meanPrice\":4624,\"demandBracket\":0,\"stockBracket\":1,\"stock\":274,\"demand\":1,\"statusFlags\":[],\"categoryname\":\"Weapons\",\"locName\":\"Personal Weapons\"},{\"id\":128049235,\"name\":\"ReactiveArmour\",\"legality\":\"\",\"buyPrice\":0,\"sellPrice\":2475,\"meanPrice\":2108,\"demandBracket\":3,\"stockBracket\":0,\"stock\":0,\"demand\":8225,\"statusFlags\":[],\"categoryname\":\"Weapons\",\"locName\":\"Reactive Armour\"}]}";



            CMarket market = new CMarket();

            JObject jo = JObject.Parse(resp);

            Assert.NotNull(jo, "Json parse");
            bool ret = market.FromJson(jo);

            Assert.IsTrue(ret, "From JSon");

            Assert.AreEqual(3230605824, market.id, "id");

            Assert.AreEqual("Dunbar Ring", market.name, "Name");

            Assert.AreEqual(79, market.commodities.Count, "nr Commodities");


            Assert.AreEqual("hydrogenfuel", market.commodities[0].fdname, "Name");
            Assert.AreEqual(113, market.commodities[0].buyPrice, "buyPrice");
            Assert.AreEqual(108, market.commodities[0].sellPrice, "sellPrice");
            Assert.AreEqual(110, market.commodities[0].meanPrice, "meanPrice");
            Assert.AreEqual(0, market.commodities[0].demandBracket, "demandBracket");
            Assert.AreEqual(1, market.commodities[0].stockBracket, "stockBracket");
            Assert.AreEqual(150631, market.commodities[0].stock, "stock");
            Assert.AreEqual(1, market.commodities[0].demand, "demand");
            Assert.AreEqual("$MARKET_category_chemicals", market.commodities[0].category, "categoryname");
            Assert.AreEqual("Hydrogen Fuel", market.commodities[0].locName, "locName");
        }
        protected TradeAction EvalStopLoss(CMarket market, TradeAction result)
        {
            if (MainConfiguration.Configuration.EnableStopLoss)
            {
                //var now = market.CandleMaker.CurrentCandleDate;
                //var candleLen = MainConfiguration.Configuration.CandleWidthInSeconds / 60;
                //var E = Evaluations.EvaluationManager.Instance;

                if (Math.Abs(market.TotCoins) < 0.01M)
                {
                    // sono a zero
                    StopLoss.Reset();
                }
                else
                if (StopLoss.IsSell(this.CoinValue))
                {
                    var currentTrend = Trend();
                    if (currentTrend == TechnicalAnalysis.Trend.Fall)
                    {
                        StopLoss.Reset();
                        StopLoss.SellCounter++;
                        //AnalyticsTools.Call("stoploss");
                        //E.Add("stoploss", new Prediction() { Date = now, Type = PredictionType.LessThan, Value = this.CoinValue }, candleLen);
                        return(TradeAction.StrongSell);
                    }
                }
            }
            return(result); //TradeAction.Unknown;
        }
        private TradeAction EvalDerivative(CMarket market)
        {
            var result2  = TradeAction.Unknown;
            var emaUp    = this.EmaDiff.Derivative.IsCrossUp;
            var emaDown  = this.EmaDiff.Derivative.IsCrossDown;
            var macdUp   = this.Macd122609.Derivative.IsCrossUp;
            var macdDown = this.Macd122609.Derivative.IsCrossDown;

            LogTrade.MacdStandard = this.EmaDiff.Derivative.CurrentSpeed;
            LogTrade.Roc          = this.Macd122609.Derivative.CurrentSpeed;
            LogTrade.RocSpeed     = 0;

            if (emaUp && macdUp)
            {
                result2 = TradeAction.Buy;
            }
            else
            if (emaDown && macdDown)
            {
                result2 = TradeAction.Sell;
            }
            else
            {
                result2 = TradeAction.Hold;
            }
            return(result2);
        }
        public  CManager(CConfiguration configuration, CMarket market)
        {
            this._configuration = configuration;
            this._market = market;

            // il manager potrebbe cambiare il valore settato nella configurazione
            _ticksPerHearthBeat = configuration.Tick;
        }
Пример #6
0
        public async Task <IActionResult> Market(CCultivator cult)
        {
            TempData["Gold"]     = cult.Gold;
            TempData["Nickname"] = cult.Name;
            CMarket location = (CMarket)GLocationsList.GetById(cult.LocationId);

            return(View(location));
        }
        protected TradeAction EvalStopLossUpDown(CMarket market, TradeAction result)
        {
            var gain = 0.04M;

            if (Math.Abs(market.TotCoins) < 0.01M)
            {
                this.StopLoss.Reset();
            }
            else if (this.StopLoss.IsSell(market.TotValue))
            {
                //if (currentTrend == TechnicalAnalysis.Trend.Fall)
                {
                    this.StopLoss.Reset();
                    this.StopLoss.SellCounter++;
                    // AnalyticsTools.Call("stoploss");
                    if (this.CoinValue * (1 + gain) > LogTrade.SellAt)
                    {
                        return(TradeAction.StrongSell);
                    }
                    else
                    {
                        return(TradeAction.Sell);
                    }
                }
            }


            if (Math.Abs(market.TotMoney) < 0.01M)
            {
                this.StopLossReverse.Reset();
            }
            else if (this.StopLossReverse.IsSell(1 / this.CoinValue))
            {
                //if (currentTrend == TechnicalAnalysis.Trend.Raise)
                {
                    this.StopLossReverse.Reset();
                    this.StopLossReverse.SellCounter++;
                    //AnalyticsTools.Call("stoploss rev");
                    if (this.CoinValue * (1 - gain) < LogTrade.BuyAt)
                    {
                        return(TradeAction.StrongBuy);
                    }
                    else
                    {
                        return(TradeAction.Buy);
                    }
                }
            }

            //result = TradeAction.Hold;
            return(result);
        }
Пример #8
0
        public CMarket GetMarket()
        {
            if (NeedLogin == true)
            {
                throw new CompanionAppIllegalStateException("Service is not logged in to profile");
            }

            if (!Credentials.Confirmed)
            {
                throw new CompanionAppIllegalStateException("Credentials are not confirmed");
            }

            string data = DownloadMarket();

            if (data == null || data == "Profile unavailable")
            {
                // Happens if there is a problem with the API.  Logging in again might clear this...
                Credentials.appId = null;
                relogin();
                data = DownloadMarket();

                if (data == null || data == "Profile unavailable")
                {
                    // Try logging in again without clearing the session ID
                    relogin();
                    data = DownloadMarket();

                    if (data == null || data == "Profile unavailable")      // uhoh
                    {
                        Logout();
                        throw new CompanionAppException("Failed to obtain data from Frontier server");
                    }
                }
            }

            ProfileString = data;
            JObject jo = JObject.Parse(ProfileString);

            ProfileString = jo.ToString(Formatting.Indented);       // nicer
            //System.Diagnostics.Debug.WriteLine(ProfileString);
            CMarket market = new CMarket();

            if (market.FromJson(jo))
            {
                return(market);
            }
            else
            {
                return(null);
            }
        }
        protected TradeAction EvalAlarmIndicator(CMarket market, TradeAction result)
        {
            //var now = market.CandleMaker.CurrentCandleDate;
            //var candleLen = MainConfiguration.Configuration.CandleWidthInSeconds / 60;
            //var E = Evaluations.EvaluationManager.Instance;

            var emadiffValue = this.CurrentEmaDiff;   //EmaDiff.Calculate(); // potrebbe essere inutile (lo abbiamo già)
            var macdValue    = this.CurrentMacdValue; // potrebbe essere inutile (lo abbiamo già)

            //var roclimit = 5.0M;
            if (Math.Sign(emadiffValue) == Math.Sign(macdValue))
            {
                var limit = MainConfiguration.Configuration.AlarmStrongSellBuyLimit; // occorre capire che valori sono i migliori


                if ((emadiffValue < -limit && macdValue < -limit))
                {
                    //LogTrade.Note = ("suggestion: (emadiffValue < -limit && macdValue < -limit)");
                    //AnalyticsTools.Call("ema;macd;limit;-");
                    //E.Add("ema;macd;limit;-", new Prediction() { Date = now, Type = PredictionType.LessThan, Value = this.CoinValue }, candleLen);
                    return(TradeAction.StrongSell);
                }

                if (emadiffValue > limit && macdValue > limit)
                {
                    //LogTrade.Note = ("suggestion:  (emadiffValue > limit && macdValue > limit)");
                    //AnalyticsTools.Call("ema;macd;limit;+");
                    //E.Add("ema;macd;limit;+", new Prediction() { Date = now, Type = PredictionType.GreatherThan, Value = this.CoinValue }, candleLen);
                    return(TradeAction.StrongBuy);
                }

                /*
                 * if (emadiffValue < -1 && macdValue < -1)
                 * {
                 *  //LogTrade.Note = ("suggestion:  (emadiffValue < -1 && macdValue < -1)");
                 *  AnalyticsTools.Call("ema;macd;-1");
                 *  return TradeAction.Sell;
                 * }
                 *
                 * if (emadiffValue > 1 && macdValue > 1)
                 * {
                 *  AnalyticsTools.Call("ema;macd;+1");
                 *  //LogTrade.Note = ("suggestion:  (emadiffValue > 1 && macdValue > 1)");
                 *  return TradeAction.Buy;
                 * }
                 */
            }
            return(result); //TradeAction.Unknown;
        }
        protected TradeAction EvalStopLossValue(CMarket market, TradeAction result)
        {
            var now       = market.CandleMaker.CurrentCandleDate;
            var candleLen = MainConfiguration.Configuration.CandleWidthInSeconds / 60;
            // var E = Evaluations.EvaluationManager.Instance;

            /********************************************************************************
            * STOP LOSS SUL VALORE
            * lo stop loss viene fatto su fasce di valori per evitare l'effetto oscillazione
            ********************************************************************************/
            decimal stopLossPerc = 1.0M + 0.4M; //MainConfiguration.Configuration.TestNumber/100M;

            decimal[] stopLossLevels = { 0, 100, 250, 500, 1000, 2500, 5000, 10000, 12500, 15000, 20000, 25000, 50000 };

            if (market.TotCoins > 0)
            {
                var value = market.TotValue * stopLossPerc;
                var level = 100 * 1000M;

                var stopLossLevelIndex = 0;
                while (stopLossLevelIndex < stopLossLevels.Count() && stopLossLevels[stopLossLevelIndex] < value)
                {
                    level = stopLossLevels[stopLossLevelIndex++];
                }

                if (level < value && value < _tempStopLossMaxValue &&
                    _tempStopLossMaxValue == market.MaxValue)
                {
                    //stopLossLevelIndex++;
                    _tempStopLossMaxValue = decimal.MinValue;
                    // AnalyticsTools.Call("stoploss value");
                    //E.Add("stoploss value", new Prediction() { Date = now, Type = PredictionType.LessThan, Value = this.CoinValue }, candleLen);
                    return(TradeAction.StrongSell);
                }
                else
                {
                    _tempStopLossMaxValue       = (market.TotValue > _tempStopLossMaxValue)
                        ? _tempStopLossMaxValue = market.TotValue
                        : _tempStopLossMaxValue;
                }
            }
            else
            {
                _tempStopLossMaxValue = decimal.MinValue;
            }
            return(result); //TradeAction.Unknown;
        }
        protected TradeAction EvalPoll(CMarket market, TradeAction result)
        {
            var poll = new Poll();

            this.Macd122609.Tolerance = MainConfiguration.Configuration.Tolerance;
            this.EmaDiff.Tolerance    = MainConfiguration.Configuration.Tolerance;

            var macdSuggestion = this.Macd122609.SuggestedAction(this.CurrentMacdValue, this.CurrentTrend);

            poll.Add(macdSuggestion);

            var emadiffSuggestion = EmaDiff.SuggestedAction(CurrentEmaDiff, this.CurrentTrend);

            poll.Add(emadiffSuggestion);

            var moneySuggestion = this.Values.SuggestedAction(CoinValue, this.CurrentTrend);

            poll.Add(moneySuggestion);

            return(poll.Result());
        }
        protected TradeAction EvalCandles(CMarket market)
        {
            var bullish = 0;
            var bearish = 0;
            var candles = market.CandleMaker.GetLastCandles();

            //var candles = market.CandleMakerHourly.GetLastCandles();
            for (var i = 0; i < 1; i++)
            {
                var c     = new[] { candles[i], candles[i + 1], candles[i + 2] };
                var trend = CandleAnalyzer.Evaluate(c);
                if (trend == StackTrend.Bullish)
                {
                    // AnalyticsTools.Call("candle bull");
                    bullish++;
                }
                else
                if (trend == StackTrend.Bearish)
                {
                    // AnalyticsTools.Call("candle bear");
                    bearish++;
                }
            }
            //var candleSuggestion = TradeAction.Hold;
            var bearbullishratio = 0.6M;

            if (bullish > bearish * bearbullishratio)
            {
                //LogTrade.Note += " BULL ";
                return(TradeAction.Buy);
            }
            else if (bearish < bullish * bearbullishratio)
            {
                //LogTrade.Note += " BEAR ";
                return(TradeAction.Sell);
            }
            return(TradeAction.Hold);
        }
        public override TradeAction SuggestedAction(CMarket market)
        {
            /********************************************************************************
            * COSTANTI (evaluator)
            ********************************************************************************/

            //var timeUnit = 15;

            //data corrente (servirebbe la data del ticker, ma vabbè...)
            var now = market.CandleMaker.GetLastCandles()[0].Date;

            var lastCandle = new
            {
                m15 = market.CandleMaker.GetLastCandles()[0],
                h1  = market.CandleMakerHourly.GetLastCandles()[0],
            };

            //valutatore
            var E = Evaluations.EvaluationManager.Instance;

            //formatta i nomi degli indicatori
            Func <string, string> N = (o =>
            {
                return(string.Format("{0}[{1}]", o, this.Name));
            });



            /********************************************************************************
            * COSTANTI
            ********************************************************************************/

            var currentTrend = market.CandleMaker.Analyze.CurrentTrend; //Trend();
            var roclimit     = MainConfiguration.Configuration.AlarmStrongSellBuyRocLimit;
            var macdlimit    = MainConfiguration.Configuration.AlarmStrongSellMacdLimit;

            /********************************************************************************
            * STOP LOSS
            ********************************************************************************/
            if (MainConfiguration.Configuration.EnableStopLoss)
            {
                if (StopLoss.IsSell(this.CoinValue))
                {
                    if (currentTrend == TechnicalAnalysis.Trend.Fall)
                    {
                        StopLoss.Reset();
                        StopLoss.SellCounter++;

                        //EVAL: se uso lo stoploss, sto prevedendo che il prezzo scenda, anche di poco
                        E.Add(N("stoploss"), CreatePrediction(now, TradeAction.StrongSell), timeUnit);
                    }
                }
            }

            if (!IsValid())
            {
                //AnalyticsTools.Call("notyetready");
                return(TradeAction.Unknown);
            }



            /********************************************************************************
            * ROC (non ancora usato)
            ********************************************************************************/
            if (true)
            {
                var rocSpeed = Roc.Derivative.CurrentSpeed;
                if (Rocdiff > roclimit && rocSpeed <= 0 && currentTrend == TechnicalAnalysis.Trend.Fall)
                {
                    //LogTrade.Note = "inversione: vendere";
                    //EVAL: se dico di vendere, vuol dire che il prezzo scenderà, anche di poco
                    E.Add(N("-(rocdiff;rocspeed)"), CreatePrediction(now, TradeAction.Sell), timeUnit);

                    if (CurrentMacdValue > macdlimit)
                    {
                        //EVAL: questo è un rafforzativo, quindi mi aspetto un grande ribasso
                        E.Add(N("++(rocdiff;rocspeed;Macd122609)"), CreatePrediction(now, TradeAction.StrongSell), timeUnit);

                        //return TradeAction.StrongSell;
                    }
                }
                if (Rocdiff < -roclimit && rocSpeed <= 0 && currentTrend == TechnicalAnalysis.Trend.Raise)
                {
                    //LogTrade.Note = "inversione: comprare";
                    //EVAL: se dico di comprare, vuol dire che il prezzo salirà, anche di poco
                    E.Add(N("+(rocdiff;rocspeed)"), CreatePrediction(now, TradeAction.Buy), timeUnit);

                    if (CurrentMacdValue < -macdlimit)
                    {
                        //EVAL: questo è un rafforzativo, quindi mi aspetto un grande rialzo
                        E.Add(N("++(rocdiff;rocspeed;Macd122609)"), CreatePrediction(now, TradeAction.StrongBuy), timeUnit);
                        // return TradeAction.StrongBuy;
                    }
                }
            }
            if (true)
            {
                // se si mette a true, questo garantisce 12k e 15btc (l'altro pezzo sul roc va messo in tuning
                if (Rocdiff > roclimit && currentTrend == TechnicalAnalysis.Trend.Fall)
                {
                    //LogTrade.Note = "inversione: vendere";
                    //EVAL: se dico di vendere, vuol dire che il prezzo scenderà, anche di poco
                    E.Add(N("-(rocdiff)"), CreatePrediction(now, TradeAction.Sell), timeUnit);

                    if (CurrentMacdValue > 2)
                    {
                        //EVAL: questo è un rafforzativo, quindi mi aspetto un grande ribasso
                        E.Add(N("--(rocdiff;Macd122609)"), CreatePrediction(now, TradeAction.StrongSell), timeUnit);
                        //return TradeAction.StrongSell;
                    }
                }
                if (Rocdiff < -roclimit && currentTrend == TechnicalAnalysis.Trend.Raise)
                {
                    //LogTrade.Note = "inversione: comprare";
                    //EVAL: se dico di comprare, vuol dire che il prezzo salirà, anche di poco
                    E.Add(N("+(rocdiff;rocspeed)"), CreatePrediction(now, TradeAction.Buy), timeUnit);

                    if (CurrentMacdValue < -2)
                    {
                        //EVAL: questo è un rafforzativo, quindi mi aspetto un grande rialzo
                        E.Add(N("++(rocdiff;rocspeed;Macd122609)"), CreatePrediction(now, TradeAction.StrongBuy), timeUnit);
                        // return TradeAction.StrongBuy;
                    }
                }

                /********************************************************************************
                * ALLARMI
                ********************************************************************************/

                var emadiffValue = EmaDiff.CurrentValue;  //EmaDiff.Calculate(); // potrebbe essere inutile (lo abbiamo già)
                var macdValue    = this.CurrentMacdValue; // potrebbe essere inutile (lo abbiamo già)
                //var roclimit = 5.0M;
                if (Math.Sign(emadiffValue) == Math.Sign(macdValue))
                {
                    var limit = MainConfiguration.Configuration.AlarmStrongSellBuyLimit; // occorre capire che valori sono i migliori


                    if ((emadiffValue < -limit && macdValue < -limit))
                    {
                        //LogTrade.Note = ("suggestion: (emadiffValue < -limit && macdValue < -limit)");
                        // AnalyticsTools.Call("ema;macd;limit;-");
                        //return TradeAction.StrongSell;

                        //EVAL:
                        E.Add(N("--(ema;macd;limit;)"), CreatePrediction(now, TradeAction.StrongSell), timeUnit);
                    }

                    if (emadiffValue > limit && macdValue > limit)
                    {
                        //LogTrade.Note = ("suggestion:  (emadiffValue > limit && macdValue > limit)");
                        // AnalyticsTools.Call("ema;macd;limit;+");
                        // return TradeAction.StrongBuy;

                        //EVAL:
                        E.Add(N("++(ema;macd;limit;)"), CreatePrediction(now, TradeAction.StrongBuy), timeUnit);
                    }

                    if (emadiffValue < -1 && macdValue < -1)
                    {
                        //LogTrade.Note = ("suggestion:  (emadiffValue < -1 && macdValue < -1)");
                        // AnalyticsTools.Call("ema;macd;-1");
                        // return TradeAction.Sell;

                        //EVAL:
                        E.Add(N("-(ema;macd;-1;)"), CreatePrediction(now, TradeAction.Sell), timeUnit);
                    }

                    if (emadiffValue > 1 && macdValue > 1)
                    {
                        //  AnalyticsTools.Call("ema;macd;+1");
                        //LogTrade.Note = ("suggestion:  (emadiffValue > 1 && macdValue > 1)");
                        //return TradeAction.Buy;

                        //EVAL:
                        E.Add(N("+(ema;macd;+1;)"), CreatePrediction(now, TradeAction.Buy), timeUnit);
                    }
                }



                var poll = new Poll();

                /********************************************************************************
                * MACD
                ********************************************************************************/
                //foreach (MacdItem item in this.MacdList)
                {
                    poll.Add(Macd122609.SuggestedAction(CurrentMacdValue, currentTrend));
                    CUtility.Log(string.Format("MACD   {0}", Math.Round(CurrentMacdValue, 4).ToString(CultureInfo.InvariantCulture)));
                }

                /********************************************************************************
                * EMADIFF
                ********************************************************************************/
                var emadiffSuggestion = EmaDiff.SuggestedAction(CurrentEmaDiff, currentTrend);
                poll.Add(emadiffSuggestion);
                CUtility.Log(string.Format("EMADIFF {0}", Math.Round(CurrentEmaDiff, 4).ToString(CultureInfo.InvariantCulture)));


                /********************************************************************************
                * DECISION
                ********************************************************************************/
                //LogTrade.Note = "poll";

                var result = poll.Result();

                if (true)
                {
                    // questo sistema di sicurezza non genera troppi problemi, ma non aumenta il reddito
                    // pero' aumenta la media dei redditi

                    // sistema di sicurezza da testare
                    const decimal securitylimit = 1.5M; // va bene cosi'


                    if (result == TradeAction.Buy && market.Buy >= securitylimit * LogTrade.BuyAt && LogTrade.BuyAt > 0 &&
                        currentTrend == TechnicalAnalysis.Trend.Raise)
                    {
                        //  AnalyticsTools.Call("expensive");
                        //  return TradeAction.Hold;

                        //EVAL: in realtà, "expensive" scommette sul fatto che può comprare a meno
                        E.Add(N("expensive"), new Evaluations.Prediction()
                        {
                            Date  = now,
                            Type  = Evaluations.PredictionType.LessThan,
                            Value = this.CoinValue * (1 - 0.01M)
                        }, timeUnit);
                    }

                    if (result == TradeAction.Sell && market.Sell <= securitylimit * LogTrade.SellAt && LogTrade.SellAt > 0 &&
                        currentTrend == TechnicalAnalysis.Trend.Fall)
                    {
                        // AnalyticsTools.Call("cheap");
                        //  return TradeAction.Hold;

                        //EVAL: in realtà, "cheap" scommette sul fatto che può vendere a più
                        E.Add(N("cheap"), new Evaluations.Prediction()
                        {
                            Date  = now,
                            Type  = Evaluations.PredictionType.GreatherThan,
                            Value = this.CoinValue * (1 + 0.01M)
                        }, timeUnit);
                    }
                }

                if (result != TradeAction.Hold)
                {
                    // AnalyticsTools.Call("poll " + result.ToString());
                }

                //return result;

                //EVAL: globale, ovvero cosa fa l'algoritmo
                // E.Add("GLOBAL", CreatePrediction(now, result), timeUnit);

                return(TradeAction.Unknown);
            }
        }
        public override TradeAction SuggestedAction(CMarket market)
        {
            /********************************************************************************
            * CONSERVATIVE DYNAMIC
            *
            ********************************************************************************/
            if (MainConfiguration.Configuration.ManagerIsConservative &&
                MainConfiguration.Configuration.ManagerConservativeTimesPerValue > 0)
            {
                MainConfiguration.Configuration.ManagerConservativeMaxMoneyToInvest = ((market.Buy + market.Sell) / 2) * MainConfiguration.Configuration.ManagerConservativeTimesPerValue;
            }

            /********************************************************************************
            * EVALUATION
            * vengono esaminati i comandi ed eseguiti uno ad uno
            ********************************************************************************/
            var result      = TradeAction.Unknown;
            var commandname = "";

            foreach (var commandName in MainConfiguration.Configuration.Commands)
            {
                commandname = commandName;
                var command = GetCommand(commandname);
                if (command == null)
                {
                    // in realtà dovrebbe incazzarsi di brutto
                    continue;
                }
                result = command(market, result);

                // se il comando è Strong o hold allora termina subito
                if (result == TradeAction.Hold)
                {
                    goto exitloop;
                }
                if (result == TradeAction.StrongBuy)
                {
                    goto exitloop;
                }
                if (result == TradeAction.StrongSell)
                {
                    goto exitloop;
                }
                //if (result == TradeAction.SellStopLoss) goto exitloop;
            }
exitloop:

            /********************************************************************************
            * LOGGING
            ********************************************************************************/
            var e = Evaluations.EvaluationManager.Instance;
            var prediction = PredictionType.Unknown;

            switch (result)
            {
            //case TradeAction.SellStopLoss:
            //    commandname += "--";
            //    prediction = PredictionType.LessThan;
            //    break;
            case TradeAction.StrongBuy:
                commandname += "++ ";
                prediction   = PredictionType.GreatherThan;
                break;

            case TradeAction.StrongSell:
                commandname += "-- ";
                prediction   = PredictionType.LessThan;
                break;

            case TradeAction.Hold:
                commandname += "=  ";
                prediction   = PredictionType.Equal;
                break;

            case TradeAction.Buy:
                commandname += "+  ";
                prediction   = PredictionType.GreatherThan;
                break;

            case TradeAction.Sell:
                commandname += "-  ";
                prediction   = PredictionType.LessThan;
                break;
            }

            AnalyticsTools.Call(commandname);

            var now       = market.CandleMaker.CurrentCandleDate;
            var candleLen = MainConfiguration.Configuration.CandleWidthInSeconds / 60;

            e.Add(commandname, new Prediction()
            {
                Date = now, Type = prediction, Value = this.CoinValue
            }, candleLen);

            if (result != TradeAction.Hold)
            {
                LogTrade.Note += " " + commandname;
            }

            return(result);
        }
        protected TradeAction EvalCandles(CMarket market, TradeAction result)
        {
            var newresult = EvalCandles(market);

            return(EnforceDecision(result, newresult));
        }
 public abstract TradeAction SuggestedAction(CMarket market);
        protected TradeAction EvalDerivative(CMarket market, TradeAction result)
        {
            var newresult = EvalDerivative(market);

            return(EnforceDecision(result, newresult));
        }