This code gives different results on 1 minute and 1 hour chart

 

Hello, can anyone help me with this code.  It should (if I have coded it correctly) give the same result on both a 1 minute and a 1 hour chart but it is giving a different result and printing the lines in different places on each?


// This finds the start of a new bar using volume
                           bool OpenBar1Min = true;
                           if(iVolume(NULL,PERIOD_M1,0)>1) OpenBar1Min=false;
                    
                           if (OpenBar1Min) {
                           PlaySound("news.wav");
                                // 1 Minute extreme signals High Candle Wicks
                               
                                int    i1MinHigh = 5;
                               
                                while(R1H1Min == 0 && i1MinHigh+1 < Bars)
                                      {
                                       if (iHigh(NULL,PERIOD_M1,i1MinHigh) > iHigh(NULL,PERIOD_M1,i1MinHigh+1) && iHigh(NULL,PERIOD_M1,i1MinHigh) > iHigh(NULL,PERIOD_M1,i1MinHigh-1)
                                           && High[iHighest(NULL,PERIOD_M1,2,i1MinHigh,0)] > iHigh(NULL,PERIOD_M1,0) && High[iHighest(NULL,PERIOD_M1,2,i1MinHigh-1,0)] < iHigh(NULL,PERIOD_M1,i1MinHigh))
                                       {
                                       R1H1Min = iHigh(NULL,PERIOD_M1,i1MinHigh); //New high point found
                                       double J1Min = Open[iHighest(NULL,PERIOD_M1,MODE_HIGH,2,i1MinHigh-1)];  
                                       double K1Min = Close[iHighest(NULL,PERIOD_M1,MODE_HIGH,2,i1MinHigh-1)]; 
                                       R1L1Min2 = MathMax(J1Min,K1Min);                                   //High point of zone = high of J, K and L
                                       }
                                       i1MinHigh++;                                                          //Keep going back until high found i bars back
                                     }
                                       Min1SellStopLevel = R1H1Min;
                                       if (Bid >= R1L1Min2) PlaySound("Cable1MinSell.wav");
                                       ObjectSet("TempHigh", OBJ_HLINE, R1H1Min);
                                       ObjectSet("TempLow", OBJ_HLINE, R1L1Min2);  // This is the Bottom of the Sell Zone
                                      
                                      
                                // i Minute extreme signals Low Candle Wicks
                                int    i1MinLow = 5;
                               
                                while(T1H1Min == 0 && i1MinLow+1 < Bars)
                                      {
                                       if (iLow(NULL,PERIOD_M1,i1MinLow) < iLow(NULL,PERIOD_M1,i1MinLow+1) && iLow(NULL,PERIOD_M1,i1MinLow) < iLow(NULL,PERIOD_M1,i1MinLow-1)
                                           && Low[iLowest(NULL,PERIOD_M1,2,i1MinLow,0)] < iLow(NULL,PERIOD_M1,0) && Low[iLowest(NULL,PERIOD_M1,2,i1MinLow-1,0)] > iLow(NULL,PERIOD_M1,i1MinLow))
                                       {
                                       T1H1Min = iLow(NULL,PERIOD_M1,i1MinLow); //New Low point found
                                       double L1Min = Open[iLowest(NULL,PERIOD_M1,MODE_LOW,2,i1MinLow-1)]; 
                                       double M1Min = Close[iLowest(NULL,PERIOD_M1,MODE_LOW,2,i1MinLow-1)]; 
                                       T1L1Min2 = MathMin(L1Min,M1Min);                                   //High point of zone = high of J, K and L
                                       }
                                       i1MinLow++;                                                          //Keep going back until high found i bars back
                                     }
                                       Min1BuyStopLevel = T1H1Min;
                                       if (Bid <= T1L1Min2) PlaySound("Cable1MinBuy.wav");
                                       ObjectSet("TempLowLow", OBJ_HLINE, T1H1Min);
                                       ObjectSet("TempLowHigh", OBJ_HLINE, T1L1Min2);       //This is the Top of the Buy Zone
                                      
                           }

 
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. if(iVolume(NULL,PERIOD_M1,0)>1)
    Bars is unreliable (a refresh/reconnect can change number of bars on chart) volume is unreliable (miss ticks) Always use time. New candle - MQL4 forum
  3. N1EYR:   It should (if I have coded it correctly) give the same result on both a 1 minute and a 1 hour chart but it is giving a different result a
    && Low[iLowest(NULL,PERIOD_M1,2,i1MinLow,0)] < iLow(NULL,PERIOD_M1,0) && Low[iLowest(NULL,PERIOD_M1,2,i1MinLow-1,0)] > iLow(NULL,PERIOD_M1,i1MinLow))
    Of course it does. The Low[x] on the H1 will different than the Low[x] on the M1 chart for the same x.  You are mixing apples and oranges
 
Thanks WHRoeder, I see the error.  I thought it was with the Shift working on the different time frames and was messing about with iBarShift and getting nowhere
Reason: