Hello everyone,
After wrinting serveral indicators for the first time, I'm facing a simple, but very annoying, problem. My indicators work well. But they update to the current situation only if I change my timeframe to another one. If I keep my screen on the same timeframe, the situation between my parameters (SMA and price), after a couple of time, has changed but my indicator did not. The updating to the current situation will be done only if I change from timeframe or I compile my script.
Can anyone tell me if I missed something in my coding ?
Steve
Use SRC and show your code if someone has to answer questions about the code
Thkx for reply
Here's my script, the comments are in french.
But I want to do with this indicator is simple : draw a square Wingdings (green or red) and send an alert in case the conditions are true for each timeframe.
I specified the conditions for each timeframe because I use a different Shift for my Signal MM (MM_50_Signal) depending on each timeframe.
Thks in advance if you see what's wrong in my coding.
If you find it to complex to understand, I will send a more simple wich I face the same problem.
//+------------------------------------------------------------------+ //| Test_Dammier_dernière_version.mq4 | //| Copyright 2013, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright 2013, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" #property indicator_chart_window //---- déclaration des paramètres relatifs aux moyennes mobiles double prix,prix_M5,prix_M30,prix_4H,prix_D1,MM_20_M1,MM_20_M5,MM_20_M30,MM_20_H4,MM_20_D1, MM_50_M1,MM_50_M5,MM_50_M30,MM_50_H4,MM_50_D1, MM_50_Signal_M1,MM_50_Signal_M5,MM_50_Signal_M30,MM_50_Signal_H4,MM_50_Signal_D1; //---- déclaratio des paramètres formels int factupD1,factupH4,factup30,factup5,factup1,factdnD1,factdnH4,factdn30,factdn5,factdn1; int nbreBarres; //---- déclaration des paramètres relatifs à la création du dammmier extern int corner=3,Xdist=20,Ydist=20,Xécart=40,Yécart=20; string TF[]={"M1","M5","M30","H4","D1"}; //---- déclaration des paramètres formels relatifs au dammier int a=0,b=0,c=0; //---- déclaration des paramètres MACD double MACD_M_D1,MACD_M_H4,MACD_M_M30,MACD_M_M5,MACD_M_M1, MACD_S_D1,MACD_S_H4,MACD_S_M30,MACD_S_M5,MACD_S_M1; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators //---- initialisation des valeurs prix et moyennes mobiles prix=Bid; MM_20_M1=iMA(Symbol(),PERIOD_M1,20,0,0,0,1); MM_50_M1=iMA(Symbol(),PERIOD_M1,50,0,2,0,1); MM_50_Signal_M1=iMA(Symbol(),PERIOD_M1,50,38,2,0,1); //---- initilisation des paramètres formels factup1=0; factdn1=1; //---- squares creation for(int a=0;a<5;a++)//paramètre pour Ydistance for(int b=0;b<2;b++)//paramètre pour Xdistance { ObjectCreate("dammier"+a+b,OBJ_LABEL,0,0,0,0,0); ObjectSet("dammier"+a+b,OBJPROP_CORNER,corner); ObjectSet("dammier"+a+b,OBJPROP_XDISTANCE,b*Xdist+Xécart); ObjectSet("dammier"+a+b,OBJPROP_YDISTANCE,a*Ydist+Yécart); }//colors activated in Start() return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- ObjectsDeleteAll(); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { //---- 1 ---- Affecation des couleurs du dammier en fonction de la situation des MM et de leur TF //---- conditions Bullish à M1 if(prix>MM_20_M1&&MM_20_M1>MM_50_M1&&MM_50_M1>MM_50_Signal_M1) {ObjectSetText("dammier00",CharToStr(110),10,"Wingdings",LimeGreen); if(factup1==0) Alert(Symbol()," - UPTREND à M1"); factup1=1; factdn1=0; } else ObjectDelete("dammier00"); //---- conditions Bearish à M1 if(prix<MM_20_M1&&MM_20_M1<MM_50_M1&&MM_50_M1<MM_50_Signal_M1) {ObjectSetText("dammier01",CharToStr(110),10,"Wingdings",Red); if(factdn1==0) Alert(Symbol()," - DOWNTREND à M1"); factup1=0; factdn1=1; } else ObjectDelete("dammier01"); //---- return(0); } //+------------------------------------------------------------------+
int start(){ if(prix>MM_20_M1&&MM_20_M1>MM_50_M1&&MM_50_M1>MM_50_Signal_M1){ ObjectSetText(...Where are you updating your variables?
Nowhere, that's exactly my question. What I understood from the mql4 documentation is that data's update automatically from the broker's server.
But, what i see in concreto when I use my indicator, this one or another one, is that the situation between the parameters (MM and price) change after a couple of time on my screen and my indicator does not, unless if I change from timeframe of if I compile my script again.
I wonder if I missed something in order that my indicator changes from colour at the moment that the situation changes on on the graph and not when I change from timeframe or I compile again.
5462ZARDOZ: Nowhere, that's exactly my question. What I understood from the mql4 documentation is that data's update automatically from the broker's server.
Do I have to use refreshrates() before setting my square (red or green) in case the conditions are true ?
- Only the predefined variables automatically update at the beginning of start()
- RefreshRates() updates only the predefined variables - required ONLY after delays (sleep, between multiple server calls, network delays.)
//+------------------------------------------------------------------+ //| Test_Dammier.mq4 | //| Copyright 2013, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright 2013, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" #property indicator_chart_window //---- squares variables int corner=3,Xdist=20,Ydist=20,Xindent=20,Yindent=20; int TF[]={1,5,30,240,1440}; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators for(int a=0;a<5;a++) { ObjectCreate("square"+a,OBJ_LABEL,0,0,0,0,0); ObjectSet("square"+a,OBJPROP_CORNER,corner); ObjectSet("square"+a,OBJPROP_XDISTANCE,Xdist+Xindent); ObjectSet("square"+a,OBJPROP_YDISTANCE,a*Ydist+Yindent); ObjectSetText("square"+a,CharToStr(110),10,"Wingdings",Gold); } //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { for(int b=0;b<5;b++) { if(iClose(Symbol(),TF[b],1)>iMA(Symbol(),TF[b],20,0,0,0,1)) ObjectSetText("square"+b,CharToStr(110),10,"Wingdings",LimeGreen); if(iClose(Symbol(),TF[b],1)<iMA(Symbol(),TF[b],20,0,0,0,1)) ObjectSetText("square"+b,CharToStr(110),10,"Wingdings",Red); } //---- return(0); } //+------------------------------------------------------------------+
Ok, thanks for your comments.
I understand now where my error comes from. In my first scipt I wanted to code a signal for each timeframe manually wrinting a code for each timeframe.
But now I've written a code testing the situation for each timeframe dinamically. Here's the code above.
Now, is there a solution to get an Alert when the condition is true on one of each timeframe ?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello everyone,
After wrinting serveral indicators for the first time, I'm facing a simple, but very annoying, problem. My indicators work well. But they update to the current situation only if I change my timeframe to another one. If I keep my screen on the same timeframe, the situation between my parameters (SMA and price), after a couple of time, has changed but my indicator did not. The updating to the current situation will be done only if I change from timeframe or I compile my script.
Can anyone tell me if I missed something in my coding ?
Steve