Reset input parameters when position closes/opens
Reset input parameters when position closes/opens
03 Aug 2017, 10:20
Hi. I would like to reset my defaul parameters when a position opens or closes. Everytime a position opens/closes i need the Boolean to change from Buy to ExitLong.
Here is the code (taken some unnecessary parts out):
[Parameter("Buy", DefaultValue = false)]
public bool Buy { get; set; }
[Parameter("Exit Long", DefaultValue = false)]
public bool ExitLong { get; set; }
//=============================================================================================
protected override void OnBar()
{
var label_orig = label_a + " " + Symbol.Code;
var longPosition = Positions.Find(label_orig, Symbol, TradeType.Buy);
var shortPosition = Positions.Find(label_orig, Symbol, TradeType.Sell);
if (Buy)
{
ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, label_orig, null, null, null, name);
}
//CLOSE OUT OPEN TRADES
if (ExitLong)
{
ClosePosition(longPosition);
}
}
Spotware
03 Aug 2017, 11:03
Dear davidp13,
You can use the Positions.Opened and Positions.Closed events to reset your boolean parameters. See a small example below
Best Regards,
cTrader Team
@Spotware