SH
Topics
06 Feb 2016, 20:47
2945
3
16 Jul 2015, 18:27
3851
5
17 Jun 2015, 23:11
2953
2
19 May 2015, 05:26
4694
4
19 May 2015, 04:37
2246
2
16 May 2015, 06:49
2868
3
16 May 2015, 06:41
2581
3
30 Apr 2015, 05:46
3373
3
Replies
Shawn_Mapilot
19 May 2015, 00:24
RE:
tradermatrix said:
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 first_hand_written_code : Robot { //parameters [Parameter("MA Type")] public MovingAverageType MAType { get; set; } [Parameter()] public DataSeries SourceSeries { get; set; } [Parameter("Slow Periods", DefaultValue = 10)] public int SlowPeriods { get; set; } [Parameter("Fast Periods", DefaultValue = 5)] public int FastPeriods { get; set; } [Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01)] public double lots { get; set; } [Parameter("TakeProfitPips", DefaultValue = 200)] public int tp { get; set; } [Parameter("StopLossPips", DefaultValue = 30)] public int sl { get; set; } [Parameter("trigger ", DefaultValue = 0)] public int Trigger { get; set; } [Parameter("Trailing", DefaultValue = 0)] public int Trailing { get; set; } private MovingAverage slowMa; private MovingAverage fastMa; private const string label = "Trend Trailing"; protected override void OnStart() { fastMa = Indicators.MovingAverage(SourceSeries, FastPeriods, MAType); slowMa = Indicators.MovingAverage(SourceSeries, SlowPeriods, MAType); } protected override void OnTick() { TRAILING(); int volume = (int)(lots * 100000); //declaring variables during ticks var longPosition = Positions.Find(label, Symbol, TradeType.Buy); var shortPosition = Positions.Find(label, Symbol, TradeType.Sell); var currentSlowMa = slowMa.Result.Last(0); var currentFastMa = fastMa.Result.Last(0); var previousSlowMa = slowMa.Result.Last(1); var previousFastMa = fastMa.Result.Last(1); // when buy signal is called if (previousSlowMa > previousFastMa && currentSlowMa < currentFastMa && longPosition == null) { //if theres a short position in playy if (shortPosition != null) ClosePosition(shortPosition); ExecuteMarketOrder(TradeType.Buy, Symbol, volume, label, sl, tp); } //when short signal is called else if (previousSlowMa < previousFastMa && currentSlowMa > currentFastMa && shortPosition == null) { // if there are long positions in play if (longPosition != null) ClosePosition(longPosition); ExecuteMarketOrder(TradeType.Sell, Symbol, volume, label, sl, tp); } } private void TRAILING() { if (Trailing > 0 && Trigger > 0) { Position[] positions = Positions.FindAll(label, Symbol); foreach (Position position in positions) { if (position.TradeType == TradeType.Sell) { double distance = position.EntryPrice - Symbol.Ask; if (distance >= Trigger * Symbol.PipSize) { double newStopLossPrice = Symbol.Ask + Trailing * Symbol.PipSize; if (position.StopLoss == null || newStopLossPrice < position.StopLoss) { ModifyPosition(position, newStopLossPrice, position.TakeProfit); } } } else { double distance = Symbol.Bid - position.EntryPrice; if (distance >= Trigger * Symbol.PipSize) { double newStopLossPrice = Symbol.Bid - Trailing * Symbol.PipSize; if (position.StopLoss == null || newStopLossPrice > position.StopLoss) { ModifyPosition(position, newStopLossPrice, position.TakeProfit); } } } } } } } }good trades
Thank you :) !
@Shawn_Mapilot
Shawn_Mapilot
19 May 2015, 00:23
RE:
Waxy said:
Hello
You assign a label for each algorithm running, this way bots wont interfere each other.
Thank you :)
@Shawn_Mapilot
Shawn_Mapilot
17 Jul 2015, 07:19
thank you
@Shawn_Mapilot