Trailing Stop Loss with Trailing Distance

Trailing Stop Loss with Trailing Distance
17 Jul 2017, 00:00
This robot 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.
// ------------------------------------------------------------------------------------------------- // // This robot 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 "Trailing Stop Loss Sample" Robot places a Buy or Sell Market order according to user input. // When the order is filled it implements trailing stop loss. // // ------------------------------------------------------------------------------------------------- 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 TrailingStopLossSample : Robot { [Parameter("Volume", DefaultValue = 1000)] public int Volume { get; set; } [Parameter("Buy")] public bool Buy { get; set; } [Parameter("Stop Loss", DefaultValue = 5)] public double StopLoss { get; set; } [Parameter("Trigger When Gaining", DefaultValue = 1)] public double TriggerWhenGaining { get; set; } [Parameter("Trailing Stop Loss Distance", DefaultValue = 1)] public double TrailingStopLossDistance { get; set; } private double _highestGain; private bool _isTrailing; protected override void OnStart() { //Execute a market order based on the direction parameter ExecuteMarketOrder(Buy ? TradeType.Buy : TradeType.Sell, Symbol, Volume, "SampleTrailing", StopLoss, null); //Set the position's highest gain in pips _highestGain = Positions[0].Pips; } protected override void OnTick() { var position = Positions.Find("SampleTrailing"); if (position == null) { Stop(); return; } //If the trigger is reached, the robot starts trailing if (!_isTrailing && position.Pips >= TriggerWhenGaining) { _isTrailing = true; } //If the cBot is trailing and the profit in pips is at the highest level, we need to readjust the stop loss if (_isTrailing && _highestGain < position.Pips) { //Based on the position's direction, we calculate the new stop loss price and we modify the position if (position.TradeType == TradeType.Buy) { var newSLprice = Symbol.Ask - (Symbol.PipSize * TrailingStopLossDistance); if (newSLprice > position.StopLoss) { ModifyPosition(position, newSLprice, null); } } else { var newSLprice = Symbol.Bid + (Symbol.PipSize * TrailingStopLossDistance); if (newSLprice < position.StopLoss) { ModifyPosition(position, newSLprice, null); } } //We reset the highest gain _highestGain = position.Pips; } } protected override void OnStop() { // Put your deinitialization logic here } } }
Replies
Drummond360
04 Jan 2018, 20:18
Could you please explain why you use PipValue to calculate the trailing stop distance instead of PipSize?
var newSLprice = Symbol.Ask - (Symbol.PipValue * TrailingStopLossDistance);
I've implemented this but am getting the error TRADING_BAD_STOPS
@Drummond360
Jan
20 Nov 2019, 23:56
Trailing Stop Loss with Trailing Distance and Step
Hello,
thank you for the example. It is really valuable to get these examples here, especially for a beginner programmer like myself.
It would be great if you could show how to add a "STEP to the trailing stop. More often than not, it is not necessary to update the trailing stop on every tick advanced to the trade's direction and it would save a lot of resources to add a "STEP" to the trail, so that the trailing stop is only updated when price has moved the "STEP" amount to profit.
Below is my version of a trailing stop function (stop is trailing a custom indicator value : maketemaExit(1) )
private void SetT3ExitTrailingStop() { var sellPositions = Positions.FindAll(InstanceName, Symbol, TradeType.Sell); foreach (Position position in sellPositions) { double distance = position.EntryPrice - maketemaExit(1); if (distance < MinT3DistanceExit * Symbol.PipSize) continue; double newStopLossPrice = maketemaExit(1) + T3StopFromLineExit * Symbol.PipSize; if (position.StopLoss == null || newStopLossPrice < position.StopLoss) { ModifyPosition(position, newStopLossPrice, position.TakeProfit); } } var buyPositions = Positions.FindAll(InstanceName, Symbol, TradeType.Buy); foreach (Position position in buyPositions) { double distance = maketemaExit(1) - position.EntryPrice; if (distance < MinT3DistanceExit * Symbol.PipSize) continue; double newStopLossPrice = maketemaExit(1) - T3StopFromLineExit * Symbol.PipSize; if (position.StopLoss == null || newStopLossPrice > position.StopLoss) { ModifyPosition(position, newStopLossPrice, position.TakeProfit); } } }
@jani
Panagiotis Charalampous
21 Nov 2019, 12:01
Hi Jan,
See the example below
// ------------------------------------------------------------------------------------------------- // // This robot 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 "Trailing Stop Loss Sample" Robot places a Buy or Sell Market order according to user input. // When the order is filled it implements trailing stop loss. // // ------------------------------------------------------------------------------------------------- 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 TrailingStopLossSample : Robot { [Parameter("Volume", DefaultValue = 1000)] public int Volume { get; set; } [Parameter("Buy")] public bool Buy { get; set; } [Parameter("Stop Loss", DefaultValue = 5)] public double StopLoss { get; set; } [Parameter("Trigger When Gaining", DefaultValue = 1)] public double TriggerWhenGaining { get; set; } [Parameter("Trailing Stop Loss Distance", DefaultValue = 1)] public double TrailingStopLossDistance { get; set; } [Parameter("Step (pips)", DefaultValue = 5)] public double Step { get; set; } private double _highestGain; private bool _isTrailing; protected override void OnStart() { //Execute a market order based on the direction parameter ExecuteMarketOrder(Buy ? TradeType.Buy : TradeType.Sell, Symbol, Volume, "SampleTrailing", StopLoss, null); //Set the position's highest gain in pips _highestGain = Positions[0].Pips; } protected override void OnTick() { var position = Positions.Find("SampleTrailing"); if (position == null) { Stop(); return; } //If the trigger is reached, the robot starts trailing if (position.Pips >= TriggerWhenGaining) { //Based on the position's direction, we calculate the new stop loss price and we modify the position if (position.TradeType == TradeType.Buy) { var newSLprice = Symbol.Ask - (Symbol.PipSize * TrailingStopLossDistance); if (newSLprice > position.StopLoss) { ModifyPosition(position, newSLprice, null); } } else { var newSLprice = Symbol.Bid + (Symbol.PipSize * TrailingStopLossDistance); if (newSLprice < position.StopLoss) { ModifyPosition(position, newSLprice, null); } } TriggerWhenGaining += Step; } } protected override void OnStop() { // Put your deinitialization logic here } } }
Best Regards,
Panagiotis
@PanagiotisCharalampous
Ben Floyd
01 Feb 2020, 16:28
Is this not available in API already
Hi,
The documentation says
public TradeResult ExecuteMarketOrder(TradeType tradeType, string symbolName, double volume, string label, double? stopLossPips, double? takeProfitPips, string comment, bool hasTrailingStop)
So it seems by setting the last boolean parameter to true cAlgo will implement the trailing stop loss so I am not able to understand in which situation will one need to use the code that is provided in this thread.
Please let me know.
Thanks in advance,
Warm Regards,
Vipin.
PanagiotisCharalampous said:
Hi Jan,
See the example below
// ------------------------------------------------------------------------------------------------- // // This robot 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 "Trailing Stop Loss Sample" Robot places a Buy or Sell Market order according to user input. // When the order is filled it implements trailing stop loss. // // ------------------------------------------------------------------------------------------------- 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 TrailingStopLossSample : Robot { [Parameter("Volume", DefaultValue = 1000)] public int Volume { get; set; } [Parameter("Buy")] public bool Buy { get; set; } [Parameter("Stop Loss", DefaultValue = 5)] public double StopLoss { get; set; } [Parameter("Trigger When Gaining", DefaultValue = 1)] public double TriggerWhenGaining { get; set; } [Parameter("Trailing Stop Loss Distance", DefaultValue = 1)] public double TrailingStopLossDistance { get; set; } [Parameter("Step (pips)", DefaultValue = 5)] public double Step { get; set; } private double _highestGain; private bool _isTrailing; protected override void OnStart() { //Execute a market order based on the direction parameter ExecuteMarketOrder(Buy ? TradeType.Buy : TradeType.Sell, Symbol, Volume, "SampleTrailing", StopLoss, null); //Set the position's highest gain in pips _highestGain = Positions[0].Pips; } protected override void OnTick() { var position = Positions.Find("SampleTrailing"); if (position == null) { Stop(); return; } //If the trigger is reached, the robot starts trailing if (position.Pips >= TriggerWhenGaining) { //Based on the position's direction, we calculate the new stop loss price and we modify the position if (position.TradeType == TradeType.Buy) { var newSLprice = Symbol.Ask - (Symbol.PipSize * TrailingStopLossDistance); if (newSLprice > position.StopLoss) { ModifyPosition(position, newSLprice, null); } } else { var newSLprice = Symbol.Bid + (Symbol.PipSize * TrailingStopLossDistance); if (newSLprice < position.StopLoss) { ModifyPosition(position, newSLprice, null); } } TriggerWhenGaining += Step; } } protected override void OnStop() { // Put your deinitialization logic here } } }Best Regards,
Panagiotis
@driftingprogrammer
Panagiotis Charalampous
03 Feb 2020, 09:36
Hi driftingprogrammer,
The built-in TSL does not allow you to set a trigger distance for your trailing stop loss. It starts trailing immediately. This sample does (TriggerWhenGaining parameter).
Best Regards,
Panagiotis
@PanagiotisCharalampous
Jan
08 Feb 2020, 23:31
RE:
Hi Panagiotis ,
thanks for your message, sorry a bit late reply from me...
if I understood correctly
if (position.Pips >= TriggerWhenGaining)
Allow trailing to start if EITHER buy or sell position is in profit for more than TriggerWhenGaining ?,
Say we use Step=5 and buy has moved to Step but Sell only halfway, if (position.Pips >= TriggerWhenGaining) would allow also the Sell stop to be moved/trailed even though it has not yet reached the step, am I correct?
Do you think this would work?
private void SetMultiMaTrailingStop()
{
var sellPositions = Positions.FindAll(InstanceName, SymbolName, TradeType.Sell);
foreach (Position position in sellPositions)
{
double distance = position.EntryPrice - neutral1;
if (distance < BuyTriggerWhenGaining)
continue;
BuyTriggerWhenGaining += Step * Symbol.PipSize;
double newStopLossPrice = neutral1 + T3StopFromLineExit * Symbol.PipSize;
if (position.StopLoss == null || newStopLossPrice < position.StopLoss)
{
ModifyPosition(position, newStopLossPrice, position.TakeProfit);
}
BuyTriggerWhenGaining += Step * Symbol.PipSize;
}
//---------
var buyPositions = Positions.FindAll(InstanceName, SymbolName, TradeType.Buy);
foreach (Position position in buyPositions)
{
double distance = neutral1 - position.EntryPrice;
if (distance < SellTriggerWhenGaining)
continue;
double newStopLossPrice = neutral1 - T3StopFromLineExit * Symbol.PipSize;
if (position.StopLoss == null || newStopLossPrice > position.StopLoss)
{
ModifyPosition(position, newStopLossPrice, position.TakeProfit);
}
SellTriggerWhenGaining += Step * Symbol.PipSize;
}
}
Step feature is a bit hard to verify by backtesting, but I think I was getting the correct results.....
@jani
Panagiotis Charalampous
10 Feb 2020, 08:34
Hi Jan,
Say we use Step=5 and buy has moved to Step but Sell only halfway, if (position.Pips >= TriggerWhenGaining) would allow also the Sell stop to be moved/trailed even though it has not yet reached the step, am I correct?
I am not sure how you came to this conclusion but seems wrong. Can you please explain? The cBot is designed to trigger a TSL only for one position as soon as it has reached the trigger level. If you want to use it on multiple positions. then you will need to have multiple instances with multiple labels. Each instance should be independent and not affect other positions.
Best Regards,
Panagiotis
@PanagiotisCharalampous
Jan
10 Feb 2020, 19:17
RE:
thanks for your reply.
I was only referring to the same instance having concurrent buy & sell open positions. I think I would need to better understand how
Positions.Find(...)
API function is treating each individual Buy and Sell position.
I was assuming that it would find any position and if the condition
if (position.Pips >= TriggerWhenGaining)
would be true, if either Sell OR Buy position were satisfying the "TriggerWhenGaining" condition. And therefore for example when Buy side qualify "TriggerWhenGaining" condition it would let the logic also to update Sell side stop without the step condition being met? ..or perhaps I have some syntax error in my thought process...LOL
@jani
Panagiotis Charalampous
11 Feb 2020, 08:19
Hi Jan,
Positions.Find will only return one position matching the label. There are several changes that you need to make to this example in order to be adapted to handle any number of positions. For example, you will need to track a separate TriggerWhenGaining for each position, maybe with the use of a dictionary.
Best Regards,
Panagiotis
@PanagiotisCharalampous
Abdulhamid Yusuf
07 Apr 2020, 16:05
Simple and robust trailing algorithm
I came here to see how to implement a trailing stop loss, but the code provided by cTrader Team was unnecessarily complicated to me, so I would like to share my way ...
using cAlgo.API;
using System.Collections.Generic;
using System.Linq;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class TestTrailingStop : Robot
{
// Save the maximum winning pips each position has reached
private Dictionary<Position, double> PositionsMaxProfits;
[Parameter("Winning Pips to protect", DefaultValue = 10)]
public int PipsToProtect { get; set; }
[Parameter("Trailing Stop Distance", DefaultValue = 5)]
public int TrailingDistance { get; set; }
protected override void OnStart()
{
PositionsMaxProfits = new Dictionary<Position, double>();
// Market order for illustration purposes
var p = ExecuteMarketOrder(TradeType.Sell, SymbolName, 1000).Position;
// Add every order you create to the dictionary and set its initial max pips to 0
PositionsMaxProfits.Add(p, 0);
}
protected override void OnTick()
{
// Update Stop loss on each tick once the position has yeilded winning pips >= PipsToProtect + TrailingDistance
foreach (Position position in PositionsMaxProfits.Keys.ToList())
{
var positionMaxProfit = PositionsMaxProfits[position];
// 1st condition checks if winning pips >= PipsToProtect + TrailingDistance
// 2ed condition checks if winning pips is greater than previous winning pips
if ((position.Pips >= PipsToProtect + TrailingDistance) && position.Pips > positionMaxProfit)
{
// Assign the new higher winning pips to the position
PositionsMaxProfits[position] = position.Pips;
// Modify Stop loss to be $TrailingDistance pips away from current winnig pips
// ** -1 means put stop loss on oppostie direction than normal
position.ModifyStopLossPips(-1 * (position.Pips - TrailingDistance));
}
}
}
}
}
@abdulhamid0yusuf
Jan
08 Apr 2020, 19:49
RE: Simple and robust trailing algorithm
Thanks for sharing your code. Have you checked that this code works?
Initially, I wanted to add "Step" to the trailing stop to determine the minimum distance price has to move in favour of the position for the trailing stop to be adjusted. This is just to save resources in case adjusting SL on every tick is not necessary.
@jani
Abdulhamid Yusuf
10 Apr 2020, 00:20
RE: RE: Simple and robust trailing algorithm
jani said:
Thanks for sharing your code. Have you checked that this code works?
Initially, I wanted to add "Step" to the trailing stop to determine the minimum distance price has to move in favour of the position for the trailing stop to be adjusted. This is just to save resources in case adjusting SL on every tick is not necessary.
Hey jani, Yes I have tested this code and it works as expected, but in order to add a step to. modify the trailing stop every time a new level is reached, you will need to modify the conditional statement to be as follows:
if ((position.Pips >= positionMaxProfit + PipsToProtect + TrailingDistance))
Let me know if this is what you want,
Thanks.
@abdulhamid0yusuf
Jagadish
03 Feb 2021, 07:09
RE: Simple and robust trailing algorithm
Hi Abdul,
How can I make it work for the Pending Orders?
Thanks.
abdulhamid0yusuf said:
I came here to see how to implement a trailing stop loss, but the code provided by cTrader Team was unnecessarily complicated to me, so I would like to share my way ...
using cAlgo.API; using System.Collections.Generic; using System.Linq; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class TestTrailingStop : Robot { // Save the maximum winning pips each position has reached private Dictionary<Position, double> PositionsMaxProfits; [Parameter("Winning Pips to protect", DefaultValue = 10)] public int PipsToProtect { get; set; } [Parameter("Trailing Stop Distance", DefaultValue = 5)] public int TrailingDistance { get; set; } protected override void OnStart() { PositionsMaxProfits = new Dictionary<Position, double>(); // Market order for illustration purposes var p = ExecuteMarketOrder(TradeType.Sell, SymbolName, 1000).Position; // Add every order you create to the dictionary and set its initial max pips to 0 PositionsMaxProfits.Add(p, 0); } protected override void OnTick() { // Update Stop loss on each tick once the position has yeilded winning pips >= PipsToProtect + TrailingDistance foreach (Position position in PositionsMaxProfits.Keys.ToList()) { var positionMaxProfit = PositionsMaxProfits[position]; // 1st condition checks if winning pips >= PipsToProtect + TrailingDistance // 2ed condition checks if winning pips is greater than previous winning pips if ((position.Pips >= PipsToProtect + TrailingDistance) && position.Pips > positionMaxProfit) { // Assign the new higher winning pips to the position PositionsMaxProfits[position] = position.Pips; // Modify Stop loss to be $TrailingDistance pips away from current winnig pips // ** -1 means put stop loss on oppostie direction than normal position.ModifyStopLossPips(-1 * (position.Pips - TrailingDistance)); } } } } }
@8089669
PUdPUd
09 Feb 2021, 22:54
RE: Simple and robust trailing algorithm
Hi Abdul
I have tried to implement your code as written and the dictionary component doesn't work and I can't find documentation for the syntax. The error that I am getting is Error CS1502: The best overloaded method match for 'System.Collections.Generic.Dictionary<cAlgo.API.Position,double>.Add(cAlgo.API.Position, double)' has some invalid arguments.
Where is the syntax for dictionary in cTrader?
Thanks for the code
PUdPUd
abdulhamid0yusuf said:
I came here to see how to implement a trailing stop loss, but the code provided by cTrader Team was unnecessarily complicated to me, so I would like to share my way ...
using cAlgo.API; using System.Collections.Generic; using System.Linq; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class TestTrailingStop : Robot { // Save the maximum winning pips each position has reached private Dictionary<Position, double> PositionsMaxProfits; [Parameter("Winning Pips to protect", DefaultValue = 10)] public int PipsToProtect { get; set; } [Parameter("Trailing Stop Distance", DefaultValue = 5)] public int TrailingDistance { get; set; } protected override void OnStart() { PositionsMaxProfits = new Dictionary<Position, double>(); // Market order for illustration purposes var p = ExecuteMarketOrder(TradeType.Sell, SymbolName, 1000).Position; // Add every order you create to the dictionary and set its initial max pips to 0 PositionsMaxProfits.Add(p, 0); } protected override void OnTick() { // Update Stop loss on each tick once the position has yeilded winning pips >= PipsToProtect + TrailingDistance foreach (Position position in PositionsMaxProfits.Keys.ToList()) { var positionMaxProfit = PositionsMaxProfits[position]; // 1st condition checks if winning pips >= PipsToProtect + TrailingDistance // 2ed condition checks if winning pips is greater than previous winning pips if ((position.Pips >= PipsToProtect + TrailingDistance) && position.Pips > positionMaxProfit) { // Assign the new higher winning pips to the position PositionsMaxProfits[position] = position.Pips; // Modify Stop loss to be $TrailingDistance pips away from current winnig pips // ** -1 means put stop loss on oppostie direction than normal position.ModifyStopLossPips(-1 * (position.Pips - TrailingDistance)); } } } } }
@PUdPUd
PUdPUd
09 Feb 2021, 22:59
RE:
Hi PanagiotisCharalampous
I am having trouble implementing your code. It works fine once but I would like to run it each day. I added the ExecuteMarketOrder entry into the OnStart and subscribed it to daily bars, but then the code doesn't execute any market order.
protected override void OnStart()
{
var dailyBars = MarketData.GetBars(TimeFrame.Daily);
dailyBars.BarOpened += OnDailyBarsBarOpened;
}
void OnDailyBarsBarOpened(BarOpenedEventArgs obj)
{
//Execute a market order based on the direction parameter
ExecuteMarketOrder(Buy ? TradeType.Buy : TradeType.Sell, SymbolName, Volume, "SampleTrailing", StopLoss, 20);
//Set the position's highest gain in pips
_highestGain = Positions[0].Pips;
}
Also, I would like to do this for a combination of market orders and to modify stop orders once they are executed so I would need a dictionary. I cannot seem to find documentation on the syntax for Dictionary. Where do I find this?
Thanks
PanagiotisCharalampous said:
Hi Jan,
Positions.Find will only return one position matching the label. There are several changes that you need to make to this example in order to be adapted to handle any number of positions. For example, you will need to track a separate TriggerWhenGaining for each position, maybe with the use of a dictionary.
Best Regards,
Panagiotis
@PUdPUd
Panagiotis Charalampous
10 Feb 2021, 08:22
Hi PUdPUd,
Can you please create a separate thread with the complete cBot code and exact steps to reproduce your issue? Regarding dictionaries, you can start from here.
Best Regards,
Panagiotis
@PanagiotisCharalampous
emilio
25 Apr 2023, 12:01
RE: info
Spotware said:
This robot 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.
// ------------------------------------------------------------------------------------------------- // // This robot 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 "Trailing Stop Loss Sample" Robot places a Buy or Sell Market order according to user input. // When the order is filled it implements trailing stop loss. // // ------------------------------------------------------------------------------------------------- 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 TrailingStopLossSample : Robot { [Parameter("Volume", DefaultValue = 1000)] public int Volume { get; set; } [Parameter("Buy")] public bool Buy { get; set; } [Parameter("Stop Loss", DefaultValue = 5)] public double StopLoss { get; set; } [Parameter("Trigger When Gaining", DefaultValue = 1)] public double TriggerWhenGaining { get; set; } [Parameter("Trailing Stop Loss Distance", DefaultValue = 1)] public double TrailingStopLossDistance { get; set; } private double _highestGain; private bool _isTrailing; protected override void OnStart() { //Execute a market order based on the direction parameter ExecuteMarketOrder(Buy ? TradeType.Buy : TradeType.Sell, Symbol, Volume, "SampleTrailing", StopLoss, null); //Set the position's highest gain in pips _highestGain = Positions[0].Pips; } protected override void OnTick() { var position = Positions.Find("SampleTrailing"); if (position == null) { Stop(); return; } //If the trigger is reached, the robot starts trailing if (!_isTrailing && position.Pips >= TriggerWhenGaining) { _isTrailing = true; } //If the cBot is trailing and the profit in pips is at the highest level, we need to readjust the stop loss if (_isTrailing && _highestGain < position.Pips) { //Based on the position's direction, we calculate the new stop loss price and we modify the position if (position.TradeType == TradeType.Buy) { var newSLprice = Symbol.Ask - (Symbol.PipSize * TrailingStopLossDistance); if (newSLprice > position.StopLoss) { ModifyPosition(position, newSLprice, null); } } else { var newSLprice = Symbol.Bid + (Symbol.PipSize * TrailingStopLossDistance); if (newSLprice < position.StopLoss) { ModifyPosition(position, newSLprice, null); } } //We reset the highest gain _highestGain = position.Pips; } } protected override void OnStop() { // Put your deinitialization logic here } } }
can you add a take profit? is it possible doing more operations?
@Emilio90
Panagiotis Charalampous
05 Jan 2018, 11:50
Hi Drummond360,
Indeed it should have been PipSize. I fixed the code. Can you try now please?
Best Regards,
Panagiotis
@PanagiotisCharalampous