Download MetaTrader 5

Issue placing 1 trade per bar

To add comments, please log in or register
Connor Fitz
15
Connor Fitz  

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


Keith Watford
Moderator
10614
Keith Watford  

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? 

Connor Fitz
15
Connor Fitz  
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
Connor Fitz
15
Connor Fitz  
i believe i found the problem. Thanks for your help!
To add comments, please log in or register