One trade per bar - page 2

 
David Diez: It's another HiLo-Breakout, you've seen the entry condition. Rest of lines are money management, orders count and so on.

I cannot assume anything because from what I have seen on your posted code, it is poorly written with poor logic, so I can only conclude that the rest of your code is of the same poor quality.

Do as I have suggested. Add many "prints" at various points in the code and see why the sections are not been executed. So far you have posted code, but you have not post output to logs for the current prints.

Add more prints in different sections, and analyse the output. Post the logs for advice!

 
Fernando Carreiro:

I cannot assume anything because from what I have seen on your posted code, it is poorly written with poor logic, so I can only conclude that the rest of your code is of the same poor quality.

Do as I have suggested. Add many "prints" at various points in the code and see why the sections are not been executed. So far you have posted code, but you have not post output to logs for the current prints.

Add more prints in different sections, and analyse the output. Post the logs for advice!

In essence, the condition 'NewBarFlag' is not met.

 
David Diez:In essence, the condition 'NewBarFlag' is not met.

How do you know? You have not placed any prints in place to print out the different variables and the results, so you do not know. Don't insist!

Add prints! Follow the logic! Analyse the logs! Otherwise you will not grow as a coder and will be stuck at the same level!

You are being argumentative, just as William stated. Don't argue! Put the prints in place and show your logs!

EDIT: Also inform us of what your chart period is and have the prints also print that out!

 
Very well. Send the code via PM, but I will only fix this bug and no other. I will report the bugs in the forum, not in private.
 
Fernando Carreiro:
Very well. Send the code via PM, but I will only fix this bug and no other. I will report the bugs in the forum, not in private.

Thank you much.

 
David Diez: Thank you much.
What symbol and what period?
 

No need for the Symbol or Period! I have found your bug! You are placing my code inside a loop that scans all symbols. That is why it does not work.

What do you think a static variable is? You have to understand how a static variable works! You can't just copy/past code into whichever place you feel like it with out understanding how it works.

As it is now it cannot be fixed with a simple code change. It has be replaced with a proper and understandable code logic.

You would have to have a time check for a new bar that is outside of your loop, and instead of depending in the bar data check, you will have to create a time check that is equivalent to the period you wish to use.

 

This is a quick fix, but not the ideal fix as your code has many, many problems and the logic is all over the place.

void OnTick() {
   // Check for New Period
   static long PeriodCurrent  = WRONG_VALUE;
          long PeriodPrevious = PeriodCurrent;
               PeriodCurrent  = (long) TimeCurrent()
                              / PeriodSeconds( WTimeframe );       
          bool NewPeriodFlag  = ( PeriodCurrent != PeriodPrevious );

   // ... your other code ...
   
   for(int s=0;s<SymbolsTotal(true);s++){
   
      // ... your other code ...

      //--------------------------------------------------- Start ---!
      if(NewPeriodFlag){
         // ... the code you posted ...
      }
         
      // ... your other code ...

   }
}
 
Fernando Carreiro:

This is a quick fix, but not the ideal fix as your code has many, many problems and the logic is all over the place.

Ok, I understand this but I've copied just as you've coded it and the result is the same: no trades.

 
David Diez: Ok, now I understand.

Please note that the above solution does not really detect a new bar, but only aligns the timing to the selected period and possible new bar.