[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 324

 

Hi all!

I have studied MQL4 Expert Advisor during a month and decided to write an Expert Advisor. I did not want to write a new one due to lack of experience and decided to use tradingexpert.mq4 template from the book.

The essence of the strategy is the following: a three-bar system of "Larry Williams" highs and lows, plot two three-day EMAs for highs and lows, sell

to the highs and buys to the lows.

In the template, in the section of global variables I removed the line extern double Rastvor =28.0; (actually it is not needed) and also removed it from the trading criteria.

Changed MA values to 3 in global variables:

extern int Period_MA_1= 3; // Period MA 1
extern int Period_MA_2= 3; // Period MA 2

In the trading criteria section it was:

//--------------------------------------------------------------- 5 --
   // Торговые критерии
   MA_1_t=iMA(NULL,0,Period_MA_1,0,MODE_LWMA,PRICE_TYPICAL,0); // МА_1
   MA_2_t=iMA(NULL,0,Period_MA_2,0,MODE_LWMA,PRICE_TYPICAL,0); // МА_2
 
   if (MA_1_t > MA_2_t + Rastvor*Point)         // Если разница между
     {                                          // ..МА 1 и 2 большая
      Opn_B=true;                               // Критерий откр. Buy
      Cls_S=true;                               // Критерий закр. Sell
     }
   if (MA_1_t < MA_2_t - Rastvor*Point)         // Если разница между
     {                                          // ..МА 1 и 2 большая
      Opn_S=true;                               // Критерий откр. Sell
      Cls_B=true;                               // Критерий закр. Buy
     }
//--------------------------------------------------------------- 
has become:

//--------------------------------------------------------------- 5 --
// Trade criteria
MA_1_t=iMA(NULL,0,Period_MA_1,0,MODE_EMA,PRICE_HIGH,0); // MA_1
MA_2_t=iMA(NULL,0,Period_MA_2,0,MODE_EMA,PRICE_LOW,0); // MA_2

if (PRICE_HIGH * Point >= MA_1_t * Point)
{
Opn_S=true;
Cls_B=true;
}

if (PRICE_LOW * Point <= MA_2_t * Point)
{
Opn_B=true; //open criterion. Buy
Cls_S=true; // Close Criterion. Sell
}
//---------------------------------------------------------------

Now the crux of the problem: the system only opens sell orders, but does not want to buy. What may be the error?

It's quite possible there are errors somewhere else, please don't judge harshly but help with advice)

 
Forexman77:


//--------------------------------------------------------------- 5 --
// Trading criteria
MA_1_t=iMA(NULL,0,Period_MA_1,0,MODE_EMA,PRICE_HIGH,0); // MA_1
MA_2_t=iMA(NULL,0,Period_MA_2,0,MODE_EMA,PRICE_LOW,0); // MA_2

if (PRICE_HIGH * Point >= MA_1_t * Point)
{
Opn_S=true;
Cls_B=true;
}

if (PRICE_LOW * Point <= MA_2_t * Point)
{
Opn_B=true; //open criterion. Buy
Cls_S=true; // Close Criterion. Sell
}
//---------------------------------------------------------------

Now the crux of the problem: the system only opens sell orders, but does not want to buy. What may be the error?

It is quite possible that I have errors somewhere else. Please don't judge, but help me with advice.)



What is this? PRICE_LOW and PRICE_HIGH. They are integer constants which have value 0 or 1, up to 6.

You must use iHigh(Symbol(),Period(),i) to get the max BID value on bar i, and iLow(Symbol(),Period(),i) to get the min BID value on bar i.

If tumbling on the current bar then: if ( iHigh(Symbol(),Period(),0) >= MA_1_t) And there is no need to multiply MA by Point.

 

Good afternoon to all!

Please tell me what is the problem.

I attached a volume indicator (Volume) to Awesome standard indicator.

I want to organize the calculation of the Total wave volume (counted from Low to High price and corresponds to the Min and Max value of Awesome). See Fig. 1.

fig1

What is the error, the values are not counted.

Below is the code itself.

#property  indicator_separate_window
#property  indicator_buffers 2
#property  indicator_color1  Red
#property  indicator_color2  SteelBlue
#property  indicator_width1  2

//---- basic fan indicator parameters

extern bool Show_AOLine_2=true;
extern int SlowEMA3=34;
extern int EMA=2;
extern bool Show_Volume=true;
extern double coaf=1.5;
extern bool Show_Vol_line=true;
//---- indicator buffers
double AOBuffer3[];
double ExtMapBuffer1[];


double VLUP;
   double prhgh_e=0, prhgh_s, prlw_e=0, prlw_s;
    datetime tmhgh, tmlw;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   //---- drawing settings
   
  string name_ind = "Awesome_super_volumes";
   IndicatorShortName("Awesome_super_volumes");
   
   
//---- AO_fan line 2 (basic)
   if(Show_AOLine_2 ==true){Show_AOLine_2=DRAW_LINE; }
   else 
    {Show_AOLine_2=DRAW_NONE; }
   SetIndexBuffer(0,AOBuffer3);
   SetIndexStyle(0,Show_AOLine_2);
   SetIndexLabel(0,"basic line");   

   SetIndexBuffer(1,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexLabel(1,"Volume");
   
  //---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Awesome Oscillator                                               |
//+------------------------------------------------------------------+
int start()
  {
  
   int    limit;
   int    counted_bars=IndicatorCounted();
   double prev,current;
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;

//---- AO_fan line 2 (basic) buffer
   for(int i=0; i<limit; i++)
   {
     
 //---- AO_fan basic line + Volumes
     
      AOBuffer3[i]=iMA(NULL,0,EMA,0,MODE_SMA,PRICE_MEDIAN,i)-iMA(NULL,0,SlowEMA3,0,MODE_SMA,PRICE_MEDIAN,i);
if (Show_Volume==true)
{
double nSum = Volume[i]*Point*coaf;
   if (AOBuffer3[i]<=0)ExtMapBuffer1[i] = nSum;
   if (AOBuffer3[i]>0)ExtMapBuffer1[i] = -nSum;
}
if (Show_Vol_line==true)
{
double Vol_Arr[];


  if (AOBuffer3[i]<=0)Vol_Arr[i]=Volume[i]*Point*coaf;
  if (AOBuffer3[i]>0)Vol_Arr[i] = -Volume[i]*Point*coaf;}
//---- dispatch values between 2 buffers
   }
   
  //-- Поиск High & Time  
  if (AOBuffer3[i]>=0)
  {
  prhgh_s = High[i];
  if (prhgh_s >= prhgh_e) {prhgh_e = prhgh_s; tmhgh = Time[i];}
  }   
   
  //-- Поиск Low & Time  
  if (AOBuffer3[i]<=0)
  {
  prlw_s = Low[i];
  if (prlw_s > prlw_e) {prlw_e = prlw_s; tmlw = Time[i];}
  } 
  
  // -- Пересчет баров от High до Low
  int colbr = iBarShift(NULL,0,tmhgh)-iBarShift(NULL,0,tmlw);     
  
  int shift=iBarShift(NULL,0,tmlw);
  
 for (i=0; i<=colbr; i++)
{VLUP += MathAbs(iVolume(NULL,0, shift+i));}
       
  SetText("Awesome_super_volumes"+Time[i], DoubleToStr(VLUP,0), tmhgh, 0.0010, Black);     
 
//-- Эти значения должны отображаться в окне Awesome
  SetText2("Волна1",DoubleToStr(VLUP,0),980,10,Gray,10); 
  SetText2("Волна2",TimeToStr(tmlw,0),980,25,Gray,10); 
  SetText2("Волна3",TimeToStr(tmhgh,0),980,40,Gray,10);
  SetText2("Волна4",DoubleToStr(colbr,0),980,55,Gray,10);  
  
  
      
//---- done
   return(0);
  }
//+------------------------------------------------------------------+
void SetText(string name, string Vl, datetime t1, double p1, color c)
 {
 // if (ObjectFind(name)!=-1) ObjectDelete(name);
  ObjectCreate(name,OBJ_TEXT,WindowFind("Awesome_super_volumes"),0,0,0,0);
  ObjectSetText(name, Vl, 10, "Times New Roman", c);
  ObjectSet(name, OBJPROP_TIME1 , t1);
  ObjectSet(name, OBJPROP_PRICE1, p1);
  ObjectSet(name, OBJPROP_COLOR, c); 
  }
  
//--Ввeл дополнительную процедуру для отображения значений на чарте. Ее не должно быть.
  void SetText2(string name, string text, int xdist, int ydist, color c, int size) 
 {                                                                                    
  ObjectCreate(name,OBJ_LABEL,0,0,0,0,0);     
  ObjectSet(name, OBJPROP_XDISTANCE, xdist);
  ObjectSet(name, OBJPROP_YDISTANCE, ydist);    
  ObjectSetText(name,text,7,"Arial Black",c);
 }
 
Sepulca:


What is this? PRICE_LOW and PRICE_HIGH. They are integer constants with value 0 or 1, up to 6.

You should use iHigh(Symbol(),Period(),i) to get max BID value on bar i, and iLow(Symbol(),Period(),i) to get min BID value on bar i.

If tumbling on the current bar, then: if ( iHigh(Symbol(),Period(),0) >= MA_1_t) And there is no need to multiply MA by Point.

Thanks a lot!!! It works!!!
 

Guys, someone tell me what's wrong with the code plz!

 
Fox_RM:

Guys, someone tell me what's wrong with the code plz!


if (Show_Vol_line==true)
{
double Vol_Arr[]; // ошибки: 1. Размещение  2. Область видимости


  if (AOBuffer3[i]<=0)Vol_Arr[i]=Volume[i]*Point*coaf;
  if (AOBuffer3[i]>0)Vol_Arr[i] = -Volume[i]*Point*coaf;}
//---- dispatch values between 2 buffers
   }
   
 
VladislavVG:


I don't quite get it. But there are no problems with the volume display. There are problems with calculating volumes. Somewhere in here.

 //-- Поиск High & Time  
  if (AOBuffer3[i]>=0)
  {
  prhgh_s = High[i];
  if (prhgh_s >= prhgh_e) {prhgh_e = prhgh_s; tmhgh = Time[i];} // -- tmhgh - выводил это значение оно = 0;

  }   
   
  //-- Поиск Low & Time  
  if (AOBuffer3[i]<=0)
  {
  prlw_s = Low[i];
  if (prlw_s > prlw_e) {prlw_e = prlw_s; tmlw = Time[i];}
  } 
  
  // -- Пересчет баров от High до Low
  int colbr = iBarShift(NULL,0,tmhgh)-iBarShift(NULL,0,tmlw);    tmlw - тоже = 0; Почему?
  
  int shift=iBarShift(NULL,0,tmlw);
  
 for (i=0; i<=colbr; i++)
{VLUP += MathAbs(iVolume(NULL,0, shift+i));}
       
  SetText("Awesome_super_volumes"+Time[i], DoubleToStr(VLUP,0), tmhgh, 0.0010, Black);     
 
asdfgh001:

Good afternoon!

My question will be a little off-topic.

Can you please tell me if it is possible to find somewhere the slicing of TA shapes as CSV files? I can use txt, xls or any other formats that can be processed programmatically.

There are examples of TA figures in various TA articles, textbooks, but of course as ordinary pictures. Has anybody got more or less big sets of TA symbols saved as a slice of history of some currency pair on the periods H1-H4, say?

I googled, did not find any. Of course, we can manually go through the history, mark the shapes, export this piece of history as .csv; repeat the required number of times, collect the shape base in the end. But if someone has already done this, would like to save time.

Thanks in advance :)


Why do you need the shapes as CSV files? Write a shape library... Write them yourself, so you can understand them, not borrow someone else's. A lot doesn't mean better!
 
Fox_RM:


I don't quite get it. But there is no problem with displaying volumes. There is a problem with volume counting. Somewhere in here.


1. The array needs to be placed - that is, allocated memory. Otherwise there is simply nowhere to store the values ;).

2. When you receive a new tick your even placed array will be repositioned/reinitialised. This has to do with scope. The array must be of the "static" type to prevent this from happening.

Read something on programming fundamentals.

HZ The problem with counting is where I pointed out the array usage errors to you.

 
VladislavVG:


1. An array must be located, in other words, memory must be allocated. Otherwise, there is just no place to store values ;).

2. When you receive a new tick your even placed array will be repositioned/reinitialised. This has to do with scope. The array must be of the "static" type to prevent this from happening.

Read something on programming fundamentals.

HZ The problem with counting is where I've pointed out errors in array use to you.

I.e.Vol_Arr[] should be initialized as a global array as I understand it.


The question is of course a null question, BUT.

1. Why then the volumes are displayed correctly in the indicator.

2. When calculating, I accessAOBuffer3[] and notVol_Arr[].

Thank you!

Reason: