Google sheets Array Formula IF Statement - google-sheets

I'm trying to run an array formula to see how long (days) it is in a current status.
Source:
={
"Days since application submitted";
ArrayFormula(
If(
Isblank(U3:U),
"",
(
IF(
G3:G="APPLICATION SENT",
DATEDIF(U3:U,AA3:AA,"D"),
(
IF(
G3:G="APPLICATION ACCEPTED - AWAITING REPAYMENT",
DATEDIF(U3:U,AF3:AF,"D"),
(
IF(
G3:G="CREDIT",
DATEDIF(U3:U,AF3:AF,"D"),
(
IF(
G3:G="COMPLETED",
DATEDIF(U3:U,AF3:AF,"D"),
)
)
)
)
)
)
)
)
)
)
}
It works fine however if I don't have anything in column 'AF' as I may skip a status it will show up with an error. But if 'AF' is blank I then want to do another check within the same array formula to run something like (IF(ISBLANK(AF3:AF),"",(IF(G3:G="COMPLETED",DATEDIF(U3:U,AJ3:AJ,"D") ... Looking at another date in 'AJ' column.
={
"Days since application submitted";
ArrayFormula(
If(
Isblank(U3:U),
"",
(
IF(
G3:G="APPLICATION SENT",
DATEDIF(U3:U,AA3:AA,"D"),
(
IF(
G3:G="APPLICATION ACCEPTED - AWAITING REPAYMENT",
DATEDIF(U3:U,AF3:AF,"D"),
(
IF(
G3:G="CREDIT",
DATEDIF(U3:U,AF3:AF,"D"),
(
IF(
G3:G="COMPLETED",
DATEDIF(U3:U,AF3:AF,"D"),
OR(
if(
isblank(
AF3:AF,
IF(
G3:G="COMPLETED",
DATEDIF(U3:U,AJ3:AJ,"D"),
)
)
)
)
)
)
)
)
)
)
)
)
)
)
}
Any support would be helpful where I am going wrong.

Instead of nesting many if() functions, try ifs(), like this:
=arrayformula(
{
"Days since application submitted";
ifs(
isblank(U3:U),
iferror(1/0),
isblank(AF3:AF) * (G3:G = "COMPLETED"),
datedif(U3:U, AJ3:AJ, "D"),
G3:G = "APPLICATION SENT",
datedif(U3:U, AA3:AA, "D"),
regexmatch(to_text(G3:G), "(?i)accepted|credit|completed"),
datedif(U3:U, AF3:AF, "D"),
true,
na()
)
}
)

try:
={"Days since application submitted"; ARRAYFORMULA(
IF(ISBLANK(U3:U),,
IF(G3:G="APPLICATION SENT", DATEDIF(U3:U, AA3:AA, "D"),
IF(ISBLANK(AF3:AF),,
IF(REGEXMATCH(""&G3:G, "APPLICATION ACCEPTED - AWAITING REPAYMENT|CREDIT|COMPLETED"),
DATEDIF(U3:U, AF3:AF, "D"))))))}

Related

QUERY simplification with LAMBDA function

I have this formula so I want to make the same QUERY for each variable and join the results. The given formula works (no error in cell) but it give me only the first query result.
I want the result to be QUERYRESULT1 / QUERYRESULT2 / QUERYRESULT3, etc. and i could repeeat the query for each variable, but I'm asking for a way to make it with only one line (to simplify). Is it possible?
=MAP(
BI3:BI;BL3:BL;BO3:BO;BR3:BR;BU3:BU;BX3:BX;CA3:CA;CD3:CD;CG3:CG;CJ3:CJ;CM3:CM;CP3:CP;
LAMBDA(f;g;h;i;j;k;l;m;n;o;p;q;
TEXTJOIN(" / "; TRUE;
IFNA(
ARRAYFORMULA(
IFERROR(QUERY('BDD Componentes'!AR:AV;"SELECT AV WHERE AR = '"&{f;g;h;i;j;k;l;m;n;o;p;q}&"'";0))
)
)
)
)
)
here I am with the same suggestion as in your previous question. Try it and let me know:
=BYROW({BI3:BI\BL3:BL\BO3:BO\BR3:BR\BU3:BU\BX3:BX\CA3:CA\CD3:CD\CG3:CG\CJ3:CJ\CM3:CM\CP3:C};
LAMBDA(r;
TEXTJOIN(" / "; TRUE;
IFNA(
ARRAYFORMULA(
IFERROR(QUERY('BDD Componentes'!AR:AV;"SELECT AV WHERE AR = '"&r&"'";0))
)
)
)
)
)

And function in google sheets not working with complex funtions

=IF(
K22;
ARRAY_CONSTRAIN(
FILTER(
Pockets2.0!A:E;
Pockets2.0!A:A;
REGEXMATCH(Pockets2.0!C:C;"MTC");
K22=Pockets2.0!A:A;
O22=IF(
AND(REGEXMATCH(Pockets2.0!C:C;"MTC-.*$");TRUE());
-1;
1
) * Pockets2.0!D:D
);
1;
5
);
)
if I quit the and and just put the first statement it works, but with 'and' and true it fails
The and() function is an aggregating function and will not give row-by-row results in an array formula the way you seem to expect. To make it work, use Boolean arithmetic, like this:
=filter(
Pockets2.0!A:E,
K22 = Pockets2.0!A:A,
regexmatch(Pockets2.0!C:C, "mtc"),
O22 = if( regexmatch(Pockets2.0!C:C, "mtc-") * (true = true), -1, 1 ) * Pockets2.0!D:D
)

LUA|MTA attempt to index global "zoneName" (a nil value)

I'm encountering a problem in a Lua script that I'm learning from (i am new to Lua) this error got me heavily confused, when I run the code it gives me this following error:
attempt to index global "zoneName" (a nil value)
this is my code:
local zoneName = zoneName:gsub ( "'", "" )
if dbExec ( handler, "INSERT INTO `safeZones` (`rowID`, `zoneName`, `zoneX`, `zoneY`, `zoneWidth`, `zoneHeight`) VALUES (NULL, '".. tostring ( zoneName ) .."', '".. tostring ( zoneX ) .."', '".. tostring ( zoneY ) .."', '".. zoneWidth .."', '".. zoneHeight .."');" ) then
createSafeZone ( { [ "zoneName" ] = zoneName, [ "zoneX" ] = zoneX, [ "zoneY" ] = zoneY, [ "zoneWidth" ] = zoneWidth, [ "zoneHeight" ] = zoneHeight } )
outputDebugString ( "Safe Zones: Safe zone created name: ".. tostring ( zoneName ) )
return true
else
return false, "Unable to create the safe zone"
end
You reference zoneName already in it's definition, you code equals to
local zoneName = nil:gsub("'", "")
hence the error (zoneName is not yet defined when Lua tries to execute zoneName:gsub()).
Either define zoneName before the gsub() call or use string.gsub()

Calling OrderOpenPrice() in OrderSelect() causes crash MT4 (on W7)

The next function closes orders in my EA. It works fine while the 3rd if(...)-code-block is quoted-out.
When it is activated in the function, MT4 stops and W7 pops up with a message saying there's a problem with the program (MT4). Defining the variable prijsOpen or not makes no difference.
Can anybody tell me what's wrong??
void sluitBUY( double waarde ){
for ( int i = 0; i < OrdersTotal(); i++ ){
if ( OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) == true ){
double prijsOpen = OrderOpenPrice();
if ( OrderType() == 0 ){
if ( waarde != 0
&& prijsOpen < waarde
) //<============================================ CAUSES CRASH
OrderClose( OrderTicket(),
OrderLots(),
OrderClosePrice(),
3,
clrCyan
);
}
}
}
}
I don't see anything wrong with the code you provided. But I have seen the behavior that you are describing. Your MT4 platform may be corrupted. Try the same code on a different instance of MT4 and see if it still has the same problem. I'm guessing that it won't.

How to repair an Error 4059 on calling the OrderModify() function | MQL4?

My EA comes up with an error code of 4059which meansthat the OrderModify() function is apparently not allowed in (back) testing.
Is there any way in which this could be allowed at all?
All I'm wanting to do is change the position to breakeven, when it gets 100 pips "to the good"
PrintFormat( "TKT[%.2d]OP:[%7.5f]SL:[%7.5f]CurrentPrice:[%7.5f]Stoplevel:[%.3d]FreezeLevel:[%.3d]",
aTicket,
anOpenPrice,
aCurrentSL,
anAskPrice,
stopLevel,
freezeLevel
);
SellMod = OrderModify( aTicket,
NormalizeDouble( anOpenPrice, Digits ),
NormalizeDouble( aNewSLPrice, Digits ),
NormalizeDouble( aNewTpPrice, Digits ),
0,
sellcolor
);
SendMail( "Notification of Order Modification for Ticket#"
+ IntegerToString( OrderTicket(), 10 ),
"Good news! Order Ticket#"
+ IntegerToString( OrderTicket(), 10 )
+ "has been changed to breakeven"
);
if ( !SellMod )
{ PrintFormat( "Order modification for ticket %10d has failed modify the order under the Error Code# %5d. Check MQL4 Documentation",
aTicket,
GetLastError()
);
result = false;
}
4059 ERR_FUNC_NOT_ALLOWED_IN_TESTINGis clear, not the source of it though
Function is not allowed in testing mode[ HIDDEN REMAINS _WHERE_ + _WHY_ IT IS REPORTED] :)
So,
modify a few details on Error-Detection
so as to get back to the riding saddle and to get the things back under your full control:
.
..
...
// ======================================== .ASSUME NOTHING ; the best
// advice
// ever :)
// // ALWAYS (pre-clear)
GetLastError(); /* _ _ _ _ _ _ _ _ _ _ _ AND ERR_SYSREG, 0 ; CLEAR SYSREG
; (
; prevents
; from reading
; a value from
; some "old"
; error-code
; on a "next"
; GetLastError
; call
; )
*/
OrderModify(...); // CALL _OrderModify
gotLastERROR = // MOV VAR, ERR_SYSREG ; CATCH ERR
GetLastError(); // _ _ _ _ _ _ _ _ _ _ _ AND ERR_SYSREG, 0 ; CLEAR SYSREG
// ---------------------------------------- ( a main-effect )
// ( VAR has this _FUN call error-code )
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- ( a side-effect )
// ( ERR_SYSREG is clear AGAIN )
...
..
.
With a similarly systematic approach to Error-Detection you will soon realise the root cause of the observed problem and any Error-Handling will only start to have sense.
Most probably, the error originates a few SLOC-s lower, under your OrderModify() call, where SendMail() call appears, in spite of the fact, that HELP explicitly says:
NoteSending can be prohibited in settings, email address can be omitted as well. For the error information call GetLastError().
SendMail() function does not work in the Strategy Tester.
OrderModify() does NOT generate error 4059.
That error comes from SendMail(). Documentation states that:
https://docs.mql4.com/common/sendmail

Resources