cBot stops after one bar

oleh.mudryi's avatar

oleh.mudryi since: 02 Aug 2022;

  03 Aug 2022, 11:06
cBot stops after one bar

I am new one in C# programming and cAlgo.
When i start my cBot, it stops on next bar.

If you try to backtest it, you will see that he stops on next bar. 
If I take away function ClosePosition than bot works.
So I think the problem is with it.

It stops my bot without any mistakes in code or build

It is hard to find mistake

See Full code and download bot you can here:
 

oleh.mudryi's avatar

oleh.mudryi since: 02 Aug 2022;

  03 Aug 2022, 17:02
RE: i used debugger

oleh.mudryi said:

I am new one in C# programming and cAlgo.
When i start my cBot, it stops on next bar.

If you try to backtest it, you will see that he stops on next bar. 
If I take away function ClosePosition than bot works.
So I think the problem is with it.

It stops my bot without any mistakes in code or build

It is hard to find mistake

See Full code and download bot you can here:
 

Okay. I used debugger and I see error on ClosePosition 

the NullReferenceException indicates that your code is trying to work with an object that has a null value as its reference

oleh.mudryi's avatar

oleh.mudryi since: 02 Aug 2022;

  03 Aug 2022, 18:52
RE: RE: i used debugger

oleh.mudryi said:

oleh.mudryi said:

I am new one in C# programming and cAlgo.
When i start my cBot, it stops on next bar.

If you try to backtest it, you will see that he stops on next bar. 
If I take away function ClosePosition than bot works.
So I think the problem is with it.

It stops my bot without any mistakes in code or build

It is hard to find mistake

See Full code and download bot you can here:
 

Okay. I used debugger and I see error on ClosePosition 

the NullReferenceException indicates that your code is trying to work with an object that has a null value as its reference

Okay. I have found how to resolve it:

 

var buy_position = Positions.FindAll("order_buy", SymbolName, TradeType.Buy);

var sell_position = Positions.FindAll("order_sell", SymbolName, TradeType.Sell);

foreach (var position in buy_position)

{

if (close_buy)

ClosePosition(position);

}

foreach (var position in sell_position)

{

if (close_sell)

ClosePosition(position);

}