Close Position with multiple AND/OR
Close Position with multiple AND/OR
12 Jun 2014, 23:26
Hi,
I have a robot that opens a position in one direction only. I have a exit strategy that contains three OR checks.
//Close of long position
if (currentSlowMa > currentFastMa && _cci.Result.Last(1) < _cci.Result.Last(0) && longPosition != null || _cci.Result.Last(1) < 0 || xFastMA > valueClose)
{
ClosePosition(longPosition);
}
This all is currently sitting in protected override void OnTick() and when I run the backtest it does not create any entries. Why would that and where should i move it too?
Replies
breakermind
16 Jun 2014, 11:11
RE:
davidp13 said:
Correct. This code is to close the open position. The problem I have is when I add || (or) then no entries open anymore when I back test.
Hi,
think different ;)
if (currentSlowMa > currentFastMa && _cci.Result.Last(1) < _cci.Result.Last(0) && longPosition != null)
{
ClosePosition(longPosition);
}
if(_cci.Result.Last(1) < 0){
ClosePosition(longPosition);
}
if(xFastMA > valueClose)){
ClosePosition(longPosition);
]
Regards
@breakermind
Yasen
18 Jun 2014, 03:24
Backtesting is a simulator to test your strategy. And each backtesting is a separate process - you can not open a position in one cBot and close it in an another one ( not like in real execution) - In real execution all cBots work together. In real life you for sure can open a position an one cBot and close it in another one even if each cBot runs on a separate computer (using same account for sure) ..... So if you like to backtest a set of cBots together you can copy each cBots code to a single new cBot and then backtest this new cBot to test all cBots together.... "It Can Be Only One"
@Yasen
davidp13
15 Jun 2014, 20:54
Hi, can anyone help please?
@davidp13