Replies

alibuc
24 Oct 2014, 15:22

RE: Sorry about bad formatting..
alibuc said:
Something like this? // ------------------------------------------------------------------------------------------------- // // This code is a cAlgo API sample. // // This cBot is intended to be used as a sample and does not guarantee any particular outcome or // profit of any kind. Use it at your own risk // // The "Sample Martingale cBot" creates a random Sell or Buy order. If the Stop loss is hit, a new // order of the same type (Buy / Sell) is created with double the Initial Volume amount. The cBot will // continue to double the volume amount for all orders created until one of them hits the take Profit. // After a Take Profit is hit, a new random Buy or Sell order is created with the Initial Volume amount. // // ------------------------------------------------------------------------------------------------- using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class ab_Martingale : Robot { [Parameter("Initial Volume", DefaultValue = 1000, MinValue = 0)] public int InitialVolume { get; set; } [Parameter("Stop Loss", DefaultValue = 40)] public int StopLoss { get; set; } [Parameter("Take Profit", DefaultValue = 40)] public int TakeProfit { get; set; } [Parameter("Max Bet", DefaultValue = 50000)] public int maxBet { get; set; } private Random random = new Random(); protected override void OnStart() { Positions.Closed += OnPositionsClosed; ExecuteOrder(InitialVolume, GetRandomTradeType()); } private void ExecuteOrder(long volume, TradeType tradeType) { var result = ExecuteMarketOrder(tradeType, Symbol, volume, "Martingale", StopLoss, TakeProfit); if (result.Error == ErrorCode.NoMoney) Stop(); } private void OnPositionsClosed(PositionClosedEventArgs args) { Print("Closed"); var position = args.Position; if (position.Label != "Martingale" || position.SymbolCode != Symbol.Code) return; if (position.GrossProfit > 0) { ExecuteOrder(InitialVolume, GetRandomTradeType()); } else { ExecuteOrder(getNewVolume((int)position.Volume), position.TradeType); } } private int getNewVolume(int posVol) { var newVol = posVol * 2; newVol = Math.Min(newVol, maxBet); if (newVol == maxBet) newVol = InitialVolume; Print("newVol = {0}", newVol); return newVol; } private TradeType GetRandomTradeType() { return random.Next(2) == 0 ? TradeType.Buy : TradeType.Sell; } } }


@alibuc

alibuc
24 Oct 2014, 15:19

Something like this? // ------------------------------------------------------------------------------------------------- // // This code is a cAlgo API sample. // // This cBot is intended to be used as a sample and does not guarantee any particular outcome or // profit of any kind. Use it at your own risk // // The "Sample Martingale cBot" creates a random Sell or Buy order. If the Stop loss is hit, a new // order of the same type (Buy / Sell) is created with double the Initial Volume amount. The cBot will // continue to double the volume amount for all orders created until one of them hits the take Profit. // After a Take Profit is hit, a new random Buy or Sell order is created with the Initial Volume amount. // // ------------------------------------------------------------------------------------------------- using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class ab_Martingale : Robot { [Parameter("Initial Volume", DefaultValue = 1000, MinValue = 0)] public int InitialVolume { get; set; } [Parameter("Stop Loss", DefaultValue = 40)] public int StopLoss { get; set; } [Parameter("Take Profit", DefaultValue = 40)] public int TakeProfit { get; set; } [Parameter("Max Bet", DefaultValue = 50000)] public int maxBet { get; set; } private Random random = new Random(); protected override void OnStart() { Positions.Closed += OnPositionsClosed; ExecuteOrder(InitialVolume, GetRandomTradeType()); } private void ExecuteOrder(long volume, TradeType tradeType) { var result = ExecuteMarketOrder(tradeType, Symbol, volume, "Martingale", StopLoss, TakeProfit); if (result.Error == ErrorCode.NoMoney) Stop(); } private void OnPositionsClosed(PositionClosedEventArgs args) { Print("Closed"); var position = args.Position; if (position.Label != "Martingale" || position.SymbolCode != Symbol.Code) return; if (position.GrossProfit > 0) { ExecuteOrder(InitialVolume, GetRandomTradeType()); } else { ExecuteOrder(getNewVolume((int)position.Volume), position.TradeType); } } private int getNewVolume(int posVol) { var newVol = posVol * 2; newVol = Math.Min(newVol, maxBet); if (newVol == maxBet) newVol = InitialVolume; Print("newVol = {0}", newVol); return newVol; } private TradeType GetRandomTradeType() { return random.Next(2) == 0 ? TradeType.Buy : TradeType.Sell; } } }
@alibuc

alibuc
20 Oct 2014, 01:29

RE:

Thanks for the reply, no virus yet.. I think that there was a problem with upstream proxy caching an old version of manifest file. After clearing cache cAlgo installs fine.

Regards,

Al

Spotware said:

 

It says "File, cAlgo.API.XML, has a different computed hash than specified in manifest". Please make sure that your PC is not infected by a virus.

 


@alibuc