Programming Q

Questions and discussion of Trading Blox and other platforms for non Trading Blox customers. Trading Blox customers should use the Trading Blox Support forum.
Post Reply
LeviF
Roundtable Knight
Roundtable Knight
Posts: 1428
Joined: Mon Dec 22, 2003 12:24 pm
Location: Des Moines, IA
Contact:

Programming Q

Post by LeviF » Wed Aug 17, 2011 1:27 am

I posted this on the MT4 board with no response yet.

I am printing the following statement:

Print(Order_Symbol, ",", Order_Quantity, ",",(OrderType() == 1),",", (Order_Quantity == 0));

It returns (symbol, 0, 1, 0)

Any idea how Order_Quantity = 0 and Order_Quantity == 0 could return FALSE in the same statement? Order_Quantity is declared as a double/floating variable.

sluggo
Roundtable Knight
Roundtable Knight
Posts: 2986
Joined: Fri Jun 11, 2004 2:50 pm

Post by sluggo » Wed Aug 17, 2011 7:39 am

Not an MT4 programmer, this could be balderdash.

1. Blox's programming language has ways to force a PRINT statement to print a floating point variable with lots of digits of precision. Maybe MT4's programming language has a feature like that, too. Perhaps when you print with lots of digits of precision, you may discover that Order_Quantity isn't zero, but rather it's 1.234e-19 .

2. Tradestation EasyLanguage was, once upon a time, notoriously unreliable if you passed an expression as an argument to a function. Maybe MT4 has got this disease too? Maybe if you performed a couple of assignment statements
  • temp1 = 0;
    if(OrderType() == 1) then temp1 = 1;
    temp2 = 0 ;
    if(Order_Quantity != 0.00) then temp2 = 1;
    Print( symbol , Order_Quantity, temp1, temp2) ;
and then printed the results of the assignment statements, you could feel cozy that you have bypassed this category of possible bugs.

3. Maybe MT4 has funny rules about comparisons that involve floats. Maybe a comparison (float == integer) ALWAYS fails, and maybe your comparison (Order_Quantity == 0) is considered to be a comparison between a float and an integer. If so you could change it so that even the dumbest compiler would recognize both as floats, perhaps
  • Order_Quantity == 0.000
    Order_Quantity < 0.000001234

ratio
Roundtable Knight
Roundtable Knight
Posts: 338
Joined: Sun Jan 15, 2006 11:07 pm
Location: Montreal, Canada

Post by ratio » Wed Aug 17, 2011 7:43 am

In programming language like C++ double == sign mean a comparaison not an assignment

This is why Quantity == 0 return false

Quantity = 0 is an assignment, ie I want Quantity to = to 0


This is something that The VB version in TB handle differently, in both case in TB it mean assignment. I had ask that question at the time in a Blox conference in Boston

Denis

LeviF
Roundtable Knight
Roundtable Knight
Posts: 1428
Joined: Mon Dec 22, 2003 12:24 pm
Location: Des Moines, IA
Contact:

Post by LeviF » Wed Aug 17, 2011 9:32 am

It was a precision problem. I cant for the life of me figure out where the issue is being introduced, but lopping off some unnecessary decimal places is taking care of it.

Post Reply