Compiler error?

Back to topics list To post a new topic, please log in or register
avatar
6
sievm 2015.07.11 11:56
 

When I coded an IF statement of this pattern, it has caused the abnormal behavior.(MQL4)

 

if (Trend == "RANGE")

{

   A = 0;//(an processing example) 

}else

   if (Trend == "UP")

   {

      OrderSend();//(an processing example) 

   }else //←This else statement means (Trend == "DOWN") independently.

   {

      if (Trend == "DOWN")//←This if statement is what I was coded wrong.

      {

         OrderClose();//(an processing example) 

      }

   }

}


When the condition was (Trend == "UP"), OrderClose() will occur, too.

When the condition was (Trend == "DOWN"), OrderSend() will occur, too.


 I'm sorry when this was a mistake.

 

avatar
13010
WHRoeder 2015.07.11 16:21 #
 
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Don't use strings when you mean an enumeration. What happens if you accidentally write Trend="Down";? What happens if you use an enumeration and write Trend=Down;?
    enum trend { RANGE, UP, DOWN };
    trend Trend = ...;
    
    if (Trend == RANGE){
       A = 0;//(an processing example) 
    }else if (Trend == UP){
       OrderSend();//(an processing example) 
    }else if (Trend == DOWN){
      OrderClose();//(an processing example) 
    }
  3. When the condition was (Trend == "UP"), OrderClose() will occur, too.

    When the condition was (Trend == "DOWN"), OrderSend() will occur, too.

    You code says UP OrderSend. DOWN OrderClose.

avatar
6
sievm 2015.07.11 18:42 #
 
WHRoeder:

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Don't use strings when you mean an enumeration. What happens if you accidentally write Trend="Down";? What happens if you use an enumeration and write Trend=Down;?
  3. When the condition was (Trend == "UP"), OrderClose() will occur, too.

    When the condition was (Trend == "DOWN"), OrderSend() will occur, too.

    You code says UP OrderSend. DOWN OrderClose.

1. I'm sorry. I don't attach it.

2. Thank you for explanation of MQL5. I can't understand MQL5 yet so well. 

3. When "Trend == UP" OrderSend() should be occur. But phenomenon that OrderClose() was executed, too. It has occurred many times.

    When "Trend == DOWN" OrderClose() should be occur. But phenomenon that OrderSend() was executed, too. It has occurred many times.

So I understand now.

 

avatar
13010
WHRoeder 2015.07.11 21:45 #
 
  1. I posted for large amounts attach
  2. I didn't mention anything about MT5
  3. Not by your posted code. "code says UP OrderSend. DOWN OrderClose." Of course we can't see your Trend code so if you're processing bar zero opens and closes can occur many times in a candle.
avatar
313
JD4 2015.07.11 21:51 #
 
seivm, MQL5 will not work with the MT4 trading platform.  If you are trying to write code for MT5, then that will work.  If you are trying to code for MT4 (which I think is the most likely given you are on the MQL4 forum), then you need to use the MQL4 language.  Since the metaeditor can process both MQL4 and MQL5, you need to make sure that you are editing and compiling from 4.
avatar
6
sievm 2015.07.12 09:13 #
 
JD4:
seivm, MQL5 will not work with the MT4 trading platform.  If you are trying to write code for MT5, then that will work.  If you are trying to code for MT4 (which I think is the most likely given you are on the MQL4 forum), then you need to use the MQL4 language.  Since the metaeditor can process both MQL4 and MQL5, you need to make sure that you are editing and compiling from 4.

Thank you for letting me know.

 

avatar
6
sievm 2015.07.12 09:57 #
 
WHRoeder:
  1. I posted for large amounts attach
  2. I didn't mention anything about MT5
  3. Not by your posted code. "code says UP OrderSend. DOWN OrderClose." Of course we can't see your Trend code so if you're processing bar zero opens and closes can occur many times in a candle.

1. I'm sorry.

2. Indeed. I seems don't know all of the MQL4.

3. "code says UP OrderSend. DOWN OrderClose." ⇒ Yes.

   if you're processing bar zero opens and closes can occur many times in a candle. ⇒ Yes indeed ! That was the phenomenon. Well, it was a bar 1. I spend about 4 days about the phenomenon. There was no logical mistake except abnormal if statement.

 

Tens of minutes after correction of the if statement, forex market was closed. I felt my EA become stable. I'm going to confirm if it is stable next week in a long enough time. I have attached just the displaying phenomenon. Thank you.

 

avatar
13010
WHRoeder 2015.07.12 14:12 #
 
sievm: Tens of minutes after correction of the if statement, forex market was closed. I felt my EA become stable. I'm going to confirm if it is stable next week in a long enough time.

Tester is for testing.
avatar
6
sievm 2015.07.12 16:03 #
 
WHRoeder:
sievm: Tens of minutes after correction of the if statement, forex market was closed. I felt my EA become stable. I'm going to confirm if it is stable next week in a long enough time.

Tester is for testing.

I still have never used Forex Tester. Only exclusively forward testing. Thank you.

 

avatar
313
JD4 2015.07.12 19:19 #
 
sievm:

Thank you for letting me know.

 

Welcome, and good luck with your program. :)
avatar
6
sievm 2015.07.13 15:54 #
 
JD4:
Welcome, and good luck with your program. :)

Thank you JD4. 

The phenomenon was reproduced on Monday. ^^;

The cause was not our compiler. :)

 

Back to topics list  

To add comments, please log in or register