Label and CBOT to work in parallel
Label and CBOT to work in parallel
18 Feb 2014, 17:34
Hi to all,
I have two similar cBot that assign a Label to each new order.
If the cBot1 and cBot2 are working simultaneously enter into conflict.
I would like to modify the code and insert a condition in order to check the label and avoid conflict.
So cBot1 have to run all the code with reference to the positions with his Label1 and cBot2 must ignore the positions of cBot1 and manage positions with his Label2.
How can I handle it? Where should I put this control?
Thanks for help.
Replies
Forex19
19 Feb 2014, 20:26
( Updated at: 21 Dec 2023, 09:20 )
RE:
Spotware said:
Please look at the following example:
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC)] public class Sample : Robot { const string Label = "My unique label"; protected override void OnTick() { var position = Positions.Find(Label); if (position == null) { //if there is no position with my label ExecuteMarketOrder(TradeType.Buy, Symbol, Symbol.VolumeMin, Label); } else { //if position exists //some actions with position object } } } }You need to specify the Label in trade operation and then find your position with Positions.Find method
Hi,
I tried to modify the code as suggested but the result is always this error:
The startup code that I tried to change for both cBots is similar to this:
using System; using cAlgo.API; namespace cAlgo.Robots { [Robot("RF")] public class RF : Robot { [Parameter(DefaultValue = 3000, MinValue = 1000)] public int FirstLot { get; set; } [Parameter("Take_Profit", DefaultValue = 180, MinValue = 10)] public int TakeProfit { get; set; } [Parameter("Tral_Start", DefaultValue = 50)] public int Tral_Start { get; set; } [Parameter("Tral_Stop", DefaultValue = 50)] public int Tral_Stop { get; set; } [Parameter(DefaultValue = 300)] public int PipStep { get; set; } [Parameter(DefaultValue = 5, MinValue = 2)] public int MaxOrders { get; set; } private Position position; private bool RobotStopped; private int LotStep = 3000; protected override void OnStart() { RF_Label = "RF " + Symbol.Code + " - Diretto"; Positions.Opened += PositionsOnOpened; } protected override void OnTick() { double Bid = Symbol.Bid; double Ask = Symbol.Ask; double Point = Symbol.TickSize; if (Trade.IsExecuting) return; if (Positions.Count > 0 && RobotStopped) return; else RobotStopped = false; if (Positions.Count == 0) SendFirstOrder(FirstLot); else ControlSeries(); foreach (var position in Positions) { if (position.SymbolCode == Symbol.Code) { if (position.TradeType == TradeType.Buy) { if (Bid - GetAveragePrice(TradeType.Buy) >= Tral_Start * Point) if (Bid - Tral_Stop * Point >= position.StopLoss) ModifyPosition(position, Bid - Tral_Stop * Point, position.TakeProfit); } if (position.TradeType == TradeType.Sell) { if (GetAveragePrice(TradeType.Sell) - Ask >= Tral_Start * Point) if (Ask + Tral_Stop * Point <= position.StopLoss || position.StopLoss == 0) ModifyPosition(position, Ask + Tral_Stop * Point, position.TakeProfit); } } } } protected override void OnError(Error CodeOfError) { if (CodeOfError.Code == ErrorCode.NoMoney) { RobotStopped = true; Print("ERROR!!! No money for order open, robot is stopped!"); } else if (CodeOfError.Code == ErrorCode.BadVolume) { RobotStopped = true; Print("ERROR!!! Bad volume for order open, robot is stopped!"); } } private void SendFirstOrder(int OrderVolume) { int Signal = GetStdIlanSignal(); if (!(Signal < 0)) switch (Signal) { case 0: ExecuteMarketOrder(TradeType.Buy, Symbol, OrderVolume, RF_Label); break; case 1: ExecuteMarketOrder(TradeType.Sell, Symbol, OrderVolume, RF_Label); break; } } private void PositionsOnOpened(PositionOpenedEventArgs args) { Position position = args.Position; string emailBody = string.Format("Position {0} {1} Opened at {2}", position.Volume, position.TradeType, position.EntryPrice); string subject = string.Format("RF P{0}", Positions.Count); Notifications.SendEmail("cAlgoNotice@gmail.com", "forex19@email.it", subject, emailBody); double? StopLossPrice = null; double? TakeProfitPrice = null; if (Positions.Count == 1) { if (position.TradeType == TradeType.Buy) TakeProfitPrice = position.EntryPrice + TakeProfit * Symbol.TickSize; if (position.TradeType == TradeType.Sell) TakeProfitPrice = position.EntryPrice - TakeProfit * Symbol.TickSize; } else switch (GetPositionsSide()) { case 0: TakeProfitPrice = GetAveragePrice(TradeType.Buy) + TakeProfit * Symbol.TickSize; break; case 1: TakeProfitPrice = GetAveragePrice(TradeType.Sell) - TakeProfit * Symbol.TickSize; break; } for (int i = 0; i < Positions.Count; i++) { position = Positions[i]; if (StopLossPrice != null || TakeProfitPrice != null) ModifyPosition(position, position.StopLoss, TakeProfitPrice); } } protected override void OnPositionOpened(Position openedPosition) { } private double GetAveragePrice(TradeType TypeOfTrade) { double Result = Symbol.Bid; double AveragePrice = 0; long Count = 0; for (int i = 0; i < Positions.Count; i++) { position = Positions[i]; if (position.TradeType == TypeOfTrade) { AveragePrice += position.EntryPrice * position.Volume; Count += position.Volume; } } if (AveragePrice > 0 && Count > 0) Result = AveragePrice / Count; return Result; } private int GetPositionsSide() { int Result = -1; int i, BuySide = 0, SellSide = 0; for (i = 0; i < Positions.Count; i++) { if (Positions[i].TradeType == TradeType.Buy) BuySide++; if (Positions[i].TradeType == TradeType.Sell) SellSide++; } if (BuySide == Positions.Count) Result = 0; if (SellSide == Positions.Count) Result = 1; return Result; } private void ControlSeries() { int _pipstep, NewVolume, Rem; int BarCount = 25; int Del = MaxOrders - 1; if (PipStep == 0) _pipstep = GetDynamicPipstep(BarCount, Del); else _pipstep = PipStep; if (Positions.Count < MaxOrders) switch (GetPositionsSide()) { case 0: if (Symbol.Ask < FindLastPrice(TradeType.Buy) - _pipstep * Symbol.TickSize) { NewVolume = Math.DivRem((int)(FirstLot + FirstLot * Positions.Count), LotStep, out Rem) * LotStep; if (!(NewVolume < LotStep)) ExecuteMarketOrder(TradeType.Buy, Symbol, NewVolume, RF_Label); } break; case 1: if (Symbol.Bid > FindLastPrice(TradeType.Sell) + _pipstep * Symbol.TickSize) { NewVolume = Math.DivRem((int)(FirstLot + FirstLot * Positions.Count), LotStep, out Rem) * LotStep; if (!(NewVolume < LotStep)) ExecuteMarketOrder(TradeType.Sell, Symbol, NewVolume, RF_Label); } break; } } private int GetDynamicPipstep(int CountOfBars, int Del) { int Result; double HighestPrice = 0, LowestPrice = 0; int StartBar = MarketSeries.Close.Count - 2 - CountOfBars; int EndBar = MarketSeries.Close.Count - 2; for (int i = StartBar; i < EndBar; i++) { if (HighestPrice == 0 && LowestPrice == 0) { HighestPrice = MarketSeries.High[i]; LowestPrice = MarketSeries.Low[i]; continue; } if (MarketSeries.High[i] > HighestPrice) HighestPrice = MarketSeries.High[i]; if (MarketSeries.Low[i] < LowestPrice) LowestPrice = MarketSeries.Low[i]; } Result = (int)((HighestPrice - LowestPrice) / Symbol.TickSize / Del); return Result; } private double FindLastPrice(TradeType TypeOfTrade) { double LastPrice = 0; for (int i = 0; i < Positions.Count; i++) { position = Positions[i]; if (TypeOfTrade == TradeType.Buy) if (position.TradeType == TypeOfTrade) { if (LastPrice == 0) { LastPrice = position.EntryPrice; continue; } if (position.EntryPrice < LastPrice) LastPrice = position.EntryPrice; } if (TypeOfTrade == TradeType.Sell) if (position.TradeType == TypeOfTrade) { if (LastPrice == 0) { LastPrice = position.EntryPrice; continue; } if (position.EntryPrice > LastPrice) LastPrice = position.EntryPrice; } } return LastPrice; } private int GetStdIlanSignal() { int Result = -1; int LastBarIndex = MarketSeries.Close.Count - 2; int PrevBarIndex = LastBarIndex - 1; if (MarketSeries.Close[LastBarIndex] > MarketSeries.Open[LastBarIndex]) if (MarketSeries.Close[PrevBarIndex] > MarketSeries.Open[PrevBarIndex]) Result = 0; if (MarketSeries.Close[LastBarIndex] < MarketSeries.Open[LastBarIndex]) if (MarketSeries.Close[PrevBarIndex] < MarketSeries.Open[PrevBarIndex]) Result = 1; return Result; } } }
Can you tell me more about how and where to edit the code?
Thanks
@Forex19
Forex19
20 Feb 2014, 11:31
RE:
Spotware said:
Regarding to label problems, you still do not filter your positions by Label.
add the following code to the beginning of PositionsOnOpened method:
Position position = args.Position; if (position.Label != RF_Label) return;
I tried your suggestion to filter my position by Label but the problem persists (as shown on the image that I previously uploaded).
I also tried to filter the positions in other parts of the code but does not change the result always the same error.
In addition to filtering the positions I have to edit anything else?
Where is the problem?
@Forex19
Forex19
20 Feb 2014, 12:11
RE:
Spotware said:
TRADING_BAD_STOPS means that you have a mistake in the calculation of SL or TP levels
I understood that the error is in the calculation of TP levels. Why?
If I filter positions with the label, the two CBOT should be independent and don't check what it does the other CBOT.
Thanks.
@Forex19
Forex19
26 Feb 2014, 16:15
RE:
Spotware said:
TRADING_BAD_STOPS means that you have a mistake in the calculation of SL or TP levels
Hi,I have done several tests, using as suggested
Position position = args.Position; if (position.Label! = RF_Label) return;
But if I run the two CBOT, together, the error occurs on the TP in one of the two CBOT (as I showed), while if I run only one of the two CBOT's okay.
Why? How can I fix?
@Forex19
Forex19
28 Feb 2014, 14:42
RE:
Spotware said:
Probably you do not filter positions by the label somewhere in your code.
As I said he made several tests to filter the label in the various parts of the code.
But I think there is another problem because the two cbots (as I have shown in the screenshot) are two different locations with the right label.
The problem is in TP, which is not assigned.
Do you have any suggestions on how and where to change the code?
Thanks
@Forex19
AimHigher
04 Mar 2014, 19:35
RE: RE:
Forex19 said:
Spotware said:
Probably you do not filter positions by the label somewhere in your code.
As I said he made several tests to filter the label in the various parts of the code.
But I think there is another problem because the two cbots (as I have shown in the screenshot) are two different locations with the right label.
The problem is in TP, which is not assigned.
Do you have any suggestions on how and where to change the code?Thanks
You have defined Point using Symbol.TickSize while the API Guide uses Symbol.PipSize to set a stop loss price when the stop loss is specified as a number of pips, which your trailing stop is. However, I am very new to cAlgo so I don't know if that solves it.
@AimHigher
AimHigher
04 Mar 2014, 19:51
RE: RE: RE:
AimHigher said:
Forex19 said:
Spotware said:
Probably you do not filter positions by the label somewhere in your code.
As I said he made several tests to filter the label in the various parts of the code.
But I think there is another problem because the two cbots (as I have shown in the screenshot) are two different locations with the right label.
The problem is in TP, which is not assigned.
Do you have any suggestions on how and where to change the code?Thanks
You have defined Point using Symbol.TickSize while the API Guide uses Symbol.PipSize to set a stop loss price when the stop loss is specified as a number of pips, which your trailing stop is. However, I am very new to cAlgo so I don't know if that solves it.
Nevermind. When I tested it, Symbol.Bid - 50 * Symbol.TickSize still appears to generate a valid price so I don't think that is it.
@AimHigher
Forex19
05 Mar 2014, 11:29
RE: RE: RE: RE:
AimHigher said:
AimHigher said:
Forex19 said:
Spotware said:
Probably you do not filter positions by the label somewhere in your code.
As I said he made several tests to filter the label in the various parts of the code.
But I think there is another problem because the two cbots (as I have shown in the screenshot) are two different locations with the right label.
The problem is in TP, which is not assigned.
Do you have any suggestions on how and where to change the code?Thanks
You have defined Point using Symbol.TickSize while the API Guide uses Symbol.PipSize to set a stop loss price when the stop loss is specified as a number of pips, which your trailing stop is. However, I am very new to cAlgo so I don't know if that solves it.
Nevermind. When I tested it, Symbol.Bid - 50 * Symbol.TickSize still appears to generate a valid price so I don't think that is it.
As I said I did several tests but I've always found the same error.
Also I'm not an expert on cAlgo, but it would be important to understand whether this error comes from a bug or other.
@Forex19
leo8three
26 Jun 2014, 18:18
@ Forex19: concerning the bad TP calculation, I think the problem is in
private int LotStep = 3000;
you can change it to LotStep = 1000 or 10000
@ Spotware: Forex19's robot places an order than modifies it, using old API classes "Trade.Create***MarketOrder(...)", and OnPositionOpened(...) where a new TP is set up; what is the best way to update this system to the new API?
I think a solution could be to try the following methods: ExecuteMarketOrderAsync(TradeType.***, Symbol, Volume, "My Label", OnExecuted); and
private void OnExecuted(TradeResult result) { if (result.IsSuccessful) { ModifyPosition(position, position.StopLoss, TakeProfitPrice); } }
does it can be a good solution?
Kind regards
@leo8three
Forex19
26 Jun 2014, 19:13
RE:
leo8three said:
@ Forex19: concerning the bad TP calculation, I think the problem is in
private int LotStep = 3000;you can change it to LotStep = 1000 or 10000
Do you think that the error is in the value "3000" or variable declared "private" ?
@ Spotware: Forex19's robot places an order than modifies it, using old API classes "Trade.Create***MarketOrder(...)", and OnPositionOpened(...) where a new TP is set up; what is the best way to update this system to the new API?
I think a solution could be to try the following methods: ExecuteMarketOrderAsync(TradeType.***, Symbol, Volume, "My Label", OnExecuted); and
private void OnExecuted(TradeResult result) { if (result.IsSuccessful) { ModifyPosition(position, position.StopLoss, TakeProfitPrice); } }does it can be a good solution?
Kind regards
Could you better indicate which parts of the code update? And how exactly?
Thank you very much.
@Forex19
leo8three
27 Jun 2014, 00:00
RE: RE:
I'm sorry, I've just realized my last answer is utterly wrong.
There is a lot of work for me to do in advance...
Forex19 said:
leo8three said:
@ Forex19: concerning the bad TP calculation, I think the problem is in
private int LotStep = 3000;you can change it to LotStep = 1000 or 10000
Do you think that the error is in the value "3000" or variable declared "private" ?
@ Spotware: Forex19's robot places an order than modifies it, using old API classes "Trade.Create***MarketOrder(...)", and OnPositionOpened(...) where a new TP is set up; what is the best way to update this system to the new API?
I think a solution could be to try the following methods: ExecuteMarketOrderAsync(TradeType.***, Symbol, Volume, "My Label", OnExecuted); and
private void OnExecuted(TradeResult result) { if (result.IsSuccessful) { ModifyPosition(position, position.StopLoss, TakeProfitPrice); } }does it can be a good solution?
Kind regards
Could you better indicate which parts of the code update? And how exactly?
Thank you very much.
@leo8three
breakermind
27 Jun 2014, 23:36
RE: RE: RE:
Hi,
how it should work just in a few sentences (may be easier to write it from the beginning)?
@breakermind
breakermind
28 Jun 2014, 11:26
Modyfikacja sl and tp with label
Hi all,
Modyfikacja sl and tp with label:
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 Label_SL_TP_Modify : Robot { [Parameter("Label", DefaultValue = "WOW")] public string Label { get; set; } [Parameter("LabelNumber", DefaultValue = 1, MinValue = 1)] public int LabelNumber { get; set; } [Parameter("Volume", DefaultValue = 10000, MinValue = 1000)] public int Volume { get; set; } [Parameter("Stop Loss (pips)", DefaultValue = 40, MinValue = 1)] public int StopLossInPips { get; set; } [Parameter("Take Profit (pips)", DefaultValue = 40, MinValue = 1)] public int TakeProfitInPips { get; set; } [Parameter("Spacing(Pips)", DefaultValue = 5, MinValue = 1)] public int Spacing { get; set; } public string LabelAll; protected override void OnStart() { // All label LabelAll = Label + LabelNumber + Symbol; for (int i = 1; i < 5; i++) { PlaceStopOrder(TradeType.Buy, Symbol, Volume, Symbol.Ask + Spacing * i * Symbol.PipSize, LabelAll); } // set pending down(SELL) for (int j = 1; j < 5; j++) { PlaceStopOrder(TradeType.Sell, Symbol, Volume, Symbol.Bid - Spacing * j * Symbol.PipSize, LabelAll); } } protected override void OnTick() { foreach (var position in Positions.FindAll(LabelAll)) { // Modifing position sl and tp if (position.StopLoss == null) { Print("Position {1} SL price is {0}", position.StopLoss, position.Id); } if (position.TakeProfit == null) { Print("Position {1} TP price is {0}", position.StopLoss, position.Id); } if (position.StopLoss == null && position.TakeProfit == null) { Print("Modifying {0}", position.Id); ModifyPosition(position, GetAbsoluteStopLoss(position, StopLossInPips), GetAbsoluteTakeProfit(position, TakeProfitInPips)); } if (position.StopLoss == null) { Print("Modifying {0}", position.Id); ModifyPosition(position, GetAbsoluteStopLoss(position, StopLossInPips), position.TakeProfit); } if (position.TakeProfit == null) { Print("Modifying {0}", position.Id); ModifyPosition(position, position.StopLoss, GetAbsoluteTakeProfit(position, TakeProfitInPips)); } } } //================================================================================ // modify SL and TP //================================================================================ private double GetAbsoluteStopLoss(Position position, int stopLossInPips) { Symbol Symbol = MarketData.GetSymbol(position.SymbolCode); return position.TradeType == TradeType.Buy ? position.EntryPrice - (Symbol.PipSize * stopLossInPips) : position.EntryPrice + (Symbol.PipSize * stopLossInPips); } private double GetAbsoluteTakeProfit(Position position, int takeProfitInPips) { Symbol Symbol = MarketData.GetSymbol(position.SymbolCode); return position.TradeType == TradeType.Buy ? position.EntryPrice + (Symbol.PipSize * takeProfitInPips) : position.EntryPrice - (Symbol.PipSize * takeProfitInPips); } } }
It's somewhere in the examples or finished cbots.
Have a nice day.
@breakermind
breakermind
28 Jun 2014, 11:43
RE: Modyfikacja sl and tp with label
breakermind said:
Hi all,
Modyfikacja sl and tp with label:
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 Label_SL_TP_Modify : Robot { [Parameter("Label", DefaultValue = "WOW")] public string Label { get; set; } [Parameter("LabelNumber", DefaultValue = 1, MinValue = 1)] public int LabelNumber { get; set; } [Parameter("Volume", DefaultValue = 10000, MinValue = 1000)] public int Volume { get; set; } [Parameter("Stop Loss (pips)", DefaultValue = 40, MinValue = 1)] public int StopLossInPips { get; set; } [Parameter("Take Profit (pips)", DefaultValue = 40, MinValue = 1)] public int TakeProfitInPips { get; set; } [Parameter("Spacing(Pips)", DefaultValue = 5, MinValue = 1)] public int Spacing { get; set; } public string LabelAll; protected override void OnStart() { // All label LabelAll = Label + LabelNumber + Symbol; for (int i = 1; i < 5; i++) { PlaceStopOrder(TradeType.Buy, Symbol, Volume, Symbol.Ask + Spacing * i * Symbol.PipSize, LabelAll); } // set pending down(SELL) for (int j = 1; j < 5; j++) { PlaceStopOrder(TradeType.Sell, Symbol, Volume, Symbol.Bid - Spacing * j * Symbol.PipSize, LabelAll); } } protected override void OnTick() { foreach (var position in Positions.FindAll(LabelAll)) { // Modifing position sl and tp if (position.StopLoss == null) { Print("Position {1} SL price is {0}", position.StopLoss, position.Id); } if (position.TakeProfit == null) { Print("Position {1} TP price is {0}", position.StopLoss, position.Id); } if (position.StopLoss == null && position.TakeProfit == null) { Print("Modifying {0}", position.Id); ModifyPosition(position, GetAbsoluteStopLoss(position, StopLossInPips), GetAbsoluteTakeProfit(position, TakeProfitInPips)); } if (position.StopLoss == null) { Print("Modifying {0}", position.Id); ModifyPosition(position, GetAbsoluteStopLoss(position, StopLossInPips), position.TakeProfit); } if (position.TakeProfit == null) { Print("Modifying {0}", position.Id); ModifyPosition(position, position.StopLoss, GetAbsoluteTakeProfit(position, TakeProfitInPips)); } } } //================================================================================ // modify SL and TP //================================================================================ private double GetAbsoluteStopLoss(Position position, int stopLossInPips) { Symbol Symbol = MarketData.GetSymbol(position.SymbolCode); return position.TradeType == TradeType.Buy ? position.EntryPrice - (Symbol.PipSize * stopLossInPips) : position.EntryPrice + (Symbol.PipSize * stopLossInPips); } private double GetAbsoluteTakeProfit(Position position, int takeProfitInPips) { Symbol Symbol = MarketData.GetSymbol(position.SymbolCode); return position.TradeType == TradeType.Buy ? position.EntryPrice + (Symbol.PipSize * takeProfitInPips) : position.EntryPrice - (Symbol.PipSize * takeProfitInPips); } } }It's somewhere in the examples or finished cbots.
Have a nice day.
or with Symbol.Code
LabelAll = Label + LabelNumber + Symbol.Code;
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 Label_SL_TP_Modify : Robot { [Parameter("Label", DefaultValue = "WOW")] public string Label { get; set; } [Parameter("LabelNumber", DefaultValue = 1, MinValue = 1)] public int LabelNumber { get; set; } [Parameter("Volume", DefaultValue = 10000, MinValue = 1000)] public int Volume { get; set; } [Parameter("Stop Loss (pips)", DefaultValue = 40, MinValue = 1)] public int StopLossInPips { get; set; } [Parameter("Take Profit (pips)", DefaultValue = 40, MinValue = 1)] public int TakeProfitInPips { get; set; } [Parameter("Spacing(Pips)", DefaultValue = 5, MinValue = 1)] public int Spacing { get; set; } public string LabelAll; protected override void OnStart() { // All label LabelAll = Label + LabelNumber + Symbol.Code; for (int i = 1; i < 5; i++) { PlaceStopOrder(TradeType.Buy, Symbol, Volume, Symbol.Ask + Spacing * i * Symbol.PipSize, LabelAll); } // set pending down(SELL) for (int j = 1; j < 5; j++) { PlaceStopOrder(TradeType.Sell, Symbol, Volume, Symbol.Bid - Spacing * j * Symbol.PipSize, LabelAll); } } protected override void OnTick() { foreach (var position in Positions.FindAll(LabelAll)) { // Modifing position sl and tp if (position.StopLoss == null) { Print("Position {1} SL price is {0}", position.StopLoss, position.Id); } if (position.TakeProfit == null) { Print("Position {1} TP price is {0}", position.StopLoss, position.Id); } if (position.StopLoss == null && position.TakeProfit == null) { Print("Modifying {0}", position.Id); ModifyPosition(position, GetAbsoluteStopLoss(position, StopLossInPips), GetAbsoluteTakeProfit(position, TakeProfitInPips)); } if (position.StopLoss == null) { Print("Modifying {0}", position.Id); ModifyPosition(position, GetAbsoluteStopLoss(position, StopLossInPips), position.TakeProfit); } if (position.TakeProfit == null) { Print("Modifying {0}", position.Id); ModifyPosition(position, position.StopLoss, GetAbsoluteTakeProfit(position, TakeProfitInPips)); } } } //================================================================================ // modify SL and TP //================================================================================ private double GetAbsoluteStopLoss(Position position, int stopLossInPips) { Symbol Symbol = MarketData.GetSymbol(position.SymbolCode); return position.TradeType == TradeType.Buy ? position.EntryPrice - (Symbol.PipSize * stopLossInPips) : position.EntryPrice + (Symbol.PipSize * stopLossInPips); } private double GetAbsoluteTakeProfit(Position position, int takeProfitInPips) { Symbol Symbol = MarketData.GetSymbol(position.SymbolCode); return position.TradeType == TradeType.Buy ? position.EntryPrice + (Symbol.PipSize * takeProfitInPips) : position.EntryPrice - (Symbol.PipSize * takeProfitInPips); } } }
Regards
@breakermind
Spotware
18 Feb 2014, 17:50
Please look at the following example:
You need to specify the Label in trade operation and then find your position with Positions.Find method
@Spotware