Download MetaTrader 5

if else conditional operator problem

To add comments, please log in or register
Have you developed an application? Publish it in Code Base!
REH2001
36
REH2001 2013.12.18 21:44 
How arrows look when indi is run..//top
// if(Close[i+Time2]<Open[i+Time1]){
if(V2<Close[i+Time2]){         
sObjName="FXPTlblUpAr2"+i;
 ObjectCreate(sObjName, OBJ_ARROW, 0, Time[i+Time1],Low[i+Time1]-ArrowSpacing2*Poin);   
 ObjectSet(sObjName, OBJPROP_ARROWCODE, 241); 
 ObjectSet(sObjName, OBJPROP_COLOR, OpenTxtClr2);
  BotAr++;
}

if(V2<Open[i+Time1]){
sObjName="FXPTlblUpAr"+i;
 ObjectCreate(sObjName, OBJ_ARROW, 0, Time[i+Time1],Low[i+Time1]-ArrowSpacing*Poin);   
 ObjectSet(sObjName, OBJPROP_ARROWCODE, 241); 
 ObjectSet(sObjName, OBJPROP_COLOR, OpenTxtClr);
  BotAr++;
}                              

Hi, I am just learning how to program in mql4 for metaTrader .. I have run into the following problem with the if else coditional operator statement...

<CODE REMOVED>

What this does is put two rows of arrows below the charts candles... the top row can only be Lime Green, by the defined variable OpenTxtClr = Lime Green, and second row arrow can only be Yellow by the defined variable Open TxtClr2 = Yellow up inthe Global area... however when the program is compiled and run on the chart . Sometimes the bottom or second row of arrows shows a Lime green arrow... The top row of arrows are fine... no problems there... I can not figure out why some of the bottom row of arrows show up as lime green instead of Yellow.... I am confused with the if else operator anyways... So if you can spot what I have done wrong please explain how I can fix this..... If you should need more info let me know ... the program is a bit long, but other then defining the appropriate variables this part is the only part that really pertains to the two rows of arrows... Thank you.

Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2013.12.18 22:48  
REH:

Hi, I am just learning how to program in mql4 for metaTrader .. I have run into the following problem with the if else coditional operator statement...

<CODE REMOVED>

What this does is put two rows of arrows below the charts candles... the top row can only be Lime Green, by the defined variable OpenTxtClr = Lime Green, and second row arrow can only be Yellow by the defined variable Open TxtClr2 = Yellow up inthe Global area... however when the program is compiled and run on the chart . Sometimes the bottom or second row of arrows shows a Lime green arrow... The top row of arrows are fine... no problems there... I can not figure out why some of the bottom row of arrows show up as lime green instead of Yellow.... I am confused with the if else operator anyways... So if you can spot what I have done wrong please explain how I can fix this..... If you should need more info let me know ... the program is a bit long, but other then defining the appropriate variables this part is the only part that really pertains to the two rows of arrows... Thank you.

Have you checked the properties of the arrows that you think are the wrong colours to check their names and verified they are in fact the wrong colour, not just the wrong positions ?
REH2001
36
REH2001 2013.12.19 01:07  
RaptorUK:
Have you checked the properties of the arrows that you think are the wrong colours to check their names and verified they are in fact the wrong colour, not just the wrong positions ?


Problem corrected... It seems the number 2 at the end of the name ---> sObjName="FXPTlblUpAr2"+i; Was not being recognized... Does that sound right... because I changed the name, and it corrected the displayed arrows on the chart...hmmmm :-)



whroeder1
14532
whroeder1 2013.12.19 02:17  
REH: ---> sObjName="FXPTlblUpAr2"+i; Was not being recognized... Does that sound right...

I is a bar index which changes each bar. Once you create the object xxxx1 you can't create it again so on subsequent bars your ObjectCreate fails.

  1. What are Function return values ? How do I use them ? - MQL4 forum
  2. Use a unique name for your object like "xxxx" +Time[i] not "xxxx" + i
  3. If it was an indicator, you could use buffers to create the arrow and avoid the problems with objects.
To add comments, please log in or register