Status
Open
Budget
20.00 GBP
Payment Method
Direct Payment
Job Description
Hi guys.
How can i modify CounterTrade to automatically Close " it's trade " when the " Original position " closes. Please any help would be much appreciated.
Many Thanks
This is the cbot
https://ctdn.com/algos/cbots/show/475
Comments
Log in to add a comment.
private const string Label = "CounterTrade";
protected override void OnStart()
{
Positions.Opened += OnPositionsOpened;
Positions.Closed += OnPositionsClosed;
}
void OnPositionsClosed(PositionClosedEventArgs args)
{
var originalPosition = args.Position;
if (originalPosition.Label != Label)
{
var tradeType = originalPosition.TradeType == TradeType.Buy ? TradeType.Sell : TradeType.Buy;
var position = Positions.Find(Label, Symbol, tradeType);
if (position != null)
{
ClosePosition(position);
}
}
}
void OnPositionsOpened(PositionOpenedEventArgs args)
{
var originalPosition = args.Position;
if (originalPosition.Label != Label)
{
var tradeType = originalPosition.TradeType == TradeType.Buy ? TradeType.Sell : TradeType.Buy;
ExecuteMarketOrder(tradeType, Symbol, originalPosition.Volume, Label);
}
}