Download MetaTrader 5

Problem with array

To add comments, please log in or register

Hi all.

Plz  explain to me if this code should work. I want to use ZigZag to manage SL. In order that i look for 3 last value>0 of the indicator. Than I want to use this 3 values in further conditions. Will this 3 val change in every thick? (I copied essential part of code, because whole thing has over 500 lines ).

Will it "zigzag0< zigzag2 && zigzag0<zigzag1 && zigzag1>zigzag2 && Close[1]<zigzag2" be cheeked every thick? i suppose no...Plz help me make it work.

ZZDepth,ZZDeviation,ZZBackstep are input int
void  SLman()
{  int type, ticket;
   int total = OrdersTotal();  
   double pip2dbl = Point;    // 1/tysiąc, nie 10 tys
          if(Digits  == 3  || Digits == 5) {pip2dbl = 10.0 * Point; }
   double openPrice, stopPrice, zigzag0, zigzag1, zigzag2, SLforSell, SLforBuy;
   double SAR0 = iSAR(Symbol(),PERIOD_H1,SARstep,SARmaxstep,0);
   double SAR1 = iSAR(Symbol(),PERIOD_H1,SARstep,SARmaxstep,1);
   double ATRd = iCustom(NULL,PERIOD_D1,"MTR",MTRperiod,0,1);
    SLforSell= MathRound((zigzag1+0.04*ATRd)/Point)*Point;
    SLforBuy=  MathRound((zigzag1-0.04*ATRd)/Point)*Point;
double ZZ3val[3];  
 int k=0;
 int l=0;
 for(l,k ; l<200 && k<=2 ; l++)
   { if(iCustom(NULL,PERIOD_H1,"ZigZag",ZZDepth,ZZDeviation,ZZBackstep,0,l)>0)  
         { ZZ3val[k]=iCustom(NULL,PERIOD_H1,"ZigZag",ZZDepth,ZZDeviation,ZZBackstep,0,l);

for(int i=total-1;i>=0;i--)
   {      if(OrderSelect(i, SELECT_BY_POS))
      {  ticket = OrderTicket();
         type = OrderType();
         openPrice = OrderOpenPrice();
         stopPrice = OrderStopLoss();
//---------------------------------------------- SL sell ------------------------------------------------      
   if(type == OP_SELL          
            && OrderSymbol()==Symbol()
            && zigzag0< zigzag2 && zigzag0<zigzag1 && zigzag1>zigzag2 && Close[1]<zigzag2
            && OrderProfit()>0


// SLman(); is inside the OnTick() function //

  1. Brt88: explain to me if this code should work.
        SLforSell= MathRound((zigzag1+0.04*ATRd)/Point)*Point;
        SLforBuy=  MathRound((zigzag1-0.04*ATRd)/Point)*Point;
    You haven't found a value for zigzag1 yet.
  2.    if(OrderSelect(i, SELECT_BY_POS)
       && OrderSymbol()==Symbol() )
          {  ticket = OrderTicket(); ..
    Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.) Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum
  3. Check your return codes What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
so stupid oversight, thank you very much WHRoeder ! :)
To add comments, please log in or register