Description
For an example we use Bollinger Bands.
We assume, that if bargains do not cross the top and bottom strip we are in chaos(weak balance across Nish).
Further it is necessary for us to define the leader or a dominant.
It depends on band height and periods of domination.
If the strip is crossed, and the given period of domination achieves, it means formation of a direction on growth(buy) or falling (sell).
Using more difficult calculations (in this example they aren't present), we can predict formation of a trend and its size.
// ------------------------------------------------------------------------------- // // Simple example with use of "Games Theory". // Vsoft(c). // // ------------------------------------------------------------------------------- using System; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Requests; using cAlgo.Indicators; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC)] public class SampleBreakoutRobot : Robot { [Parameter] public DataSeries Source { get; set; } [Parameter("Band Height", DefaultValue = 1.0, MinValue = 0)] public double BandHeight { get; set; } [Parameter("Stop Loss", DefaultValue = 10, MinValue = 1)] public int StopLossInPips { get; set; } [Parameter("Take Profit", DefaultValue = 10, MinValue = 1)] public int TakeProfitInPips { get; set; } [Parameter("Volume", DefaultValue = 10000, MinValue = 1000)] public int Volume { get; set; } [Parameter("Bollinger Bands Deviations", DefaultValue = 2)] public int Deviations { get; set; } // BB [Parameter("Bollinger Bands Periods", DefaultValue = 20)] public int Periods { get; set; } // BB [Parameter("Bollinger Bands MA Type")] public MovingAverageType MAType { get; set; } // BB [Parameter("Domination Periods", DefaultValue = 1)] public int DominationPeriods { get; set; } // Definition a dominant. private BollingerBands bollingerBands; private int Domination; protected override void OnStart() { bollingerBands = Indicators.BollingerBands(Source, Periods, Deviations, MAType); } protected override void OnBar() { double top = bollingerBands.Top.LastValue; double bottom = bollingerBands.Bottom.LastValue; if ((top - bottom)/ Symbol.PipSize <= BandHeight) { Domination= Domination+1; } else { Domination=0; } if ( Domination >= DominationPeriods) { if (Symbol.Ask > top && MarketSeries.Close[MarketSeries.Close.Count - 2]> MarketSeries.Open[MarketSeries.Close.Count - 2]) { var request = new MarketOrderRequest(TradeType.Buy, Volume) { Label = "SampleGameTheory", StopLossPips = StopLossInPips, TakeProfitPips = TakeProfitInPips }; Trade.Send(request); Domination = 0; } else if (Symbol.Bid < bottom && MarketSeries.Close[MarketSeries.Close.Count - 2]< MarketSeries.Open[MarketSeries.Close.Count - 2]) { var request = new MarketOrderRequest(TradeType.Sell, Volume) { Label = "SampleGameTheory", StopLossPips = StopLossInPips, TakeProfitPips = TakeProfitInPips }; Trade.Send(request); Domination = 0; } } } } }
/
vito
Joined on 22.07.2013
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: SampleGameTheoryRobot.algo
- Rating: 0
- Installs: 3566
- Modified: 13/10/2021 09:54
Comments
Thank you, that is very interesting. Although I am afraid my son is yet too young to think about the code of the games. He would rather play something, that has already been coded.
That makes sense. But can you imagine that different people can have different goals? If you like to play ready-made games, you can check them out now https://fnfmod.online/ or forever keep your peace. While my own son said he would rather study the programming algos himself as he dreams of making mods one day too.