Topics
Replies
tgjobscv
24 Apr 2019, 20:19
RE:
tradermatrix said:
look what interests you ..
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 Scalp : Robot { [Parameter("One Cancels Other", DefaultValue = true)] public bool Oco { get; set; } [Parameter("Initial Volume Stop Order ", DefaultValue = 10000)] public int InitialVolume { get; set; } [Parameter("distance pips", DefaultValue = 20)] public double PipsAway { get; set; } [Parameter("Stop Loss", DefaultValue = 20)] public double StopLoss { get; set; } [Parameter("Take Profit", DefaultValue = 20)] public double TakeProfit { get; set; } [Parameter("Start Automate", DefaultValue = true)] public bool StartAutomate3 { get; set; } protected override void OnStart() { string text = "Ssalp By TraderMatriX"; base.ChartObjects.DrawText("Scalp By TraderMatriX", text, StaticPosition.TopCenter, new Colors?(Colors.Lime)); StopOrders(); Positions.Closed += OnPositionsClosed1; Positions.Closed += OnPositionsClosed2; Positions.Opened += OnPositionOpened; } protected override void OnTick() { var netProfit = 0.0; foreach (var openedPosition in Positions) { netProfit += openedPosition.NetProfit + openedPosition.Commissions; } ChartObjects.DrawText("a", netProfit.ToString(), StaticPosition.BottomRight, new Colors?(Colors.Lime)); } private void StopOrders() { var sellOrderTargetPrice = Symbol.Bid - PipsAway * Symbol.PipSize; ChartObjects.DrawHorizontalLine("sell target", sellOrderTargetPrice, Colors.Lime, 1, LineStyle.Solid); PlaceStopOrder(TradeType.Sell, Symbol, InitialVolume, sellOrderTargetPrice, "Scalp", StopLoss, TakeProfit); var buyOrderTargetPrice = Symbol.Ask + PipsAway * Symbol.PipSize; ChartObjects.DrawHorizontalLine("buy target", buyOrderTargetPrice, Colors.Lime, 1, LineStyle.Solid); PlaceStopOrder(TradeType.Buy, Symbol, InitialVolume, buyOrderTargetPrice, "Scalp", StopLoss, TakeProfit); } private void OnPositionsClosed1(PositionClosedEventArgs args) { if (StartAutomate3 == true) { Print("Closed"); var position = args.Position; if (position.Label != "Scalp" || position.SymbolCode != Symbol.Code) return; StopOrders(); } } private void OnPositionsClosed2(PositionClosedEventArgs args) { if (StartAutomate3 == false) { Print("Closed"); var position = args.Position; if (position.Label != "Scalp" || position.SymbolCode != Symbol.Code) return; } } private void OnPositionOpened(PositionOpenedEventArgs args) { if (Oco == true) { var position = args.Position; if (position.Label == "Scalp" && position.SymbolCode == Symbol.Code) { foreach (var order in PendingOrders) { if (order.Label == "Scalp" && order.SymbolCode == Symbol.Code) { CancelPendingOrderAsync(order); ChartObjects.RemoveObject("sell target"); ChartObjects.RemoveObject("buy target"); } } } } } } }et aussi "FireBote" de breakermind
https://github.com/breakermind/cAlgoRobotsIndicators/blob/master/FireBot
1 //================================================================================ 2 // SimpleWeekRobo 3 // Start at Week start(Day start 00:00) 4 // (M15-M30 regression(2000,2,3)(1.8,2,2000)) 5 // 100Pips levels, suport or resistance 6 // Simple Monday-Friday script without any security with close when earn 7 // If CloseWhenEarn == 0 then dont close positions 8 // If TP or SL == 0 dont modifing positions 9 // If TrailingStop > 0 ==> BackStop == 0 10 // Multi positions yes or no 11 //================================================================================ 12 using System; 13 using cAlgo.API; 14 using cAlgo.API.Indicators; 15 using cAlgo.Indicators; 16 17 namespace cAlgo.Robots 18 { 19 [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)] 20 public class Fire : Robot 21 { 22 //================================================================================ 23 // Parametrs 24 //================================================================================ 25 26 private Position _position; 27 private double WeekStart; 28 private double LastProfit = 0; 29 private double StopMoneyLoss = 0; 30 31 [Parameter(DefaultValue = true)] 32 public bool SetBUY { get; set; } 33 34 [Parameter(DefaultValue = true)] 35 public bool SetSELL { get; set; } 36 37 [Parameter(DefaultValue = 300000, MinValue = 1000)] 38 public int Volume { get; set; } 39 40 [Parameter(DefaultValue = true)] 41 public bool MultiVolume { get; set; } 42 43 [Parameter(DefaultValue = 10, MinValue = 5)] 44 public int Spacing { get; set; } 45 46 [Parameter(DefaultValue = 30, MinValue = 1)] 47 public int HowMuchPositions { get; set; } 48 49 [Parameter("TakeProfitPips", DefaultValue = 0, MinValue = 0)] 50 public int TP { get; set; } 51 52 [Parameter("StopLossPips", DefaultValue = 0, MinValue = 0)] 53 public int SL { get; set; } 54 55 [Parameter(DefaultValue = 0, MinValue = 0)] 56 public int BackStop { get; set; } 57 58 [Parameter(DefaultValue = 5, MinValue = 0)] 59 public int BackStopValue { get; set; } 60 61 [Parameter(DefaultValue = 0, MinValue = 0)] 62 public int TrailingStop { get; set; } 63 64 // close when earn 65 [Parameter(DefaultValue = 0, MinValue = 0)] 66 public int CloseWhenEarn { get; set; } 67 68 // safe deposit works when earn 100% 69 [Parameter(DefaultValue = false)] 70 public bool MoneyStopLossOn { get; set; } 71 72 [Parameter(DefaultValue = 1000, MinValue = 100)] 73 public int StartDeposit { get; set; } 74 75 [Parameter(DefaultValue = 50, MinValue = 10, MaxValue = 100)] 76 public int StopLossPercent { get; set; } 77 78 [Parameter(DefaultValue = 2, MinValue = 1, MaxValue = 100)] 79 public int OnWhenDepositX { get; set; } 80 81 82 private int Multi = 0; 83 private int VolumeBuy = 0; 84 private int VolumeSell = 0; 85 //================================================================================ 86 // OnStart 87 //================================================================================ 88 protected override void OnStart() 89 { 90 VolumeSell = Volume; 91 VolumeBuy = Volume; 92 WeekStart = Symbol.Ask; 93 94 // set pending up(BUY) 95 if (SetBUY) 96 { 97 for (int i = 1; i < HowMuchPositions; i++) 98 { 99 100 Multi = Multi + Spacing; 101 if (MultiVolume == true) 102 { 103 if (Multi > 100) 104 { 105 VolumeBuy = VolumeBuy + Volume; 106 } 107 if (Multi > 200) 108 { 109 VolumeBuy = VolumeBuy + Volume; 110 } 111 if (Multi > 300) 112 { 113 VolumeBuy = VolumeBuy + Volume; 114 } 115 } 116 PlaceStopOrder(TradeType.Buy, Symbol, VolumeBuy, Symbol.Ask + Spacing * i * Symbol.PipSize); 117 } 118 } 119 120 // set pending down(SELL) 121 if (SetSELL) 122 { 123 Multi = 0; 124 for (int j = 1; j < HowMuchPositions; j++) 125 { 126 127 Multi = Multi + Spacing; 128 if (MultiVolume == true) 129 { 130 if (Multi > 100) 131 { 132 VolumeSell = VolumeSell + Volume; 133 } 134 if (Multi > 200) 135 { 136 VolumeSell = VolumeSell + Volume; 137 } 138 if (Multi > 300) 139 { 140 VolumeSell = VolumeSell + Volume; 141 } 142 } 143 PlaceStopOrder(TradeType.Sell, Symbol, VolumeSell, Symbol.Bid - Spacing * j * Symbol.PipSize); 144 } 145 } 146 } 147 148 //================================================================================ 149 // OnTick 150 //================================================================================ 151 protected override void OnTick() 152 { 153 var netProfit = 0.0; 154 155 // Take profit 156 if (TP > 0) 157 { 158 foreach (var position in Positions) 159 { 160 161 // Modifing position tp 162 if (position.TakeProfit == null) 163 { 164 Print("Modifying {0}", position.Id); 165 ModifyPosition(position, position.StopLoss, GetAbsoluteTakeProfit(position, TP)); 166 } 167 168 } 169 170 } 171 172 // Stop loss 173 if (SL > 0) 174 { 175 foreach (var position in Positions) 176 { 177 178 // Modifing position sl and tp 179 if (position.StopLoss == null) 180 { 181 Print("Modifying {0}", position.Id); 182 ModifyPosition(position, GetAbsoluteStopLoss(position, SL), position.TakeProfit); 183 } 184 185 } 186 187 } 188 189 190 191 foreach (var openedPosition in Positions) 192 { 193 netProfit += openedPosition.NetProfit; 194 } 195 196 if (MoneyStopLossOn == true) 197 { 198 // safe deposit works when earn 100% 199 if (LastProfit < Account.Equity && Account.Equity > StartDeposit * OnWhenDepositX) 200 { 201 LastProfit = Account.Equity; 202 } 203 204 if (Account.Equity > StartDeposit * 3) 205 { 206 //StopLossPercent = 90; 207 } 208 209 StopMoneyLoss = LastProfit * (StopLossPercent * 0.01); 210 Print("LastProfit: ", LastProfit); 211 Print("Equity: ", Account.Equity); 212 Print("StopLossMoney: ", StopMoneyLoss); 213 214 if (Account.Equity < StopMoneyLoss) 215 { 216 //open orders 217 foreach (var openedPosition in Positions) 218 { 219 ClosePosition(openedPosition); 220 } 221 // pending orders 222 foreach (var order in PendingOrders) 223 { 224 CancelPendingOrder(order); 225 } 226 Stop(); 227 } 228 } 229 230 if (netProfit >= CloseWhenEarn && CloseWhenEarn > 0) 231 { 232 // open orders 233 foreach (var openedPosition in Positions) 234 { 235 ClosePosition(openedPosition); 236 } 237 // pending orders 238 foreach (var order in PendingOrders) 239 { 240 CancelPendingOrder(order); 241 } 242 Stop(); 243 } 244 245 246 //===================================================== Back Trailing 247 if (BackStop > 0) 248 { 249 foreach (var openedPosition in Positions) 250 { 251 Position Position = openedPosition; 252 if (Position.TradeType == TradeType.Buy) 253 { 254 double distance = Symbol.Bid - Position.EntryPrice; 255 256 if (distance >= BackStop * Symbol.PipSize) 257 { 258 double newStopLossPrice = Math.Round(Symbol.Bid - BackStopValue * Symbol.PipSize, Symbol.Digits); 259 260 if (Position.StopLoss == null) 261 { 262 ModifyPosition(Position, newStopLossPrice, Position.TakeProfit); 263 } 264 } 265 } 266 else 267 { 268 double distance = Position.EntryPrice - Symbol.Ask; 269 270 if (distance >= BackStop * Symbol.PipSize) 271 { 272 273 double newStopLossPrice = Math.Round(Symbol.Ask + BackStopValue * Symbol.PipSize, Symbol.Digits); 274 275 if (Position.StopLoss == null) 276 { 277 ModifyPosition(Position, newStopLossPrice, Position.TakeProfit); 278 } 279 } 280 } 281 } 282 } 283 284 //===================================================== Trailing 285 if (TrailingStop > 0 && BackStop == 0) 286 { 287 foreach (var openedPosition in Positions) 288 { 289 Position Position = openedPosition; 290 if (Position.TradeType == TradeType.Buy) 291 { 292 double distance = Symbol.Bid - Position.EntryPrice; 293 294 if (distance >= TrailingStop * Symbol.PipSize) 295 { 296 double newStopLossPrice = Math.Round(Symbol.Bid - TrailingStop * Symbol.PipSize, Symbol.Digits); 297 298 if (Position.StopLoss == null || newStopLossPrice > Position.StopLoss) 299 { 300 ModifyPosition(Position, newStopLossPrice, Position.TakeProfit); 301 } 302 } 303 } 304 else 305 { 306 double distance = Position.EntryPrice - Symbol.Ask; 307 308 if (distance >= TrailingStop * Symbol.PipSize) 309 { 310 311 double newStopLossPrice = Math.Round(Symbol.Ask + TrailingStop * Symbol.PipSize, Symbol.Digits); 312 313 if (Position.StopLoss == null || newStopLossPrice < Position.StopLoss) 314 { 315 ModifyPosition(Position, newStopLossPrice, Position.TakeProfit); 316 } 317 } 318 } 319 } 320 } 321 322 323 324 325 326 327 328 329 330 } 331 332 //================================================================================ 333 // OnPositionOpened 334 //================================================================================ 335 protected override void OnPositionOpened(Position openedPosition) 336 { 337 int BuyPos = 0; 338 int SellPos = 0; 339 340 foreach (var position in Positions) 341 { 342 // Count opened positions 343 if (position.TradeType == TradeType.Buy) 344 { 345 BuyPos = BuyPos + 1; 346 } 347 if (position.TradeType == TradeType.Sell) 348 { 349 SellPos = SellPos + 1; 350 } 351 } 352 353 Print("All Buy positions: " + BuyPos); 354 Print("All Sell positions: " + SellPos); 355 356 357 } 358 // end OnPositionOpened 359 360 //================================================================================ 361 // OnBar 362 //================================================================================ 363 protected override void OnBar() 364 { 365 366 } 367 //================================================================================ 368 // OnPositionClosed 369 //================================================================================ 370 protected override void OnPositionClosed(Position closedPosition) 371 { 372 373 } 374 375 //================================================================================ 376 // OnStop 377 //================================================================================ 378 protected override void OnStop() 379 { 380 381 } 382 383 //================================================================================ 384 // Function 385 //================================================================================ 386 private void Buy() 387 { 388 ExecuteMarketOrder(TradeType.Buy, Symbol, 10000, "", 1000, 1000); 389 } 390 391 private void Sell() 392 { 393 ExecuteMarketOrder(TradeType.Sell, Symbol, 10000, "", 1000, 1000); 394 } 395 396 private void ClosePosition() 397 { 398 if (_position != null) 399 { 400 ClosePosition(_position); 401 _position = null; 402 } 403 } 404 405 406 //================================================================================ 407 // modify SL and TP 408 //================================================================================ 409 private double GetAbsoluteStopLoss(Position position, int stopLossInPips) 410 { 411 //Symbol Symbol = MarketData.GetSymbol(position.SymbolCode); 412 return position.TradeType == TradeType.Buy ? position.EntryPrice - (Symbol.PipSize * stopLossInPips) : position.EntryPrice + (Symbol.PipSize * stopLossInPips); 413 } 414 415 private double GetAbsoluteTakeProfit(Position position, int takeProfitInPips) 416 { 417 //Symbol Symbol = MarketData.GetSymbol(position.SymbolCode); 418 return position.TradeType == TradeType.Buy ? position.EntryPrice + (Symbol.PipSize * takeProfitInPips) : position.EntryPrice - (Symbol.PipSize * takeProfitInPips); 419 } 420 //================================================================================ 421 // Robot end 422 //================================================================================ 423 } 424 }
Error CS0116: A namespace cannot directly contain members such as fields or methods
errors 83
@tgjobscv
tgjobscv
15 Mar 2019, 13:37
PLATFORM VERSION INFO
Windows : 6.1.7601.65536 (Win32NT)
Common Language Runtime : 4.0.30319.42000
System.Deployment.dll : 4.7.3221.0 built by: NET472REL1LAST_C
clr.dll : 4.7.3324.0 built by: NET472REL1LAST_C
dfdll.dll : 4.7.3221.0 built by: NET472REL1LAST_C
dfshim.dll : 4.0.41209.0 (Main.041209-0000)
SOURCES
Deployment url : http://pepperstoneuk.ctrader.com/xTrader.application?/currentApplication=%22Automate%22
ERROR SUMMARY
Below is a summary of the errors, details of these errors are listed later in the log.
* Activation of http://pepperstoneuk.ctrader.com/xTrader.application?/currentApplication="Automate" resulted in exception. Following failure messages were detected:
+ Downloading http://pepperstoneuk.ctrader.com/xTrader.application?/currentApplication="Automate" did not succeed.
+ Unable to connect to the remote server
+ No connection could be made because the target machine actively refused it 127.0.0.1:4444
COMPONENT STORE TRANSACTION FAILURE SUMMARY
No transaction error was detected.
WARNINGS
There were no warnings during this operation.
OPERATION PROGRESS STATUS
* [3/14/2019 11:31:20 PM] : Activation of http://pepperstoneuk.ctrader.com/xTrader.application?/currentApplication="Automate" has started.
ERROR DETAILS
Following errors were detected during this operation.
* [3/14/2019 11:31:21 PM] System.Deployment.Application.DeploymentDownloadException (Unknown subtype)
- Downloading http://pepperstoneuk.ctrader.com/xTrader.application?/currentApplication="Automate" did not succeed.
- Source: System.Deployment
- Stack trace:
at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)
at System.Deployment.Application.SystemNetDownloader.DownloadAllFiles()
at System.Deployment.Application.FileDownloader.Download(SubscriptionState subState, X509Certificate2 clientCertificate)
at System.Deployment.Application.DownloadManager.DownloadManifestAsRawFile(Uri& sourceUri, String targetPath, IDownloadNotification notification, DownloadOptions options, ServerInformation& serverInformation)
at System.Deployment.Application.DownloadManager.DownloadDeploymentManifestDirectBypass(SubscriptionStore subStore, Uri& sourceUri, TempFile& tempFile, SubscriptionState& subState, IDownloadNotification notification, DownloadOptions options, ServerInformation& serverInformation)
at System.Deployment.Application.DownloadManager.DownloadDeploymentManifestBypass(SubscriptionStore subStore, Uri& sourceUri, TempFile& tempFile, SubscriptionState& subState, IDownloadNotification notification, DownloadOptions options)
at System.Deployment.Application.ApplicationActivator.PerformDeploymentActivation(Uri activationUri, Boolean isShortcut, String textualSubId, String deploymentProviderUrlFromExtension, BrowserSettings browserSettings, String& errorPageUrl, Uri& deploymentUri)
at System.Deployment.Application.ApplicationActivator.PerformDeploymentActivationWithRetry(Uri activationUri, Boolean isShortcut, String textualSubId, String deploymentProviderUrlFromExtension, BrowserSettings browserSettings, String& errorPageUrl)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Deployment.Application.ApplicationActivator.PerformDeploymentActivationWithRetry(Uri activationUri, Boolean isShortcut, String textualSubId, String deploymentProviderUrlFromExtension, BrowserSettings browserSettings, String& errorPageUrl)
at System.Deployment.Application.ApplicationActivator.ActivateDeploymentWorker(Object state)
--- Inner Exception ---
System.Net.WebException
- Unable to connect to the remote server
- Source: System
- Stack trace:
at System.Net.HttpWebRequest.GetResponse()
at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)
--- Inner Exception ---
System.Net.Sockets.SocketException
- No connection could be made because the target machine actively refused it 127.0.0.1:4444
- Source: System
- Stack trace:
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
COMPONENT STORE TRANSACTION DETAILS
No transaction information is available.
@tgjobscv
tgjobscv
06 May 2019, 21:40
This is Wiwdows error number. Thanks for support.
@tgjobscv