Solved: Multiframe indicator fails with text, It does not fail with wingdings

 

Good afternoon friends, I am learning how some things work, and I have run into a problem that I do not understand.

It is a multi-frame table for buying and selling (it is only a test to start a project).

The problem is that if I use symbols, everything works fine, but if I use text, when I change the timeframe, the data in the table changes with respect to that time frame.

Anyone else has happened? Do you know what the explanation for this is?



I have selected an example, but the data of the whole table changes

Thank you very much in advance. Please, do not redirect me to the freelance service, on other occasions it has been very helpful, but in this case I am only looking to learn

Files:
 

Hello my friend

I am checking your code, i ll help you, and explain what is problem in this code

 
Ashkan Hazegh Nikrou:

Hello my friend

I am checking your code, i ll help you, and explain what is problem in this code

Thank you very much Ashkan, it drives me crazy, because if I use wingdings this does not happen to me

 

When you change time frame, Indicator will read OnDeinit function and then Init function again.

In graphical panels like this, by change time frame, some texts remain from old time frame calculation.

In this case, you need code in OnDeinit function to remove all exist texts, and do calculation again according to new time frame.

My suggest is to use prefix for all objects, then Delete all objects contain this prefix by each OnDeinit calls.

If you are coder, or you are beginner, its not hard task, you can do it easy, if no, let me know i ll send correct code here.

Have a good time

 
Ashkan Hazegh Nikrou:

When you change time frame, Indicator will read OnDeinit function and then Init function again.

In graphical panels like this, by change time frame, some texts remain from old time frame calculation.

In this case, you need code in OnDeinit function to remove all exist texts, and do calculation again according to new time frame.

My suggest is to use prefix for all objects, then Delete all objects contain this prefix by each OnDeinit calls.

If you are coder, or you are beginner, its not hard task, you can do it easy, if no, let me know i ll send correct code here.

Have a good time

I understand what you mean, but I'm not sure this is the problem. I send another example in which this does not happen to me, and this indicator I have built with the same "mold"

Files:
 
Ashkan Hazegh Nikrou:

When you change time frame, Indicator will read OnDeinit function and then Init function again.

In graphical panels like this, by change time frame, some texts remain from old time frame calculation.

In this case, you need code in OnDeinit function to remove all exist texts, and do calculation again according to new time frame.

My suggest is to use prefix for all objects, then Delete all objects contain this prefix by each OnDeinit calls.

If you are coder, or you are beginner, its not hard task, you can do it easy, if no, let me know i ll send correct code here.

Have a good time

I can't solve it, with the same file with wingdings it works, I change it to label and not anymore.  I change the timeframe and everything moves
 

Your algorithm was requesting the first historically encountered bar from all timeframes . Thats not problematic if the bar is 0 (the most recent) but if each timeframe has a different amount of historically available bars , you understand what the problem is .

try this : 

#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 1
bool initFinished=false;
int period[]={1,5,15,30,60,240,1440,10080,43200};
string periodString[]={"M1","M5","M15","M30","H1","H4","D1","W1","MN1"};
string SignalNameString[]={"MA20","MA50","MA100","BULLS","BEARS","MACD","ADX(14)","CCI(14)","AO"};
int scaleX=60, // horizontal interval at which the squares are created
    scaleY=30, // vertical interval
    offsetX=50, // horizontal indent of all squares
    offsetY=50, // vertical indent
    fontSize=30, // font size
    corner=0;
input color SignalBuyColor=clrDodgerBlue;//Buy Color:
input color SignalSellColor=clrOrangeRed;//Sell Color:
input color SignalErrorColor=clrGray;//Error Color:
input color TfDecallsColor=clrGoldenrod;//TF Color:
input color IndyColor=clrWhiteSmoke;//Indy Color:
input int MA_Period_1 = 20;//MA1 Period : 
input int MA_Period_2 = 50;//MA2 Period : 
input int MA_Period_3 = 100;//MA3 Period : 
input int Bulls_Period = 13;//Bulls Period
input int Bears_Period = 13;//Bears Period
input int Fast_EMA = 12;//Fast EMA
input int Slow_EMA = 26;//Slow EMA
input int MACD_SMA = 9;//MACD SMA
input int ADX_Period = 14;//ADX Period 
input int CCI_Period = 14;//CCI Period
//--- indicator buffers
double Buffer1[];
double Buffer2[];
double Buffer3[];
double Buffer4[];
double Buffer5[];
double Buffer6[];
double Buffer7[];
double Buffer8[];
double Buffer9[];
double Buffer10[];
double Buffer11[];
double Buffer12[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   uint indynames_max=0;
   TextSetFont("Arial Black",8,0,0);
   int subwin=0;
   int tsw=WindowFind("Multi Info Panel");
   if(tsw==-1){tsw=(int)ChartGetInteger(ChartID(),CHART_WINDOWS_TOTAL)-1;}
   for(int y=0; y<8; y++){
   uint w,h;
   TextGetSize(SignalNameString[y],w,h);
   if(w>indynames_max){indynames_max=w;}}
   int xm=(int)(indynames_max+offsetX);
   for(int x=0; x<9; x++){
   for(int y=0; y<8; y++){
   string coordinates=IntegerToString(x)+"_"+IntegerToString(y);
   ObjectCreate("Signal"+coordinates,OBJ_LABEL,tsw,0,0,0,0);
   ObjectSet("Signal"+coordinates,OBJPROP_CORNER,corner);
   ObjectSet("Signal"+coordinates,OBJPROP_XDISTANCE,x*scaleX+xm);
   ObjectSet("Signal"+coordinates,OBJPROP_YDISTANCE,y*scaleY+offsetY);
   ObjectSetText("Signal"+coordinates,"",10,"Arial Black",SignalErrorColor);}}
   //names of timeframes
   for(int x=0;x<9;x++){
   ObjectCreate("textPeriod"+IntegerToString(x),OBJ_LABEL,tsw,0,0,0,0);
   ObjectSet("textPeriod"+IntegerToString(x),OBJPROP_XDISTANCE,x*scaleX+xm+(scaleX/2));
   ObjectSet("textPeriod"+IntegerToString(x),OBJPROP_YDISTANCE,offsetY);
   ObjectSetText("textPeriod"+IntegerToString(x),periodString[x],8,"Arial Black",TfDecallsColor);
   ObjectSetDouble(ChartID(),"textPeriod"+IntegerToString(x),OBJPROP_ANGLE,90);
   ObjectSetInteger(ChartID(),"textPeriod"+IntegerToString(x),OBJPROP_ANCHOR,ANCHOR_LEFT);}
   //names of indicators
   for(int y=0; y<8; y++){
   ObjectCreate("textSignal"+IntegerToString(y),OBJ_LABEL,tsw,0,0,0,0);
   ObjectSet("textSignal"+IntegerToString(y),OBJPROP_XDISTANCE,(xm-xm/4));
   ObjectSet("textSignal"+IntegerToString(y),OBJPROP_YDISTANCE,y*scaleY+offsetY);
   ObjectSetText("textSignal"+IntegerToString(y),SignalNameString[y],8,"Arial Black",IndyColor);
   ObjectSetInteger(ChartID(),"textSignal"+IntegerToString(y),OBJPROP_ANCHOR,ANCHOR_RIGHT_UPPER);}
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime& time[],
                const double& CLOSE[],
                const double& high[],
                const double& low[],
                const double& close[],
                const long& tick_volume[],
                const long& volume[],
                const int& spread[])
  {
  //--- main loop
   for(int i=0;i>=0;i--)
     {
      if(i==0){
      //Loop to timeframes starts here
      for(int x=0; x<9; x++)
        {
         //Indicator Buffer 1
         string which=IntegerToString(x)+"_0";bool buy=false;int errors=0;ResetLastError();
         if(iMA(NULL,period[x],MA_Period_1,0,MODE_SMA, PRICE_CLOSE,1+i)<=iMA(NULL,period[x],MA_Period_1,0,MODE_SMA,PRICE_CLOSE,i)){buy=true;}
         errors+=GetLastError();
         if(buy&&errors==0){ObjectSetText("Signal"+which,"BUY",10,"Arial Black",SignalBuyColor);}
         if(!buy&&errors==0){ObjectSetText("Signal"+which,"SELL",10,"Arial Black",SignalSellColor);}
         if(errors>0){ObjectSetText("Signal"+which,"ERROR",10,"Arial Black",SignalErrorColor);}
         //Indicator Buffer 2
         which=IntegerToString(x)+"_1";buy=false;errors=0;ResetLastError();
         if(iMA(NULL,period[x],MA_Period_2,0,MODE_SMA,PRICE_CLOSE,1+i)<=iMA(NULL,period[x],MA_Period_2,0,MODE_SMA,PRICE_CLOSE,i)){buy=true;}
         errors+=GetLastError();
         if(buy&&errors==0){ObjectSetText("Signal"+which,"BUY",10,"Arial Black",SignalBuyColor);}
         if(!buy&&errors==0){ObjectSetText("Signal"+which,"SELL",10,"Arial Black",SignalSellColor);}
         if(errors>0){ObjectSetText("Signal"+which,"ERROR",10,"Arial Black",SignalErrorColor);}
         //Indicator Buffer 3
         which=IntegerToString(x)+"_2";buy=false;errors=0;ResetLastError();
         if(iMA(NULL,period[x],MA_Period_3,0,MODE_SMA,PRICE_CLOSE,1+i)<=iMA(NULL,period[x],MA_Period_3,0,MODE_SMA,PRICE_CLOSE,i)){buy=true;}
         errors+=GetLastError();
         if(buy&&errors==0){ObjectSetText("Signal"+which,"BUY",10,"Arial Black",SignalBuyColor);}
         if(!buy&&errors==0){ObjectSetText("Signal"+which,"SELL",10,"Arial Black",SignalSellColor);}
         if(errors>0){ObjectSetText("Signal"+which,"ERROR",10,"Arial Black",SignalErrorColor);}
         //Indicator Buffer 4
         which=IntegerToString(x)+"_3";buy=false;errors=0;ResetLastError();
         if(iBullsPower(NULL,period[x],Bulls_Period,PRICE_CLOSE,1+i)<=iBullsPower(NULL,period[x],Bulls_Period,PRICE_CLOSE,i)){buy=true;}
         errors+=GetLastError();
         if(buy&&errors==0){ObjectSetText("Signal"+which,"BUY",10,"Arial Black",SignalBuyColor);}
         if(!buy&&errors==0){ObjectSetText("Signal"+which,"SELL",10,"Arial Black",SignalSellColor);}
         if(errors>0){ObjectSetText("Signal"+which,"ERROR",10,"Arial Black",SignalErrorColor);}
         //Indicator Buffer 5
         which=IntegerToString(x)+"_4";buy=false;errors=0;ResetLastError();
         if(iBearsPower(NULL,period[x],Bears_Period,PRICE_CLOSE,1+i)<=iBearsPower(NULL,period[x],Bears_Period,PRICE_CLOSE,i)){buy=true;}
         errors+=GetLastError();
         if(buy&&errors==0){ObjectSetText("Signal"+which,"BUY",10,"Arial Black",SignalBuyColor);}
         if(!buy&&errors==0){ObjectSetText("Signal"+which,"SELL",10,"Arial Black",SignalSellColor);}
         if(errors>0){ObjectSetText("Signal"+which,"ERROR",10,"Arial Black",SignalErrorColor);}
         //Indicator Buffer 6
         which=IntegerToString(x)+"_5";buy=false;errors=0;ResetLastError();
         if(iMACD(NULL,period[x],Fast_EMA,Slow_EMA,MACD_SMA,PRICE_CLOSE,MODE_MAIN,1+i)<=iMACD(NULL,period[x],Fast_EMA,Slow_EMA,MACD_SMA,PRICE_CLOSE,MODE_MAIN,i)){buy=true;}
         errors+=GetLastError();
         if(buy&&errors==0){ObjectSetText("Signal"+which,"BUY",10,"Arial Black",SignalBuyColor);}
         if(!buy&&errors==0){ObjectSetText("Signal"+which,"SELL",10,"Arial Black",SignalSellColor);}
         if(errors>0){ObjectSetText("Signal"+which,"ERROR",10,"Arial Black",SignalErrorColor);}
         //Indicator Buffer 7
         which=IntegerToString(x)+"_6";buy=false;errors=0;ResetLastError();
         if(iADX(NULL, period[x],ADX_Period,PRICE_CLOSE,MODE_MAIN,1+i)<=iADX(NULL,period[x],ADX_Period,PRICE_CLOSE,MODE_MAIN,i)){buy=true;}
         errors+=GetLastError();
         if(buy&&errors==0){ObjectSetText("Signal"+which,"BUY",10,"Arial Black",SignalBuyColor);}
         if(!buy&&errors==0){ObjectSetText("Signal"+which,"SELL",10,"Arial Black",SignalSellColor);}
         if(errors>0){ObjectSetText("Signal"+which,"ERROR",10,"Arial Black",SignalErrorColor);}
         //Indicator Buffer 8
         which=IntegerToString(x)+"_7";buy=false;errors=0;ResetLastError();
         if(iCCI(NULL, period[x],CCI_Period,PRICE_TYPICAL,1+i)<=iCCI(NULL,period[x],CCI_Period,PRICE_TYPICAL,i)){buy=true;}
         errors+=GetLastError();
         if(buy&&errors==0){ObjectSetText("Signal"+which,"BUY",10,"Arial Black",SignalBuyColor);}
         if(!buy&&errors==0){ObjectSetText("Signal"+which,"SELL",10,"Arial Black",SignalSellColor);}
         if(errors>0){ObjectSetText("Signal"+which,"ERROR",10,"Arial Black",SignalErrorColor);}
         }}
     }//main loop ends here
   return(prev_calculated);
  }//OnCalculate ends here
void OnDeinit(const int reason)
  {
  ObjectsDeleteAll();
  } 
 
Lorentzos Roussos:

Your algorithm was requesting the first historically encountered bar from all timeframes . Thats not problematic if the bar is 0 (the most recent) but if each timeframe has a different amount of historically available bars , you understand what the problem is .

try this : 

Wow! What a great job, as always Lorentzos! I had not thought in any case that this could be the problem.

Working perfectly with this new code. I really appreciate this great work and your time. I wish you good luck, you are a great guy!

 
Enrique Enguix Vino:

Wow! What a great job, as always Lorentzos! I had not thought in any case that this could be the problem.

Working perfectly with this new code. I really appreciate this great work and your time. I wish you good luck, you are a great guy!

You are welcome . happy sales