Hedging
Hedging
20 Apr 2013, 00:48
I've read in the cTrader presentation pdf that it supports hedging, being long and short in the same account. How does this reflect in cAlgo ? I see IAccount has Positions and PendingOrders as members (like in MT5) Is there any setting that makes Positions work with market orders instead of positions?
P.S. Is there any OnPendingOrderFilled ?
Replies
TheEconomist
23 Apr 2013, 12:24
RE:
OnPositionOpened is triggered when the pending order is filled. Positions do represent market orders. Do you need help with the code to do hedging?
Yes, do you have a sample?
@TheEconomist
cAlgo_Fanatic
23 Apr 2013, 14:31
To hedge all positions in the Account:
[Parameter(DefaultValue = 100000)] public int Volume { get; set; } protected override void OnStart() { foreach (var position in Account.Positions) { if (position.TradeType == TradeType.Buy) { Trade.CreateSellMarketOrder(Symbol, Volume); //break; // optional break to hedge only one position } else { Trade.CreateBuyMarketOrder(Symbol, Volume); //break; // optional break to hedge only one position } } }
@cAlgo_Fanatic
TheEconomist
23 Apr 2013, 18:21
RE:
To hedge all positions in the Account:
[Parameter(DefaultValue = 100000)] public int Volume { get; set; } protected override void OnStart() { foreach (var position in Account.Positions) { if (position.TradeType == TradeType.Buy) { Trade.CreateSellMarketOrder(Symbol, Volume); //break; // optional break to hedge only one position } else { Trade.CreateBuyMarketOrder(Symbol, Volume); //break; // optional break to hedge only one position } } }
Thanks! I understand from the code that Positions are like market orders in MT4. Otherwise creating a Sell with the same volume of the buy as a market order would close the position.
After the execution of the market orders, they will be incorporated in the Positions collection, am I correct?
@TheEconomist
cAlgo_Fanatic
24 Apr 2013, 09:22
Yes, the OnPositionOpened event is raised when a position is created. So, you can control/monitor the flow with this event.
@cAlgo_Fanatic
megamemo
28 Jul 2015, 07:35
hi
TheEconomist is my pleasure first of all i cut see your hedging interested and a programmer what if a told you that i have a great strategy that maybe we cut worked out together? is a really profitable one if you or any are interested please contact in my mail
burnigonhell@gmail.com
@megamemo
cAlgo_Fanatic
22 Apr 2013, 09:43
OnPositionOpened is triggered when the pending order is filled. Positions do represent market orders. Do you need help with the code to do hedging?
@cAlgo_Fanatic