SHARE
TWEET

Untitled

enheton Dec 13th, 2018 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Linq;
  3. using cAlgo.API;
  4. using cAlgo.API.Indicators;
  5. using cAlgo.API.Internals;
  6. using cAlgo.Indicators;
  7.  
  8. namespace cAlgo.Robots
  9. {
  10.     [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
  11.     public class MartingaleRobot : Robot
  12.     {
  13.         [Parameter("Initial Volume", DefaultValue = 1000, MinValue = 0)]
  14.         public int InitialVolume { get; set; }
  15.  
  16.         [Parameter("Stop Loss", DefaultValue = 10)]
  17.         public int StopLoss { get; set; }
  18.  
  19.         [Parameter("Take Profit", DefaultValue = 25)]
  20.         public int TakeProfit { get; set; }
  21.  
  22.         private Random random = new Random();
  23.  
  24.         protected override void OnStart()
  25.         {
  26.             Positions.Closed += OnPositionsClosed;
  27.  
  28.             ExecuteOrder(InitialVolume, GetRandomTradeType());
  29.         }
  30.  
  31.         private void ExecuteOrder(long volume, TradeType tradeType)
  32.         {
  33.             var result = ExecuteMarketOrder(tradeType, Symbol, volume, "Martingale", StopLoss, TakeProfit);
  34.  
  35.             if (result.Error == ErrorCode.NoMoney)
  36.                 Stop();
  37.         }
  38.  
  39.         private void OnPositionsClosed(PositionClosedEventArgs args)
  40.         {
  41.  
  42.  
  43.             Print("Closed");
  44.             var position = args.Position;
  45.  
  46.  
  47.             if (position.Label != "Martingale" || position.SymbolCode != Symbol.Code)
  48.                 return;
  49.  
  50.             if (position.GrossProfit > 0)
  51.             {
  52.                 ExecuteOrder(InitialVolume, GetRandomTradeType());
  53.             }
  54.             else
  55.             {
  56.                 ExecuteOrder((int)position.Volume * 2, position.TradeType);
  57.             }
  58.         }
  59.  
  60.         private TradeType GetRandomTradeType()
  61.         {
  62.             return random.Next(2) == 0 ? TradeType.Buy : TradeType.Sell;
  63.         }
  64.     }
  65. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top