Menu
Brokers
MT4 Forex Brokers
MT5 Forex brokers
PayPal Brokers
Skrill Brokers
Oil Trading Brokers
Gold Trading Brokers
Web Browser Platform
Brokers with CFD Trading
ECN Brokers
Bitcoin FX Brokers
PAMM Forex Brokers
With Cent Accounts
With High Leverage
Cryptocurrency Brokers
Forums
All threads
New threads
New posts
Trending
Search forums
What's new
New threads
New posts
Latest activity
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Reply to thread
Forums
Trading Platforms
Other Trading Platforms
C TRADER
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
[QUOTE="farid_ava, post: 224359, member: 111831"] How can we set multiple Take Profits with different volumes on cTrader newstrader [B]cbot [/B]? For example I have a 1 lot postion on EurUsd. I want to set Muliple Take Profits as following: 0.5 lots at 10 pips profit. 0.2 lots at 20 pips profit. and so on. [B]I have these instructions but I don't know how to put them in newstrader [B]cbot[/B]. Thank you for helping me.[/B] using cAlgo.API; using System; using System.Collections.Generic; [CODE=c]namespace cAlgo.Robots { /// <summary> /// Allows setting multiple take profit levels for positions /// Set a take profit volume parameter value to 0 if you don't want to use it /// </summary> [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class MultiTPBot : Robot { private double _firstTakeProfitVolumeInUnits; private double _secondTakeProfitVolumeInUnits; private double _thirdTakeProfitVolumeInUnits; private double _fourthTakeProfitVolumeInUnits; private List<long> _firstTakeProfitTriggeredPositionIds = new List<long>(); private List<long> _secondTakeProfitTriggeredPositionIds = new List<long>(); private List<long> _thirdTakeProfitTriggeredPositionIds = new List<long>(); private List<long> _fourthTakeProfitTriggeredPositionIds = new List<long>(); [Parameter("1st TP", DefaultValue = 0.01, MinValue = 0, Group = "Volume (Lots)")] public double FirstTakePrfitVolumeInLots { get; set; } [Parameter("2nd TP", DefaultValue = 0.03, MinValue = 0, Group = "Volume (Lots)")] public double SecondTakePrfitVolumeInLots { get; set; } [Parameter("3rd TP", DefaultValue = 0.05, MinValue = 0, Group = "Volume (Lots)")] public double ThirdTakePrfitVolumeInLots { get; set; } [Parameter("4th TP", DefaultValue = 0.1, MinValue = 0, Group = "Volume (Lots)")] public double FourthTakePrfitVolumeInLots { get; set; } [Parameter("1st TP", DefaultValue = 10, MinValue = 0, Group = "Pips")] public double FirstTakePrfitPips { get; set; } [Parameter("2nd TP", DefaultValue = 20, MinValue = 0, Group = "Pips")] public double SecondTakePrfitPips { get; set; } [Parameter("3rd TP", DefaultValue = 30, MinValue = 0, Group = "Pips")] public double ThirdTakePrfitPips { get; set; } [Parameter("4th TP", DefaultValue = 40, MinValue = 0, Group = "Pips")] public double FourthTakePrfitPips { get; set; } protected override void OnStart() { _firstTakeProfitVolumeInUnits = Symbol.QuantityToVolumeInUnits(FirstTakePrfitVolumeInLots); _secondTakeProfitVolumeInUnits = Symbol.QuantityToVolumeInUnits(SecondTakePrfitVolumeInLots); _thirdTakeProfitVolumeInUnits = Symbol.QuantityToVolumeInUnits(ThirdTakePrfitVolumeInLots); _fourthTakeProfitVolumeInUnits = Symbol.QuantityToVolumeInUnits(FourthTakePrfitVolumeInLots); } protected override void OnTick() { foreach (var position in Positions) { if (!position.SymbolName.Equals(SymbolName, StringComparison.OrdinalIgnoreCase)) continue; TriggerTakeProfitIfReached(position, _firstTakeProfitVolumeInUnits, FirstTakePrfitPips, _firstTakeProfitTriggeredPositionIds); TriggerTakeProfitIfReached(position, _secondTakeProfitVolumeInUnits, SecondTakePrfitPips, _secondTakeProfitTriggeredPositionIds); TriggerTakeProfitIfReached(position, _thirdTakeProfitVolumeInUnits, ThirdTakePrfitPips, _thirdTakeProfitTriggeredPositionIds); TriggerTakeProfitIfReached(position, _fourthTakeProfitVolumeInUnits, FourthTakePrfitPips, _fourthTakeProfitTriggeredPositionIds); } } private void ModifyPositionVolume(Position position, double newVolume) { if (position.VolumeInUnits > newVolume) { ModifyPosition(position, newVolume); } else { ClosePosition(position); } } private void TriggerTakeProfitIfReached(Position position, double takeProfitVolumeInUnits, double takeProfitPips, List<long> triggeredPositionIds) { if (triggeredPositionIds.Contains(position.Id)) return; if (takeProfitVolumeInUnits > 0 && position.Pips >= takeProfitPips) { triggeredPositionIds.Add(position.Id); ModifyPositionVolume(position, position.VolumeInUnits - takeProfitVolumeInUnits); } } } }[/CODE] [/QUOTE]
Insert quotes…
Verification
Post reply
Top
Bottom
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…