Errors, bugs, questions - page 823

 
MetaDriver:

95% of sporadic errors are related to initialization errors, or lack of it. So, a code fragment will not help, and the whole code will not do, because it is paranoid ;-)

The reason should be sought very far from the place of manifestation, and it is boring for aphthar - it's easier to demand firing squad for developers. It will help for sure.

// It really does help, doesn't it, falkov ? : )

Great! It seems it should help! :)

I bluntly do initialization EVERYWHERE and ALWAYS! Even if I assign a value to a variable after a couple of lines. I've just made an iron rule - when you declare a variable, initialize it with null or an empty string :)

About paranoia absolutely right!

Metadriver, you are a Shaman!

Документация по MQL5: Основы языка / Переменные
Документация по MQL5: Основы языка / Переменные
  • www.mql5.com
Основы языка / Переменные - Документация по MQL5
 
falkov:

Great! Seems like it should help! :)

:)

Initialising is stupid EVERYWHERE!

I don't believe it! I must have missed it this time. :)

// Really check it again, look through the whole code from this angle.

// It is the belief in your "ALWAYS AND ALWAYS" that may filter the perception of your own yawn, for "I ALWAYS...!!" :))

 
MetaDriver:
:)

I don't believe it! I missed it this time for sure. :)

// Really check again, look through the whole code from this angle.

// It is the belief in your "EVERYWHERE and EVERYWHERE" that can filter the perception of your own yawn, for "I ALWAYS...!!" :))

I'm telling you - Shaman! Over the weekend I checked all the EA files (several thousand lines). And it's true, I found two or three uninitialized variables in old libraries.

My rule is to declare ALL variables at the beginning of the function body (this has always been the case) and initialize them immediately (last year, probably)

I don't consider myself a dummy - I've written more than a hundred different indices/scripts/advisers :)

And here I am struggling like a fish on ice - I can not localize! I could shoot myself!

Документация по MQL5: Основы языка / Функции
Документация по MQL5: Основы языка / Функции
  • www.mql5.com
Основы языка / Функции - Документация по MQL5
 

Here's the code, by the way:

//Найти первое adblArray_Short х adblArray_Long  ПОСЛЕ (позже) intShift_PastSearch (поиск от intShift_PastSearch до нулевого бара)
void FindCrossArrays_PastThisShift(structS & structSled) {
    datetime adtmDTM[];
    int intShift=0;
   
    if(structSled.intShift_PastSearch>_cintBarsAmountForCalc) {return;}
    else if(structSled.intShift_PastSearch<=0) {return;}
   
    ArrayResize(adtmDTM,structSled.intBarsAmountForCalc);
    ArrayInitialize(adtmDTM,0);
    ArraySetAsSeries(adtmDTM,true);
   
    CopyTime(structSled.strSymbol,structSled.enumTF,0,structSled.intShift_PastSearch+1,adtmDTM);

    intShift=structSled.intShift_PastSearch;
   

                                    ▼ - вот здесь ошибка - array out of range in '_indMyAO_from_SetPeriod.mq5' (390,37)
    while(structSled.adblArray_Short[intShift]==structSled.adblArray_Long[intShift] && intShift>1) {intShift--;}


    if(structSled.adblArray_Short[intShift]>structSled.adblArray_Long[intShift]) {
        while(structSled.adblArray_Short[intShift]>structSled.adblArray_Long[intShift] && intShift>0) {intShift--;}
       
        if(intShift>0) {
            structSled.intRet_FindingDirection=-1;
            structSled.intRet_FindingShift=intShift;
        }
        else {
            structSled.intRet_FindingDirection=0;
            structSled.intRet_FindingShift=intShift;
        }
    }   
    else if(structSled.adblArray_Short[intShift]<structSled.adblArray_Long[intShift]) {
        while(structSled.adblArray_Short[intShift]<structSled.adblArray_Long[intShift] && intShift>0) {intShift--;}
       
        if(intShift>0) {
            structSled.intRet_FindingDirection=1;
            structSled.intRet_FindingShift=intShift;
        }
        else {
            structSled.intRet_FindingDirection=0;
            structSled.intRet_FindingShift=intShift;
        }
    }   
    structSled.dtmRet_FindingDTM=adtmDTM[structSled.intRet_FindingShift];
    return;
}
//-------------------------------------------------------------------------------------------------

 
falkov: Here is the code, by the way:

hmm, why don't you check for array overruns intShift=structSled.intShift_PastSearch;

if intShift is out of the array boundaries then while(structSled.adblArray_Short[intShift]==structSled.adblArray_Long[intShift] && intShift>1) {intShift--;}

will immediately cause an error because the code will be executed from left to right and reference to structSled.adblArray_Short[intShift] will occur before && intShift>1

set check after intShift=structSled.intShift_PastSearch; and then output if exit outside the array then Print(Hurray! It worked!)

like this

 
Good evening, could there be a function like this
void  PositionModify( int PositionTicket= PositionGetInteger(POSITION_IDENTIFIER), double price, double stoploss, double takeprofit, datetime expiration, color arrow_color=CLR_NONE)
      {  MqlTradeRequest request;
         MqlTradeResult result;
        request.action= TRADE_ACTION_SLTP; 
        request.order= PositionTicket; 
        request.price= price;
        request.symbol= Symbol();
        request.sl= stoploss;
        request.tp= takeprofit;
        return (OrderSend( request,   result    ));   
      }
Do the structures need to be zeroed when declaring in this case?
 
THANK YOU!!!
 

You know, I tried to compile in this form, it scares me.

'PositionGetInteger' - constant expected.mq5 65 44 I see the word constant. But what does it need? It's on the first line of the function.

And this is how it is for all the other variable declarations, but I've declared the function according to the help, haven't I?

'price' - missing default value for parameter order.mq5 65 92

 
Thanks, I'm compiling now.
 
Reason: