Download MetaTrader 5
To add comments, please log in or register
Develop trading robots to order. Make profit with Freelance service!
ruth26
21
ruth26 2016.10.04 18:54 

Hello, fellow coders!

I have been working on my trend indicator lately and here is how the code looks like so far:

//+------------------------------------------------------------------------------------------------------------------+
// YOU CAN CHANGE THESE PARAMETERS ACCORDING TO YOUR TASTE:
//+------------------------------------------------------------------------------------------------------------------+
int     tfnumber      = 9; // Number of the timeframes
int     tframe[]      = {1,5,15,30,60,240,1440,10080,43200}; // Timeframes in minutes
string  tf[]          = {"MN1","W1","D1","H4","H1","M30","M15","M5","M1"};
double  IndVal[][9];    // Be the second array-index equal with tfnumber
double  TrendVal[][7];
int     NumberOfPairs = 7; // Number of the pairs
string  Pairs[]       = {"GBPUSD.c","EURUSD.c","AUDUSD.c","NZDUSD.c","USDCHF.c","USDCAD.c","USDJPY.c"}; // Requested pairs


extern string IndicatorSettings=">>> Moving Average settings:<<<";
extern int FastSMAofC_Mode = 0; //0=sma  
extern int FastSMAofC_Period = 5; //sma period 
extern int FastSMAofC_PriceMode = 0; //0=close,1=open,2=high,3=low
extern int SlowSMAofC_Mode = 0; //0=sma
extern int SlowSMAofC_Period = 10; //sma period
extern int SlowSMAofC_PriceMode = 0; //0=close,1=open,2=high,3=low
extern int TwentySMAofH_Mode = 0; //0=sma
extern int TwentySMAofH_Period = 20; //sma period
extern int TwentySMAofH_PriceMode = 2; //0=close,1=open,2=high,3=low
extern int TwentySMAofL_Mode = 0; //0=sma
extern int TwentySMAofL_Period = 20; //sma period
extern int TwentySMAofL_PriceMode = 3; //0=close,1=open,2=high,3=low

//+------------------------------------------------------------------------------------------------------------------+



//+------------------------------------------------------------------------------------------------------------------+





extern color      UpColor                     = Green;
extern color      DownColor                   = Red;
extern color      FlatColor                   = Yellow;
extern color      FontColor                   = White;
extern color      MidDownColor                = Orange; 
extern color      MidUpColor                  = LightGreen;
extern int        PosX                        = 1320;
extern int        PosY                        = 100;


double SlowSMA,FastSMA,TwentySMAofH,TwentySMAofL;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 
   for(int w=0;w<NumberOfPairs;w++)
      {
      for(int j=0;j<tfnumber;j++)
      {
         ObjectCreate("BigTrendInd"+w+j,OBJ_LABEL,0,0,0,0,0);
         ObjectSet("BigTrendInd"+w+j,OBJPROP_CORNER,0);
         ObjectSet("BigTrendInd"+w+j,OBJPROP_XDISTANCE,j*23+PosX+50);
         ObjectSet("BigTrendInd"+w+j,OBJPROP_YDISTANCE,w*23+PosY+10);
         ObjectSetText("BigTrendInd"+w+j,CharToStr(110),12,"Wingdings",Silver);
      } 
      }
   
   for(w=0;w<NumberOfPairs;w++)
      {
         ObjectCreate("BigTrendPairs"+w,OBJ_LABEL,0,0,0,0,0);
         ObjectSet("BigTrendPairs"+w,OBJPROP_CORNER,0);
         ObjectSet("BigTrendPairs"+w,OBJPROP_XDISTANCE,PosX);
         ObjectSet("BigTrendPairs"+w,OBJPROP_YDISTANCE,w*23+PosY+11);
         ObjectSetText("BigTrendPairs"+w,Pairs[w],8,"Tahoma",FontColor);
      }
   for(int q=1;q<tfnumber+1;q++)
      {
         ObjectCreate(tf[q-1],OBJ_LABEL,0,0,0,0,0);
         ObjectSet(tf[q-1],OBJPROP_CORNER,1);
         ObjectSet(tf[q-1],OBJPROP_XDISTANCE,(q-1)*23+62);
         ObjectSet(tf[q-1],OBJPROP_YDISTANCE,PosY-10);
         ObjectSetText(tf[q-1],tf[q-1],8,"Tahoma",White);
      }      
   
 
   ObjectCreate("BigTrendLine0",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("BigTrendLine0",OBJPROP_CORNER,0);
   ObjectSet("BigTrendLine0",OBJPROP_XDISTANCE,PosX+83);
   ObjectSet("BigTrendLine0",OBJPROP_YDISTANCE,NumberOfPairs*16+PosY-150);
   ObjectSetText("BigTrendLine0","   ----------------------",8,"Tahoma",FontColor);
   
   ObjectCreate("BigTrendLine1",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("BigTrendLine1",OBJPROP_CORNER,0);
   ObjectSet("BigTrendLine1",OBJPROP_XDISTANCE,PosX+83);
   ObjectSet("BigTrendLine1",OBJPROP_YDISTANCE,NumberOfPairs*16+PosY-155);
   ObjectSetText("BigTrendLine1","   ----------------------",8,"Tahoma",FontColor);

   ObjectCreate("BigTrendIndName",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("BigTrendIndName",OBJPROP_CORNER,0);
   ObjectSet("BigTrendIndName",OBJPROP_XDISTANCE,PosX+113);
   ObjectSet("BigTrendIndName",OBJPROP_YDISTANCE,NumberOfPairs*16+PosY-165);
   ObjectSetText("BigTrendIndName","MA Trend",8,"Tahoma",FontColor);
   
   
      
      
   ArrayResize(IndVal,NumberOfPairs);


   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   for(int w=0;w<NumberOfPairs;w++)
      {
      for(int j=0;j<tfnumber;j++)
      {
      ObjectDelete("BigTrendInd"+w+j);
      }
      }   
      
   for(w=0;w<NumberOfPairs;w++)
      {
         ObjectDelete("BigTrendPairs"+w);
      }
      
   ObjectDelete("BigTrendLine0");
   ObjectDelete("BigTrendLine1");
   ObjectDelete("BigTrendIndName");
      
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   
   for(int z=0;z<NumberOfPairs;z++)
      {
   for(int x=0;x<tfnumber;x++)
      {
      
      
      SlowSMA=iMA(Pairs[z],tframe[x],SlowSMAofC_Period,0,SlowSMAofC_Mode,SlowSMAofC_PriceMode,0);
      FastSMA=iMA(Pairs[z],tframe[x],FastSMAofC_Period,0,FastSMAofC_Mode,FastSMAofC_PriceMode,0);      
      TwentySMAofH=iMA(Pairs[z],tframe[x],TwentySMAofH_Period,0,TwentySMAofH_Mode,TwentySMAofH_PriceMode,0);
      TwentySMAofL=iMA(Pairs[z],tframe[x],TwentySMAofL_Period,0,TwentySMAofL_Mode,TwentySMAofL_PriceMode,0);

       

        if (SlowSMA < FastSMA && FastSMA > TwentySMAofH)   // STRONG UPTREND
        {
        IndVal[z][x]=2; TrendVal[z][x]=100;
        }
        else if (SlowSMA > FastSMA && FastSMA > TwentySMAofH)   // UPTREND
        {
        IndVal[z][x]=1; TrendVal[z][x]=75;
        }
        else if (FastSMA > TwentySMAofL && FastSMA < TwentySMAofH)   // RANGING
        {
        IndVal[z][x]=0; TrendVal[z][x]=50;
        }
        else if (FastSMA > SlowSMA && FastSMA < TwentySMAofL)   // DOWNTREND
        {
        IndVal[z][x]=-1; TrendVal[z][x]=25;
        }
        else if (FastSMA < SlowSMA && FastSMA < TwentySMAofL)   // STRONG DOWNTREND
        {
        IndVal[z][x]=-2; TrendVal[z][x]=0;
        }






      }
      }
     
   
   for(int q=0;q<NumberOfPairs;q++)
      {
      for(int y=0;y<tfnumber;y++)
      {
         if(IndVal[q][y]==-2) ObjectSetText("BigTrendInd"+q+y,CharToStr(234),12,"Wingdings",DownColor); 
         if(IndVal[q][y]==-1) ObjectSetText("BigTrendInd"+q+y,CharToStr(238),12,"Wingdings",MidDownColor);
         if(IndVal[q][y]==0) ObjectSetText("BigTrendInd"+q+y,CharToStr(232),12,"Wingdings",FlatColor);
         if(IndVal[q][y]==1) ObjectSetText("BigTrendInd"+q+y,CharToStr(236),12,"Wingdings",MidUpColor);
         if(IndVal[q][y]==2) ObjectSetText("BigTrendInd"+q+y,CharToStr(233),12,"Wingdings",UpColor);                  
      }
      }

double value1,value2,value3,value4,value5,value6,value7;
 
 value1 = 






   return(0);
  }
//----

 





//+------------------------------------------------------------------+

Here is how it looks on a chart so far:

Now comes the problem. I am trying to evaluate the overall trend strength with a % number on the right side of the indicator. It will be 7 values. So I have added ->

double  TrendVal[][7];

and assigned different arrows the values I wanted ->

 if (SlowSMA < FastSMA && FastSMA > TwentySMAofH)   // STRONG UPTREND
        {
        IndVal[z][x]=2; TrendVal[z][x]=100;
        }

but I still have to define the value1 to value7 somehow ->

double value1,value2,value3,value4,value5,value6,value7;
 
 value1 = 


What would be the most optimal way of doing this?

/
To add comments, please log in or register