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

 
Forexman77:

You need to, of course! Well, how do you apply this construction to finding the minimum? I can't figure it out by brainstorming.)
And I want to learn how to declare an array. I tried it this way:

It comes out -1.



The loop goes through 34 values and the array only contains 33 cells, correct.

And try ArrayMinimum(num_array,WHOLE_ARRAY,0);

 
Forexman77:

... I also want to learn how to declare an array...

If just for training and cognitive purpose...

The period at which minimum and maximum are determined - it should be an external parameter to allow for tuning and optimization.

extern int p=34; 

So, first of all, the array is declared without size:

double val[];

The array declaration is done in a common section, not in a function.

In the init function, the size is set to the array:

int init(){

   ArrayResize(val,p);

} 

Now in the start function we fill the array:

for(int i=0;i<p;i++) val[i]=iMA(...,i+1);

Finally , ArrayMaximum() and ArrayMinimum() are applied to the array.

 
Integer:

To find the maximum, the variable val is assigned a value of 0 (obviously less than any of the values of the indictor).

This means that to find the minimum, we must add a deliberately higher value. You can use EMPTY_VALUE constant or the indicator value directly on some bar among which the minimum is searched.

Or like this:

Thank you so much!
 
evillive:

The loop goes through 34 values, while the array contains only 33 cells, fix it.

And try ArrayMinimum(num_array,WHOLE_ARRAY,0);

Thank you very much!
 

Dear fellow programmers! I'm in trouble, please help me.

I've already racked my brains about this code.

//В условии прописано что работаем с 
if(OrderType() == OP_BUY){}
//, но метатрейдер почему то игнорирует это условие, и работает только с OP_SELLLIMIT

Here is the whole function:

//+------------------------------------------------------------------+
//| Модифицируем стоплоссы                                           |
//+------------------------------------------------------------------+   
void modify_stoploss()
  {
   for(int i=0; i<=OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol())
           {
            if(OrderMagicNumber()==magic)
              {
               if(OrderType() == OP_BUY)
                 {
                  if(chek_way()==1)
                    {
                     double stoploss=NormalizeDouble(pre_openPrice(OP_BUY),Digits);
                     Print("Стоплосс для Бай ",OrderTicket()," = ", stoploss);
                     OrderModify(OrderTicket(),OrderOpenPrice(),stoploss,OrderTakeProfit(),0,CLR_NONE);
                    }
                 }
               if(OrderType() == OP_SELL)
                 {
                  if(chek_way()==0)
                    {
                     stoploss=NormalizeDouble(pre_openPrice(OP_SELL),Digits);
                     Print("Стоплосс для Cелл ",OrderTicket()," = ", stoploss);
                     OrderModify(OrderTicket(),OrderOpenPrice(),stoploss,OrderTakeProfit(),0,CLR_NONE);
                    }
                 }
              }
           }
        }
     }
  }

Reaches Print and this is what it outputs:


While ticket: 225299700 is an OP_SELLLIMIT order ticket.

And it modifies the stop loss of this selected order as expected. We don't see OP_BUY, though we surely have them:

What could be the problem? Why is it doing this to me? Please help me understand!

 
#property strict
#include <Indicators\Trend.mqh>
bool ind;
CiMA MA;
extern int pos=1;
extern int sl=40;
extern int tp=70;
datetime time;
datetime time2;
bool trade=false;
bool trade2=false;
int a,b;
int OnInit()
  {
//---
   MA.Create(Symbol(),PERIOD_CURRENT,10,6,MODE_EMA,PRICE_CLOSE);//создал машку
//---
   return(INIT_SUCCEEDED);
   
  }
void OnTick()
  {
//---
  if(IsNewBar()==true)//если новый бар включаемся
     {
     if(buy(pos)==true)//если цена выше МА продолжаем
     {
      if(!ExistPositions(Symbol(),-1,-1,0))//если нету открых ордеров продолжаем
        {

         if(GetTypeLastClosePos(Symbol(),-1)!=OP_BUY)//если тип последней закрытой позиции был не на покупку то тогда только покупаем таким образом я пред остерегаюсь от повторных входов в покупку если цена 
//все ещо выше МА...но почему то не работает открываются и дальше сделки на покупку если ордер закрылся выше МА....ХОТЯ НЕ ДОЛЖО ТАК КАК Я ОГРАНИЧИЛ ПО ТИПУ ПОЗИЦИИ ПОСЛЕДНЮЮ СДЕЛКУ И ОНИ ДОЛЖНЫ ТОЛЬКО 
//       ЧЕРЕДОВАТСЯ И УЖ НИ КАК НЕ ПОВТОРЯТСЯ ПО НЕСКОЛЬКО РАЗ ПОДРЯД
           {
            trade=true;
           }
  if(trade==true)
        {
         OpenPosition(Symbol(),OP_BUY,0.1,Ask-sl*Point,Ask+tp*Point);
         trade=false;
        }
}
        }
    
     
if(sell(pos)==true)
{
   if(!ExistPositions(Symbol(),-1,-1,0))
     {

      if(GetTypeLastClosePos(Symbol(),-1)!=OP_SELL)
        {
         trade2=true;
        }

      if(trade2==true)
        {
         OpenPosition(Symbol(),OP_SELL,0.1,Bid+sl*Point,Bid-tp*Point);
         trade=false;
      }
  }}
 }
  }

//возвращает истину если закрытие бара  с указаной позицией выше МА

bool buy(int pos)
  {
   if(iClose(Symbol(),0,pos)>MA.Main(1))
      return true;
   else
      return false;
  }
//+------------------------------------------------------------------+
//| возвращает истину если закрытие бара  с указаной позицией ниже МА
//+------------------------------------------------------------------+
bool sell(int pos)
  {
   if(iClose(Symbol(),0,pos)<MA.Main(1))
      return true;
   else return false;
  }
ALL FUNCTIONS except the two buy and sell conditions are taken from kim's branch...... please tell me where I went wrong...I need one transaction per intersection
 

another question about the function

/SetRectangle(clrBlue,"Прямоугольник",Time[10],Low[10],Time[0],High[0]);
//Если bk=true, то будет залит цветом, если false - то просто "рамка" ... sz при "просто рамка" - это ширина линий "рамки"
//

//+----------------------------------------------------------------------------+
void SetRectangle(color cl, string nm="", datetime t1=0, double p1=0, datetime t2=0, double p2=0, int sz=0, bool bk=true) {
   if (ObjectFind(nm)<0) ObjectCreate(nm, OBJ_RECTANGLE, 0, 0, 0, 0, 0);
   ObjectSet(nm, OBJPROP_TIME1   ,t1);
   ObjectSet(nm, OBJPROP_PRICE1  ,p1);
   ObjectSet(nm, OBJPROP_TIME2   ,t2);
   ObjectSet(nm, OBJPROP_PRICE2  ,p2);
   ObjectSet(nm, OBJPROP_COLOR   ,cl);
   ObjectSet(nm, OBJPROP_WIDTH   ,sz);
   ObjectSet(nm, OBJPROP_BACK    ,bk);
}

how to make a rectangle draw forward instead of backward, for example five bars forward at a specified price...... and not to redraw it

 
artmedia70:

I've had a look. Thank you.

There's not much information in the question though. There's a lot of extremes on the hour bars in the month. And by the way, extrema of what exactly?


I assumed that there are only two monthly extremes - min and max... Well, whatever, at first it was a long code, that's why I asked for help... But then it dawned on me, I managed to fit it into four lines.
 
Tell me please. In the build above 600. Can the broker give out real volumes?
 
someone write down the structure of a limit order