Learning logic

 

It's really quite simple. There is a desire to help others do the best code, and to learn from others.

It's no secret that one eventually develops quite certain stereotypes which sometimes (most often) help and sometimes hinder.

I will prepare a variant of the indicator and try to explain what has been done and why. If you are interested, of course.

 

Da, interesno!

Valera

 

on the example of an EA please, no one is interested in indicators.

 

Well, then I'm a nobody.

))) Told you the other day, I'm a forum glitch, a phantasm, a fata morgana...

 
Svinozavr:

Well, that makes me a nobody.

))) Told you the other day - I'm a forum glitch, a fiction, a fata-morgana...

But always in the right place at the right time. That's nice!

 

Victor, what inspired you to do this feat? On this forum, it's not just about logic, 90 per cent of them are not in the right mind.

Aren't you afraid of getting bogged down in this swamp? You'll have to deal with more than just the 10% who are competent...

===

I join in congratulations... I'll even drink to you, and to the success of your hopeless venture...

"Go alone and heal the blind,
To know, in the hour of doubt.
"The disciples' gloating mockery
And the indifference of the crowd."
// Akhmatova

 
Vinin:

It's really quite simple. There is a desire to help others do the best code, and to learn from others.

It's no secret that one eventually develops quite certain stereotypes which sometimes (most often) help and sometimes hinder.

I will prepare a variant of the indicator and try to explain what has been done and why. If you are interested, of course.

//+-------------------------------------------------------------------------+
//| ver.RA                                                         all1.mq4 |
//|                                               Copyright © 2010, age_nt  |
//+-------------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1 Green
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color4 LightGray
#property indicator_color5 DarkOrange

#property indicator_level1 40
#property indicator_level2 20
#property indicator_level3 0
#property indicator_level4 -20
#property indicator_level5 -40

extern int       MA     =     10;
extern bool      all = FALSE; 
//---- Буферы индикатора
double EUR_Buffer[];
double USD_Buffer[];
double GBP_Buffer[];
double CHF_Buffer[];
double JPY_Buffer[];
//---- Переменные
int BarsMin=1000;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators

   IndicatorBuffers(5);

   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));

//---- indicator line
   SetIndexBuffer(0,EUR_Buffer);
   SetIndexBuffer(1,USD_Buffer);
   SetIndexBuffer(2,GBP_Buffer);
   SetIndexBuffer(3,CHF_Buffer);
   SetIndexBuffer(4,JPY_Buffer);
   
   bool showEUR, showUSD, showGBP, showCHF, showJPY, showRAVI;
   if ( StringFind(Symbol(), "EUR", 0) != -1) showEUR = TRUE;
   if ( StringFind(Symbol(), "USD", 0) != -1) showUSD = TRUE;
   if ( StringFind(Symbol(), "GBP", 0) != -1) showGBP = TRUE;
   if ( StringFind(Symbol(), "CHF", 0) != -1) showCHF = TRUE;
   if ( StringFind(Symbol(), "JPY", 0) != -1) showJPY = TRUE;

   if ( all== TRUE || showEUR == TRUE ) SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,DodgerBlue);
   else SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,0,CLR_NONE);
   if ( all == TRUE || showUSD == TRUE ) SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1,ForestGreen);
   else SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,0,CLR_NONE);
   if ( all == TRUE || showGBP == TRUE ) SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1,FireBrick);
   else SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,0,CLR_NONE);
   if ( all == TRUE || showCHF == TRUE ) SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,1,LightBlue);
   else SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,0,CLR_NONE);
   if ( all == TRUE || showJPY == TRUE ) SetIndexStyle(4,DRAW_LINE,STYLE_SOLID,1,Orange);
   else SetIndexStyle(4,DRAW_LINE,STYLE_SOLID,0,CLR_NONE);


   SetIndexLabel(0,"EUR");
   SetIndexLabel(1,"USD");
   SetIndexLabel(2,"GBP");
   SetIndexLabel(3,"CHF");
   SetIndexLabel(4,"JPY");

   
   SetIndexDrawBegin(0,0);
   SetIndexDrawBegin(1,0);
   SetIndexDrawBegin(2,0);
   SetIndexDrawBegin(3,0);
   SetIndexDrawBegin(4,0);

   
   IndicatorShortName("all1");

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
     int limit,i;
//     string S=Symbol();
     int counted_bars=IndicatorCounted();
     
  //---- проверка на возможные ошибки
     if(counted_bars<0) return(-1);

  //---- вычисление минимального кол-ва баров (длины отображаемого графика)
     if(counted_bars==0)
       {
       BarsMin=iBars("GBPUSD",NULL);
       if(BarsMin>iBars("USDCHF",NULL)) BarsMin=iBars("USDCHF",NULL);
       if(BarsMin>iBars("EURUSD",NULL)) BarsMin=iBars("EURUSD",NULL);
       if(BarsMin>iBars("USDJPY",NULL)) BarsMin=iBars("USDJPY",NULL);
       if(BarsMin>iBars("EURGBP",NULL)) BarsMin=iBars("EURGBP",NULL);
       if(BarsMin>iBars("EURCHF",NULL)) BarsMin=iBars("EURCHF",NULL);
       if(BarsMin>iBars("EURJPY",NULL)) BarsMin=iBars("EURJPY",NULL);
       if(BarsMin>iBars("GBPCHF",NULL)) BarsMin=iBars("GBPCHF",NULL);
       if(BarsMin>iBars("GBPJPY",NULL)) BarsMin=iBars("GBPJPY",NULL);
       if(BarsMin>iBars("CHFJPY",NULL)) BarsMin=iBars("CHFJPY",NULL);
       }

 //   
 Message(Vl(Symbol(),0,0));  
     
  //---- последний посчитанный бар будет пересчитан
     if(counted_bars>0) counted_bars--;
     limit=Bars-counted_bars;
     if(limit>BarsMin-2) limit=BarsMin-2;
     
  //---- основной цикл

   //   for (i = 0; i<=limit;i++)
   //    {

   //    USD_Buffer[i]=USD(i);
   //    EUR_Buffer[i]=EUR(i); 
   //    GBP_Buffer[i]=GBP(i); 
   //    CHF_Buffer[i]=CHF(i); 
   //    JPY_Buffer[i]=JPY(i); 
  //     }
 
 
     //---- Вычисление индексов
     for (i = 0; i<=limit;i++)
      {
       USD_Buffer[i]=USD(i);
       EUR_Buffer[i]=EUR(i); 
       GBP_Buffer[i]=GBP(i); 
       CHF_Buffer[i]=CHF(i); 
       JPY_Buffer[i]=JPY(i); 
      }
     
//----
   return(0);
  }

//+------------------------------------------------------------------+
double USD(int j)
  {
  double val = 0;
  double GBP_USD=-Cl("GBPUSD",j);
  double USD_CHF=Cl("USDCHF",j);
  double EUR_USD=-Cl("EURUSD",j);
  double USD_JPY=Cl("USDJPY",j);
  val=(GBP_USD+USD_CHF+EUR_USD+USD_JPY)/4;
  return(val);
  }
//+------------------------------------------------------------------+
double GBP(int j)
  {
  double val = 0;
  double GBP_USD=Cl("GBPUSD",j);
  double EUR_GBP=-Cl("EURGBP",j);
  double GBP_CHF=Cl("GBPCHF",j);
  double GBP_JPY=Cl("GBPJPY",j);
  val=(EUR_GBP+GBP_USD+GBP_CHF+GBP_JPY)/4;
  return(val);
  }
//+------------------------------------------------------------------+
double EUR(int j)
  {
  double val = 0;
  double EUR_USD=Cl("EURUSD",j);
  double EUR_GBP=Cl("EURGBP",j);
  double EUR_CHF=Cl("EURCHF",j);
  double EUR_JPY=Cl("EURJPY",j);
  val=(EUR_USD+EUR_GBP+EUR_CHF+EUR_JPY)/4;  
  return(val);
  }
//+------------------------------------------------------------------+
double CHF(int j)
  {
  double val = 0;
  double USD_CHF=-Cl("USDCHF",j);
  double EUR_CHF=-Cl("EURCHF",j);
  double GBP_CHF=-Cl("GBPCHF",j);
  double CHF_JPY=Cl("CHFJPY",j);
  val=(USD_CHF+EUR_CHF+GBP_CHF+CHF_JPY)/4;
  return(val);
  }
//+------------------------------------------------------------------+
double JPY(int j)
  {
  double val = 0;
  double USD_JPY=-Cl("USDJPY",j);
  double EUR_JPY=-Cl("EURJPY",j);
  double GBP_JPY=-Cl("GBPJPY",j);
  double CHF_JPY=-Cl("CHFJPY",j);
  val=(USD_JPY+EUR_JPY+GBP_JPY+CHF_JPY)/4;
  return(val);
  }
//+------------------------------------------------------------------+
double Cl(string symb,int shift) 
  {
   double SMA1,SMA2,result,a,b; double k = 100*Vl(symb,0,shift); 
   double point = MarketInfo(symb,MODE_POINT); 
   double digits = MarketInfo(symb,MODE_DIGITS); 
   SMA1=iMA(symb,0,(101-k),0,MODE_LWMA,PRICE_TYPICAL,shift); 
   SMA2=iMA(symb,0,k,0,MODE_LWMA,PRICE_TYPICAL,shift); 
   result=((SMA1-SMA2)/(SMA2+0.000000001))*100;   
   a=50*(MathExp(2*result)-1)/(MathExp(2*result)+1);
   double norm = (a/point/100);    
   double target=NormalizeDouble(a,digits);  
   return(target);
  }   
double Vl(string symb,int tf,int Shi)  
{
 double v; //double k = Vol(symb,0,Bar); 
 if(iVolume(symb,0,Shi+1)<iVolume(symb,0,Shi+2)) v= iVolume(symb,0,Shi+1)/(0.0000001 +iVolume(symb,0,Shi+2));
 else v= iVolume(symb,0,Shi+2)/(0.0000001 +iVolume(symb,0,Shi+1));
 double fff=NormalizeDouble(v,2);
 return(fff); 
 }  
//+------------------------------------------------------------------+
//| Comment                                                          |
//+------------------------------------------------------------------+ 
//
void Message(string m) {  Comment(m);  if (StringLen(m)>0) Print(m);} 
//+------------------------------------------------------------------+     
Victor! If I understand correctly, you are ready to help.... I can't understand where I have "no logic"
 
age_nt:
Victor! If I understand correctly, you are ready to help.... I can't understand where I have "no logic"
Files:
logika.zip  254 kb
 

Thanks Dimitri for your attention...I respect your knowledge....and humour of course.

Couldn't appreciate it - no MSoffffffis installed

 
age_nt:

Thanks Dimitri for your attention...I respect your knowledge....and humour of course.

Couldn't appreciate it - no MSoffffffis installed.

You know, we don't have a problem. Especially for YOU in text format. You obviously have the zipper.

Files:
logika2.zip  90 kb
 
Also for the particularly resourceful, who don't have an office or a zip.
Files:
logika3.mq4  277 kb
Reason: