English

Simple loop Problem

 11 hilfx 2014.07.23 22:02   Hey everybody,I try to create a little output into the expert log on MT4.What I do:int start() {int i;for (i=0; i<=2; i++) {double lB_EURJPY_D = iBands("EURJPY",PERIOD_D1,20,2,i,PRICE_CLOSE,MODE_LOWER,0);double uB_EURJPY_D = iBands("EURJPY",PERIOD_D1,20,2,i,PRICE_CLOSE,MODE_UPPER,0); //PrintPrint("\$","EURJPY D","\$",Time[i],"\$",DoubleToString(lB_EURJPY_D,1),"\$",DoubleToString(uB_EURJPY_D,1),      "\$",DoubleToString(Low[i],1)      );}; Print("EURJPY D ready");  // EURUSD Dfor (i=0; i<=2; i++) {double lB_EURUSD_D = iBands("EURUSD",PERIOD_D1,20,2,i,PRICE_CLOSE,MODE_LOWER,0);double uB_EURUSD_D = iBands("EURUSD",PERIOD_D1,20,2,i,PRICE_CLOSE,MODE_UPPER,0);//PrintPrint("\$","EURUSD D","\$",Time[i],"\$",DoubleToString(lB_EURUSD_D,1),"\$",DoubleToString(uB_EURUSD_D,1),      "\$",DoubleToString(Low[i],1)      );     };Print("EURUSD D ready");                     return(0);}  What I get: 22:00:45 Custom indicator _FULL_Output_Daily_2 GBPAUD,Daily: loaded successfully22:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: initialized22:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURJPY D\$2014.07.23 00:00:00\$136.4\$139.6\$1.822:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURJPY D\$2014.07.22 00:00:00\$136.6\$139.6\$1.822:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURJPY D\$2014.07.21 00:00:00\$136.9\$139.5\$1.822:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: EURJPY D ready22:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURUSD D\$2014.07.23 00:00:00\$1.3\$1.4\$1.822:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURUSD D\$2014.07.22 00:00:00\$1.3\$1.4\$1.822:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURUSD D\$2014.07.21 00:00:00\$1.4\$1.4\$1.822:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: EURUSD D ready22:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURJPY D\$2014.07.23 00:00:00\$136.4\$139.6\$1.822:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURJPY D\$2014.07.22 00:00:00\$136.6\$139.6\$1.822:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURJPY D\$2014.07.21 00:00:00\$136.9\$139.5\$1.822:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: EURJPY D ready22:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURUSD D\$2014.07.23 00:00:00\$1.3\$1.4\$1.822:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURUSD D\$2014.07.22 00:00:00\$1.3\$1.4\$1.822:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURUSD D\$2014.07.21 00:00:00\$1.4\$1.4\$1.822:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: EURUSD D ready22:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURJPY D\$2014.07.23 00:00:00\$136.4\$139.6\$1.822:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURJPY D\$2014.07.22 00:00:00\$136.6\$139.6\$1.822:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURJPY D\$2014.07.21 00:00:00\$136.9\$139.5\$1.822:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: EURJPY D ready22:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURUSD D\$2014.07.23 00:00:00\$1.3\$1.4\$1.822:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURUSD D\$2014.07.22 00:00:00\$1.3\$1.4\$1.822:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURUSD D\$2014.07.21 00:00:00\$1.4\$1.4\$1.822:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: EURUSD D ready  Can anybody tell me why do I get the right output but 3 times? For me it looks strange ...Thanks for any helpHilfx
 Moderator3523 GumRai 2014.07.23 22:40 #   hilfx: Hey everybody,I try to create a little output into the expert log on MT4. Can anybody tell me why do I get the right output but 3 times? For me it looks strange ...Thanks for any helpHilfx  I'm not sure what your question is aboutYou get 3 prints because of`for (i=0; i<=2; i++)` It looks strange because you are only printing 1 decimal place`DoubleToString(lB_EURJPY_D,1)` Change to`DoubleToString(lB_EURJPY_D,3)` and EURUSD to 5 decimal places
13130
WHRoeder 2014.07.24 02:20 #

 GumRai:It looks strange because you are only printing 1 decimal place Change to`DoubleToString(lB_EURJPY_D,3)` and EURUSD to 5 decimal places Don't hard code numbers```string   PriceToStr(double p){   return( DoubleToStr(p, Digits) ); } ```

Moderator
3523
GumRai 2014.07.24 04:33 #

WHRoeder:
 GumRai:It looks strange because you are only printing 1 decimal place Change to`DoubleToString(lB_EURJPY_D,3)` and EURUSD to 5 decimal places Don't hard code numbers`string   PriceToStr(double p){   return( DoubleToStr(p, Digits) ); }`

My suggestion was a simple fix for the OP's code as I didn't want to complicate it with MarketInfo and Digits.

Your suggestion will simply Print using the Digits for the chart symbol that the EA/indicator is attached to

 11 hilfx 2014.07.24 12:43 #   GumRai: I'm not sure what your question is about You get 3 prints because of  It looks strange because you are only printing 1 decimal place  Change to  and EURUSD to 5 decimal places   Thanks for your answers. I exprect to get this output   22:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURJPY D\$2014.07.23 00:00:00\$136.4\$139.6\$1.8 22:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURJPY D\$2014.07.22 00:00:00\$136.6\$139.6\$1.8 22:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURJPY D\$2014.07.21 00:00:00\$136.9\$139.5\$1.8 22:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: EURJPY D ready 22:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURUSD D\$2014.07.23 00:00:00\$1.3\$1.4\$1.8 22:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURUSD D\$2014.07.22 00:00:00\$1.3\$1.4\$1.8 22:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURUSD D\$2014.07.21 00:00:00\$1.4\$1.4\$1.8 22:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: EURUSD D ready The numbers of decimals doesn't matter. But why do I get my exprected output 3 times?
 11 hilfx 2014.07.24 12:47 #   GumRai: I'm not sure what your question is about You get 3 prints because of  It looks strange because you are only printing 1 decimal place  Change to  and EURUSD to 5 decimal places   Thanks for your answer. The decimal places doesn't matter in this case. I exprect to get 3 prints but only one time. Why do I get 8 lines? Actually there must be 6 (3 for EURJPY and 3 for EURUSD). I don't know, its a limple for-loop but the output is wrong ...
 Moderator3523 GumRai 2014.07.24 12:53 #   hilfx: Thanks for your answers. I exprect to get this output   22:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURJPY D\$2014.07.23 00:00:00\$136.4\$139.6\$1.8 22:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURJPY D\$2014.07.22 00:00:00\$136.6\$139.6\$1.8 22:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURJPY D\$2014.07.21 00:00:00\$136.9\$139.5\$1.8 22:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: EURJPY D ready 22:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURUSD D\$2014.07.23 00:00:00\$1.3\$1.4\$1.8 22:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURUSD D\$2014.07.22 00:00:00\$1.3\$1.4\$1.8 22:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: \$EURUSD D\$2014.07.21 00:00:00\$1.4\$1.4\$1.8 22:00:46 _FULL_Output_Daily_2 GBPAUD,Daily: EURUSD D ready The numbers of decimals doesn't matter. But why do I get my exprected output 3 times? Ah, I see, you mean why is your code repeated 3 times.Maybe there were 3 ticks?Is this a script?
 11 hilfx 2014.07.24 12:57 #   GumRai: Ah, I see, you mean why is your code repeated 3 times. Maybe there were 3 ticks? Is this a script?   No, its an indicator and I turned the chart offline, otherwise I'll get the output on every new tick. I simply wanna have some historic data for analysis.
 11 hilfx 2014.07.24 17:28 #   I did it run as a script and its working :-) Thanks to you guys for help!