[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 170

 
splxgf:
Your version can be reduced to these two lines added to the author's version, and with some alterations to the conditions should in principle speed things up quite nicely.
Are you sure?
 
MaxZ:
Are you sure?

Essentially your suggestion is to exclude from checks and calculations candles which do not fall within the UPPprice/LOWprice range... this is excluded by two lines. If you don't drop out of the loop, it means the price is in the range we need and we do the standard checks. Your code may go faster only to the detriment of the results, because the logic of working with INS is very convoluted to use the value of this variable from the previous iteration is nonsense.

 
splxgf:

Essentially your suggestion is to exclude from checks and calculations candles which do not fall within the UPPprice/LOWprice range... this is excluded by two lines. If you don't drop out of the loop, it means the price is in the range we need and we do the standard checks. Your code may go faster only to the detriment of the results, because the logic of working with INS is very convoluted to use the value of this variable from the previous iteration is nonsense.

So you're sure! :))))


You cited the code earlier:

splxgf:
        if (LOWprice > iHigh(NULL,60,i)) continue;
        if (UPPprice < iLow (NULL,60,i)) continue;

If the price is below Low, why should we check if the price is above High? In your version this condition is not excluded. But in my suggestion:

         if (UPP)
            ... // не выполнится
         if (LOW)
            if (LOWprice < iLow (NULL,60,i))
               continue;
            else
            ..

it is excluded.

I do not deny that my code may not be the most optimal.

But how many times faster do you think

         if (UPP)

will work than.

         if (LOWprice > iHigh(NULL,60,i))

?

In fact:

UPP = LOWprice > iHigh(NULL, 60, i);

Only I know this for a fact (except when bid inside the current historical bar) and you calculate it...

 
abolk:


Yeah.

You have to get so twisted as to turn three clear lines of code into code that is hard to understand.

If you had the idea to split the iLow, iHigh check, you could have split it right away:

And don't make any wisecracks

And have you ever thought that twisted cumbersome code can sometimes run faster than a simple three lines? :)))
 
 INS = True;
   
   for (int i=1; i<=6000; i++)
   {
      if (INS)
      {
         if (LOWprice > iHigh(NULL,60,i))
         {
            INS = False;
            UPP = True;
            LOW = False;
            continue;

Consider this section of code

INS=True;

The loop went

if (INS) flight is ok

if (LOWprice...) for example, the condition is true, but then it goes wrong because we get INS=False and we go to the next iteration

then if (false) and we're done, because it's another bar, so what the...

As for my code, I'm not checking the price but whether the bar is within +300/300 pips of the current price and if it is, it should be considered. All other optimizations are not so critical because the first two checks for example eliminate 90% of unnecessary bars.

 
splxgf:

then if (false) and we're screwed, because it's a different bar, you have to ask what the...

Not sailed, but sailed on else { ... }.
 

and then really swam...

Why do you think Boolean variables will speed up if each condition is followed by one more if (LOWprice > iHigh(NULL,60,i)), i.e. the same eggs but from the side plus one condition and a lot of assignments...

 

Whoa!

This is where the arguments get heated up.

I'll put it like this for now:

 extern int Distance = 3000;
 int CountH,NewCountH,CountL,NewCountL,CountB,NewCountB;
 
 double ResistH,ResistL,ResistB;
 
//======================================================================
int start(){


   double bid = Bid;
   double UPPprice = bid+Distance*Point;
   double LOWprice = bid-Distance*Point;
      NewCountH=0;
      NewCountL=0;
      NewCountB=0;
      ResistH=0;
      ResistL=0;
      ResistB=0;
  
   while(LOWprice<UPPprice)
    {
      CountH=0;
      CountL=0;
      for(int i=1; i<=6000; i++){  
          if(iHigh(NULL,60,i)>LOWprice) 
          if(LOWprice>iLow(NULL,60,i)) 
          if(LOWprice> bid) CountH++; else CountL++;
       }  
      if(CountH>NewCountH){NewCountH=CountH;ResistH=LOWprice;} 
      if(CountL>NewCountL){NewCountL=CountL;ResistL=LOWprice;}   
      LOWprice=LOWprice+25*Point;
    }
      CountB=0;
      for(i=1; i<=6000; i++){  
          if(iHigh(NULL,60,i)>=bid) if(bid>=iLow(NULL,60,i)) CountB++;
       }
      if(CountB>NewCountB){NewCountB=CountB;ResistB=bid;}  
 
     
   
    Comment("\n", 
      "\n",     
//      "\n", "     Spread                                ", MarketInfo(Symbol(), MODE_SPREAD),  
      "\n", "     Distance                             ", Distance, 
      "\n", "     CountH                               ", NewCountH, 
      "\n", "     CountB                               ", NewCountB, 
      "\n", "     CountL                                ", NewCountL, 
      "\n", "-------------------------------------------------- ",     
      "\n");
      

    if(ObjectFind("RH") == -1) {
      ObjectCreate("RH", OBJ_HLINE, 0, 0, ResistH);
      ObjectSet("RH", OBJPROP_COLOR, Magenta);
      ObjectSet("RH", OBJPROP_STYLE, STYLE_DOT);
     }else ObjectMove("RH", 0, iTime(NULL,0,0), ResistH);

    string text=DoubleToStr(NewCountH,0);
    ObjectDelete("RHtxt"); 
     if(ObjectFind("RHtxt") == -1) {
       ObjectCreate("RHtxt", OBJ_TEXT, 0, 0, 0);
       ObjectSetText("RHtxt", text , 8, "Arial", Aqua);
       ObjectMove("RHtxt", 0, iTime(NULL,0,0), ResistH);
      }else ObjectMove("RHtxt", 0, iTime(NULL,0,0), ResistH);
      
    string text3=DoubleToStr(NewCountB,0);
    ObjectDelete("RBtxt"); 
     if(ObjectFind("RBtxt") == -1) {
       ObjectCreate("RBtxt", OBJ_TEXT, 0, 0, 0);
       ObjectSetText("RBtxt", text3 , 8, "Arial", Aqua);
       ObjectMove("RBtxt", 0, iTime(NULL,60,0), ResistB);
      }else ObjectMove("RBtxt", 0, iTime(NULL,60,0), ResistB);

    if(ObjectFind("RL") == -1) {
      ObjectCreate("RL", OBJ_HLINE, 0, 0, ResistL);
      ObjectSet("RL", OBJPROP_COLOR, Magenta);
      ObjectSet("RL", OBJPROP_STYLE, STYLE_DOT);
     }else ObjectMove("RL", 0, iTime(NULL,0,0), ResistL);
     
    string text2=DoubleToStr(NewCountL,0);
    ObjectDelete("RLtxt");
    if(ObjectFind("RLtxt") == -1) {
      ObjectCreate("RLtxt", OBJ_TEXT, 0, 0, 0);
      ObjectSetText("RLtxt", text2 , 8, "Arial", Aqua);
      ObjectMove("RLtxt", 0, iTime(NULL,0,0), ResistL);
     }else ObjectMove("RLtxt", 0, iTime(NULL,0,0), ResistL);

 return (0);}            //====== THE END ======================

It's very interesting to watch the price movement. It always goes in the direction of least resistance.

You can even predict its future movement. Observe.

Price is like water flowing in a stream.

Thank you all!

 

Please tell me how to find the bar number with the highest value of the high.


Search_High=MathMax( High[i],High[1])

 
001:

Can you tell me how to find the number of the bar with the highest chai value?


Search_High=MathMax( High[i],High[1])

You can go to https://docs.mql4.com/ru/array/ArrayMaximum

through the array High.