PO
Information
Username: | PorkChop_75 |
Member since: | 13 Aug 2021 |
Last login: | 01 Aug 2023 |
Status: | Active |
Activity
Where | Created | Comments |
---|---|---|
Algorithms | 0 | 1 |
Forum Topics | 1 | 1 |
Jobs | 0 | 0 |
Username: | PorkChop_75 |
Member since: | 13 Aug 2021 |
Last login: | 01 Aug 2023 |
Status: | Active |
Where | Created | Comments |
---|---|---|
Algorithms | 0 | 1 |
Forum Topics | 1 | 1 |
Jobs | 0 | 0 |
Can anyone advise how we would go about closing open trades in a direction, if the trend changes direction?
Setting a stop loss can be too restrictive so was trying to use the following but get errors:
ClosePosition(TradeType.Sell); or ClosePosition(shortSignal);
Error CS1502: The best overloaded method match for 'cAlgo.API.Robot.ClosePosition(cAlgo.API.Position)' has some invalid arguments
Error CS1503: Argument 1: cannot convert from 'cAlgo.API.TradeType' to 'cAlgo.API.Position'
Im getting stuck with the code trying to simply close any open trades as per below.....
protected override void OnBar()
{
index = Bars.ClosePrices.Count - 2;
if (ExitOnOppositeSignal && closeSignal)
ClosePosition(currentPosition);
//if (!inPosition)
{
if (EnterOnSyncSignalOnly)
{
if (localTendencyWasShort && globalTendencyWasShort && localTendencyIsLong && globalTendencyIsLong)
{
EnterInPosition(TradeType.Buy);
ClosePosition(TradeType.Sell); or ClosePosition(shortSignal);
}
else if (localTendencyWasLong && globalTendencyWasLong && localTendencyIsShort && globalTendencyIsShort)
{
EnterInPosition(TradeType.Sell);
ClosePosition(TradeType.Buy); or ClosePosition(longSignal);
}
}
else
{
if (shortSignal)
{
EnterInPosition(TradeType.Sell);
ClosePosition(TradeType.Buy); or ClosePosition(longSignal);
}
else if (longSignal)
{
EnterInPosition(TradeType.Buy);
ClosePosition(TradeType.Sell); or ClosePosition(shortSignal);
}