[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 325

 

Can you tell me how to prescribe when the difference of two EMAs (five days/minimum and maximum) increases, to sell long at the maximum EMA and buy short at the minimum EMA?

I use "Rastvor" in global variable header as the difference of two EMAs .

How do I write this code in the trading criteria?

 
Fox_RM:

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 are the volumes displayed correctly in the indicator?

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

Thank you!


When declaring an array (not a buffer) you should explicitly specify its size.... at least.
 
Fox_RM:

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 are the volumes displayed correctly in the indicator?

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

Thank you!

1.
if (Show_Volume==true)
{
double nSum = Volume[i]*Point*coaf;
   if (AOBuffer3[i]<=0)ExtMapBuffer1[i] = nSum;
   if (AOBuffer3[i]>0)ExtMapBuffer1[i] = -nSum;
}
Both arrays that you use are connected to indicator buffers, i.e. they are allocated memory (though implicitly)
SetIndexBuffer(0,AOBuffer3);
   SetIndexStyle(0,Show_AOLine_2);
   SetIndexLabel(0,"basic line");   

   SetIndexBuffer(1,ExtMapBuffer1);

You don't allocate memory for this array(Vol_Arr[]) either statically or dynamically.

2. As far as I see from the code, the difference of MA and not volumes is calculated in theAOBuffer3[] array

   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;
}

The volumes are counted inExtMapBuffer1.

Vol_Arr[] can be initialized as a global one or with a static modifier - you can choose your own, but memory should be allocated in any case or you can link it to the indicator buffer, as well as the previous two arrays - sure, there are plenty of variants.

 
VladislavVG:
1) Both arrays that you use are connected with indicator buffers, i.e. the memory is allocated for them (though implicitly).

......

Vladislav, I have reviewed the code again. A part of the code withVol_Arr[]was left from the old version of the indicator, I deleted it.

I think the error is still in this part of the code, but I don't understand where! I have commented out this part of the code in more details.

 
  //-- Поиск High & Time  
  if (AOBuffer3[i]>=0) Если Awesome больше нуля
  {
  prhgh_s = High[i];                                            // -----
  if (prhgh_s >= prhgh_e) {prhgh_e = prhgh_s; tmhgh = Time[i];}  --- Ищу самый высокий бар и определяю время этого бара // -- пока значение  tmhgh = 0
  }   
   
  //-- Поиск Low & Time  
  if (AOBuffer3[i]<=0) Если Awesome меньше нуля
  {
  prlw_s = Low[i];                                          // -----
  if (prlw_s > prlw_e) {prlw_e = prlw_s; tmlw = Time[i];}    --- Ищу самый низкий бар и определяю время этого бара // -- пока значение  tmlw = 0
  } 
  // -- Пересчет баров от High до Low
  int colbr = iBarShift(NULL,0,tmhgh)-iBarShift(NULL,0,tmlw);  //-- Здесь считаю общее количество баров от наименьшего до наибольшего значения // -- пока значение  colbr = 0
  
  int shift=iBarShift(NULL,0,tmlw); // -- Это точка отсчета
  
 for (i=0; i<=colbr; i++)
{VLUP += MathAbs(iVolume(NULL,0, shift+i));} //-- Значению VLUP суммируем все объемы начиная от самого низкого бара до самого высокого бара // -- Значение  VLUP = 47

Fig2

 
Fox_RM:

Vladislav, I have reviewed the code again. A part of the code withVol_Arr[]was left from the old version of the indicator, I deleted it.

I think that the error is still in this part of the code, but I don't understand where! I commented this part of the code in more detail.

OK, post the full code again, which now works - let's see.
 

Here it is:

#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;
}
  }
   
  //-- Поиск High & Time  
  if (AOBuffer3[i]>=0) //Если Awesome больше нуля
  {
  prhgh_s = High[i];                                            // -----
  if (prhgh_s >= prhgh_e) {prhgh_e = prhgh_s; tmhgh = Time[i];}  //--- Ищу самый высокий бар и определяю время этого бара // -- пока значение tmhgh = 0
  }   
   
  //-- Поиск Low & Time  
  if (AOBuffer3[i]<=0) //Если Awesome меньше нуля
  {
  prlw_s = Low[i];                                          // -----
  if (prlw_s > prlw_e) {prlw_e = prlw_s; tmlw = Time[i];}   // --- Ищу самый низкий бар и определяю время этого бара // -- пока значение tmlw = 0
  } 
  // -- Пересчет баров от High до Low
  int colbr = iBarShift(NULL,0,tmhgh)-iBarShift(NULL,0,tmlw);  //-- Здесь считаю общее количество баров от наименьшего до наибольшего значения // -- пока значение colbr = 0
  
  int shift=iBarShift(NULL,0,tmlw); // -- Это точка отсчета
  
 for (i=0; i<=colbr; i++)
{VLUP += MathAbs(iVolume(NULL,0, shift+i));} //-- Значению VLUP суммируем все объемы начиная от самого низкого бара до самого высокого бара // -- Значение VLUP = 47
       
  SetText("Awesome_super_volumes"+Time[i], DoubleToStr(VLUP,0), tmhgh, 0.0010, Black);     
 
  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); 
  }
  
  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);
 }

Thank you again!

 
Fox_RM:

Here it is:



At a glance:

   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;
}
  } // здесь цикл закончился
   
  //-- Поиск High & Time  
  if (AOBuffer3[i]>=0) //Если Awesome больше нуля
  {
  prhgh_s = High[i];                                            // -----
  if (prhgh_s >= prhgh_e) {prhgh_e = prhgh_s; tmhgh = Time[i];}  //--- Ищу самый высокий бар и определяю время этого бара // -- пока значение tmhgh = 0
  }   
   
  //-- Поиск Low & Time  
  if (AOBuffer3[i]<=0) //Если Awesome меньше нуля
  {
  prlw_s = Low[i];                                          // -----
  if (prlw_s > prlw_e) {prlw_e = prlw_s; tmlw = Time[i];}   // --- Ищу самый низкий бар и определяю время этого бара // -- пока значение tmlw = 0
  } 

The highlighted fragment is outside the loop and it uses the loop counter i - something is wrong either with the logic or with the implementation

 
hoz:

Why do you need the figures as CSV files?

Needed for testing and debugging recognition algorithms.

hoz:

Write them yourself to understand them rather than taking someone else's.

Write what exactly? You mean, mark up the shapes on the chart yourself and export the appropriate chunks of history? This solution is the first on the queue so far, but I still hope that someone has already done it. After all, it's just a chore.

hoz:

Plenty does not mean better!

Let me disagree. The larger the test suite, the more statistically reliable the result of the program will be.


p.s. The question is still valid.(See question in this post )

 

Hi all!!!

Could you please tell me what code is needed to make a long close at the maximum of the current MA.

Below is the actual trading criteria and highlighted in red what is not clear.

Also not clear how to tell the program to exit a position,

after increasing the difference between MA1 and MA2?

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

if ( iHigh (Symbol(),Period(),0) >= MA_1_t) //
{
Opn_S=true;
}
if ( iLow (Symbol(),Period(),0) <= MA_2_t) //
{
Opn_B=true; // Open Buy criterion
}
if(what code is needed to make a long close at today's maximum iMA?? )
{
Cls_B=true;
}
//--------------------------------------------------------------- 6 --

 
VladislavVG:


Just a quick look:

The highlighted fragment is outside the loop and it uses the i loop counter - something is wrong either with the logic or with the implementation


Thank you Vladislav! Something has started to work. But for some reason only like this! :(

fig3

Another question why text labels are not displayed in the indicator window?

// -- Процедура
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); 
  }
// -- Обращение
SetText("Awesome_super_volumes", DoubleToStr(VLUP,0), tmhgh, dist, Black);