Trading script completely ignores conditional standard

 
Hi! I coded a script where the conditionals analyse both daily and one minute time frames, the one conditionals for one day time frame is to buy when the calculations return a value > 0.5 and to sell when the calculations return a value of < -0.5. When trading yesterday on a demo account, my script sold with the EURGBP pair, the issue is however this contradicts the standard of the conditionals as the returned value for the daily time frame was 0.4545454 etc and not a value < -0.5. Does anyone know from experience what would causes a script to contradict it's own conditionals?
 

Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893

⚠️ Please pay attention!

Expert Advisors and Automated Trading

MQL5 forum: Expert Advisors and Automated Trading
MQL5 forum: Expert Advisors and Automated Trading
  • www.mql5.com
How to create an Expert Advisor (a trading robot) for Forex trading
 
And please don't create a new topic every time when clearly this is a continuation of previously discussed EA. Reuse one of your existing topics!
 
Colin Kimble: Does anyone know from experience what would causes a script to contradict it's own conditionals?

Most probably due to Incorrectly coded logic and lack of proper understanding of the basics of both MetaTrader and the MQL functionality.

As I stated before, with reason, start small with a simple EA and build it up as you fully grasp how things work.

As it is now, your EA is still very convoluted, making your debugging process very difficult for you especially as a beginner with MQL coding.

And there is no shortcut. You will have to debug your EA, one way or another, until you find what it is doing wrong.

 
Fernando Carreiro #:

Most probably due to Incorrectly coded logic and lack of proper understanding the basics of both MetaTrader and the MQL functionality.

As I stated before, with reason, start small with a simple EA and build it up as you fully grasp how things work.

As it is now, your EA is still very convoluted, making your debugging process very difficult for you especially as a beginner with MQL coding.

And there is no shortcut. You will have to debug your EA it one way or another, until you find what it is doing wrong.

Thank you for your help, where is the logic incorrect?
 
Colin Kimble #: Thank you for your help, where is the logic incorrect?

You don't really expect us to debug your 1000+ lines of code, do you?

That is not what the forum is for. Did I not previously write ...?

I did not look any further once I spotted the above bug. There may be other bugs. So, dedicate some time to look for any other bugs.

 
Fernando Carreiro #:

You don't really expect us to debug your 1000+ lines of code, do you?

That is not what the forum is for. Did I not previously write ...?

I did not look any further once I spotted the above bug. There may be other bugs. So, dedicate some time to look for any other bugs.

Lol, that wasn't why I was asking. It was because to come to a conclusion it's from something we've seen and thus deduced an outcome. I was asking what was seen to come to the conclusion as stated previously in this exact post that the logic is wrong?
 
Colin Kimble #: I was asking what was seen to come to the conclusion as stated previously in this exact post that the logic is wrong?

Even though your code has evolved a little, I only have to take one quick look at your code to conclude that it's still extremely "messy" and "stringy".

It is convoluted and unstructured, with it's trading logic spread out all over the place, which can easily lead to contradictory functionality.

This may seem arrogant and condescending, but I am doing my best to convince you to go back to drawing board and start with a small and simple EA, until you can fully understand it all.

 

When you deal with market orders

     if(UpMarket == true && BuyMarket == true && OrdersTotal() == 0)

this is not correct, because you are dealing with Positions, so when you execute market orders, it should be:

     if(UpMarket == true && BuyMarket == true && PositionsTotal() == 0)


Please at least first try and build a simplistic EA that follows rules correctly. If you successfully build a simple EA (as advised above) that follows the rules correctly, there will be far less caveats in a bigger project

 
Colin Kimble:
Hi! I coded a script where the conditionals analyse both daily and one minute time frames, the one conditionals for one day time frame is to buy when the calculations return a value > 0.5 and to sell when the calculations return a value of < -0.5. When trading yesterday on a demo account, my script sold with the EURGBP pair, the issue is however this contradicts the standard of the conditionals as the returned value for the daily time frame was 0.4545454 etc and not a value < -0.5. Does anyone know from experience what would causes a script to contradict it's own conditionals?

You might want to try

 

double OneDayCalculation = NormalizeDouble(OneDayCalculationPreCalculation / 22, 1);

good luck

 
Fernando Carreiro #:

Even though your code has evolved a little, I only have to take one quick look at your code to conclude that it's still extremely "messy" and "stringy".

It is convoluted and unstructured, with it's trading logic spread out all over the place, which can easily lead to contradictory functionality.

This may seem arrogant and condescending, but I am doing my best to convince you to go back to drawing board and start with a small and simple EA, until you can fully understand it all.

I appreciate the wisdom!