Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 130

 
Danila_mactep:
Hi all! Please advise me on this subject... I want to shift MA level in levels tab. If I want to shift it to 798, it is too complicated to calculate for many pairs. How to write an indicator that either draws the price of shifted moving average or displays it in the data window and I don't have to calculate it manually?
You can create an indicator with a MA shift in its input data. And the indicator will calculate the price level and immediately display its objects on the chart.
 
chief2000:
Such a problem - there is a one-dimensional array whose size can vary.
How to loop through all possible combinations of array elements with each other?
The order of elements doesn't matter, i.e. 123==213==321...

Here is an example for an array with 4 elements:


It is a good task for your brain. You can try this:
int start(){
 double array[4];
 int k,N[];
 k=ArraySize(array);
 ArrayResize(N,k);
 for (int i=0;i<k;i++)N[i]=-i-1;// Заполнили массив элементов массива отрицательными
//
 int j=0;
 while(N[k-1]<k){
  if(N[j]<k-1){
   N[j]++;
   bool NewComb=false;
   for(i=0;i<k-1;i++){
    if(N[i]>N[i+1]){NewComb=true;}else{NewComb=false;break;}
   }
//
   if(NewComb){
// Получили новую комбинацию в массиве N размерностью k    
    string temp="";
    for(i=0;i<k;i++){// Перебираем массив N. Если N[i] то элемент array[N[i]] не участвует в выборке.
                     // Например, для размерности 4 если N[0]=3,N[1]=1,N[2}<0,N[3]<0 то это выборка array[3] и array[1]
                     //                             если N[0]=3,N[1]=2,N[2]=1,N[3]=0 то это выборка array[3] и array[2] array[1] и array[0]
     if(N[i]<0)temp=StringConcatenate(temp,"X");else temp=StringConcatenate(temp,N[i]);
    }
   Print("NEWCOMB ",temp);// это для проверки какие комбинации выбираются
   }
//
  }
  else{
   N[j]=0;i=1;
   while(i<k){
    if(N[i]<k-1) {if(N[i]>=0)N[i]++;else N[i]=0;j=0;break;}
    else {N[i]=0;i++;}
   }
  }
  if(N[k-1]>=k-1) break;
 }
 return;
}

Test result for dimension 4. If X element of the array is not selected, otherwise use array[digit] and fragment for dimension 6:

 
artmedia70:
Make an indicator whose input data will specify the MA shift. And the indicator will calculate the price level and immediately display its objects on the chart.


I do not know how to do it and, frankly speaking, I have no idea how - when I open the МА МА code, there is so much stuff there that I do not see where the level parameter is, so I cannot copy and paste levels.
 
Danila_mactep:

I don't know how to do it and, to be honest, I have no idea how to do it - I open the MA code, there is so much stuff there that I don't see where the level parameter is, so I can copy and paste levels in it. What part of the MA code should I copy and where should I paste levels?
You have to start writing your own indicator and they will tell you what to do.
 
artmedia70:
No, you need to start writing your own indicator, and then they will tell you what you need to do.

I have created a new indicator, so far it looks like this:

#property copyright "Copyright 2013, MetaQuotes Software Corp.
#property link "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red
//--- buffers
double ExtMapBuffer1[];
//+------------------------------------------------------------------+
//| Custom indicator initialisation function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
#include "Moving Averages.mq4"
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//----

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

 
 
There are levels in the MA indicator. The question is this - how can we get data from these levels, say the price has reached the 100 or -100 level (open a buy/sell trade).
 
alexey1979621:
There are levels in the MA indicator. The question is this - how can we get data from these levels, say the price has reached level 100 or -100 (open a buy/sell trade).

The MA itself on the zero (current) bar is:

double priceMA0=iMA(Symbol(), Period(), MA_Period, MA_Shift, MA_ Method, PRICE_OPEN, 0);

To calculate the MA, we take the Open price to get rid of the "chatter" on the current bar.

Then the price of level +100 will be:

double priceP100=priceMA0+100*Point;

The level price of -100 will be:

double priceM100=priceMA0-100*Point;
 
artmedia70:

The MA itself on the zero (current) bar is:

To calculate the MA, we take the Open price to get rid of the "chatter" on the current bar.

Then the price of level +100 will be:

The level price of -100 would be:


Thank you, you've helped me out more than once. I'm sure I'll get to grips with the programming soon.....
 
Sepulca:

A good task for the brain. You can try it like this:

Test result for dimension 4. If X element of array is not selected, otherwise use array[digit] and fragment for dimension 6:


I looked at your code, but I don't understand the following - you didn't read the data of the original array at any of the steps. only the number of elements in it