Can't find bug, please help

 
Fixed
 

It might not have anything to do with this issue . . . but using Bars is a bad idea . . . didn't I say that before ?

First tick through your code . . . .

if (EachTickMode && Bars != BarCount) TickCheck = False;

. . . BarCount has been declared but has not been given a value . . . so this makes no sense.

All this kind of stuff will fail when you have maxed out the number of bars on your chart . . .

(Bars != BarCount)

In your other post you said you want to open an order at the start of a new bar and close it at the end of the bar, "trade one bar" . . . . to stop the code opening and then immediately closing why don't you simply check when the order was opened and don't allow it to close if the time is less than 1 bar ?

 

  1. Attach large amounts
  2. You can call newBar ONLY once per tick.
  3. Delete ALL references to BarCount
  4. You MUST count down when closing multiple orders or in the presence or multiple orders from multiple charts.
 
You need to learn to code . . not how to use templates . . . it takes a lot of effort, but what you are trying to achieve is not a trivial thing.
Reason: