Can this code be fixed?
22 Feb 2017, 07:38
This is a absolute static TP and SL bot I use inconjuction with my SMA breakout bot.
Randomly, this bot will add two zeros (00) to each my TP and SL levels for no reason. Example: for a 10sl and 8tp it would randomly change it to 1000 sl and 800 tp.
// -------------------------------------------------------------------------------
//
// This is a Sample used as a guideline to build your own Robot.
// Please use the forum to provide us with your suggestions about cAlgo’s API.
//
// -------------------------------------------------------------------------------
using cAlgo.API;
namespace cAlgo.Robots
{
[Robot()]
public class ModifyAccountPositions : Robot
{
protected override void OnTick()
{
foreach (var position in Positions)
{
if (position.StopLoss == null)
{
Print("Modifying {0}", position.Id);
ModifyPosition(position, GetAbsoluteStopLoss(position, 10), GetAbsoluteTakeProfit(position, 8));
}
}
}
private double GetAbsoluteStopLoss(Position position, int stopLossInPips)
{
return position.TradeType == TradeType.Buy ? position.EntryPrice - Symbol.PipSize * stopLossInPips : position.EntryPrice + Symbol.PipSize * stopLossInPips;
}
private double GetAbsoluteTakeProfit(Position position, int takeProfitInPips)
{
return position.TradeType == TradeType.Buy ? position.EntryPrice + Symbol.PipSize * takeProfitInPips : position.EntryPrice - Symbol.PipSize * takeProfitInPips;
}
}
}
Replies
derekszyszka
22 Feb 2017, 16:32
RE:
testpossessed said:
Not sure we have enough information to help you.
What currency pairs is this happening on, different ones, the same ones?
The code is pretty straight forward and I use something similar a lot without this problem.
All currency pairs, could be the gbpusd, usdjpy, audusd, it is comepletely random. Are you willing to share your SL/TP bot you use so I can compare the script?
@derekszyszka

cTKit
22 Feb 2017, 10:05
Not sure we have enough information to help you.
What currency pairs is this happening on, different ones, the same ones?
The code is pretty straight forward and I use something similar a lot without this problem.
@cTKit