Issue placing 1 trade per bar

 

Hello, this is my first post on this forum.

I have been having an issue with getting only 1 trade per bar happening, i searched the forums and used similar code to what others suggested but it still places many bars on certain spots. Can anyone explain why this is occurring and how to fix it?

My code: 

     if(lastBar < Bars){
        canTrade = true;
        lastBar = Bars;
      }

What happens


 

It is generally accepted that Time[0] is better to detect new bars.

 

Do you set cantrade to false anywhere in your code?

Do you check cantrade before opening trades? 

 
canTrade is checked before trades are placed and it is changed to false after a trade, ill modify my code to see if Time[0] will have a better effect
 
i believe i found the problem. Thanks for your help!
Reason: