Inquiry on Trailing Stop

 

Greetings!

I would just like to ask if the following code:

if((TrailingStop>0)&&
(Bid-OrderOpenPrice()>MyPoint*TrailingStop)&&
(OrderStopLoss()<Bid-MyPoint*TrailingStop))

is will have a similar effect to this:

if((TrailingStop>0)&&
(Bid-OrderOpenPrice()>MyPoint*TrailingStop)

and this:

if((TrailingStop>0)&&
(Bid>MyPoint*TrailingStop+OrderOpenPrice())

I am trying to come up with a way to establish trailing stops. Needless to say, I have scoured almost all thread and guide this site has to offer and I want to keep the code simple and concise. (spare me the detailed scientific theories of MT4 for now).

The above codes are for a BUY order

The way I understood, a trailing stop will be revised when the Current Price hits upward the target number of pips moved (x MyPoint[10]).

As for codeblock 1, I cannot come up with a scenario where Line 2 will be TRUE and Line 3 will be FALSE. Either both are TRUE or both are FALSE.

So the main question is, Is the Line 3 of codeblock 1 removable without consequence?

Please just take the code as it is. The other parts not pasted here have no direct functional relation to the codeblocks in question.

As always, your responses are much appreciated.

Thank you guys! 

 

Let's say a, b , c  boolean values :


a(TrailingStop>0);

b(Bid-OrderOpenPrice()>MyPoint*TrailingStop);

c(OrderStopLoss()<Bid-MyPoint*TrailingStop);  

it is same of :

c(Bid>MyPoint*TrailingStop+OrderOpenPrice());

------------------------------------

codeblock 1 is executed only if  a = b = c = true 

 if (a.b.c) {//your pg1 }; 

 ------------------------

codeblock 2 is executed if  a = b = true (regardless of c)

codeblock 3 is executed if  a = c = true (regardless of b)

if (a.b) {//your pg2 };

if (a.c) {//your pg3 };

--------------------

In boolean operations :

a.b.c is different of   a.b ( it's equal in case c = true)

a.b.c != a.c ( it's equal in case b = true)

 

paulselvan:

codeblock 1 is executed only if  a = b = c = true 

 if (a.b.c) {//your pg1 };

Invalid syntax. Us if( a && b && c) and no semi after closing brace.
Ibex Thales:
Write self-documenting code.
double cur = MathMax(OrderOpenPrice(), OrderStopLoss() ); // Move to BE minimum.
double tsl = Bid - MyPoint*TrailingStop;
if(TrailingStop > 0 && tsl >= cur +_Point)     // At least 1 pt (no Err 1)
 
whroeder1:
Invalid syntax. Us if( a && b && c) and no semi after closing brace.

you've probably noticed the syntax wasnt in mql4.

AND is exprimed by '.' (point) as in boolean expression

 
paulselvan: you've probably noticed the syntax wasnt in mql4. AND is exprimed by '.' (point) as in boolean expression

You used mathematic notification and mixed it with if code. Thus you confused all the non-mathematicians here.

 

@whroeder1

I have just realized that 

(Bid-OrderOpenPrice()>MyPoint*TrailingStop)&&
(OrderStopLoss()<Bid-MyPoint*TrailingStop))

will have the same effect as:

(Bid>MyPoint*TrailingStop+OrderOpenPrice())&&
(Bid>MyPoint*TrailingStop+OrderStopLoss())

Hence, the self documenting code you posted.

But i would just like to inquire on where the "cur" variable is used? Could I also write it as:

double cur = MathMax(OrderOpenPrice(), OrderStopLoss() );  // To pick the higher of either Open or StopLoss
double tsl = Bid - MyPoint*TrailingStop; 
if(TrailingStop > 0 && tsl >= cur+_Point)                  // At least 1 pt (no Err 1)

?

Lastly, is the Error1 you refer to same as Error 145 in this site: https://book.mql4.com/appendix/errors

Thank you once more, y'all!

Error Codes - Appendixes - MQL4 Tutorial
Error Codes - Appendixes - MQL4 Tutorial
  • book.mql4.com
GetLastError() - the function that returns codes of error. Code constants of errors are determined in stderror.mqh file. To draw the text messages use the ErrorDescription() function described in the stdlib.mqh file. Error codes returned from a trade server or client...
 
Ibex Thales:

But i would just like to inquire on where the "cur" variable is used? Could I also write it as:

double cur = MathMax(OrderOpenPrice(), OrderStopLoss() );  // To pick the higher of either Open or StopLoss
double tsl = Bid - MyPoint*TrailingStop; 
if(TrailingStop > 0 && tsl >= cur+_Point)       

Lastly, is the Error1 you refer to same as Error 145 in this site: https://book.mql4.com/appendix/errors

  1. This is what I meant to write.
  2. MyPoint*TrailingStop must be made larger. You can't move stops (or pending prices) closer to the market than the minimum (MODE_STOPLEVEL * _Point.)
              Requirements and Limitations in Making Trades - Appendixes - MQL4&Tutorial
 
whroeder1:
  1. This is what I meant to write.
  2. MyPoint*TrailingStop must be made larger. You can't move stops (or pending prices) closer to the market than the minimum (MODE_STOPLEVEL * _Point.)
              Requirements and Limitations in Making Trades - Appendixes - MQL4&Tutorial

I am really sorry but what do you mean "write"?

@ the minimum moves, I see. Thank you for that. :)

 
Ibex Thales: I am really sorry but what do you mean "write"?

Synonyms for write

address sign ghost comp scriven
compose tell indite dash off set down
create author ink draw up set forth
draft autograph inscribe drop a line take down
note chalk letter drop a note turn out
pen commit pencil jot down write down
print communicate reproduce knock off write up
record copy scribe knock out
rewrite correspond transcribe note down post
scrawl engross typewrite push a pencil
scribble formulate bang out put in writing
 
whroeder1:

Synonyms for write

address sign ghost comp scriven
compose tell indite dash off set down
create author ink draw up set forth
draft autograph inscribe drop a line take down
note chalk letter drop a note turn out
pen commit pencil jot down write down
print communicate reproduce knock off write up
record copy scribe knock out
rewrite correspond transcribe note down post
scrawl engross typewrite push a pencil
scribble formulate bang out put in writing

meh. lol! all these stuff seem to sap out the little sense I have left. Thanks, though!

 
I would like to ask if:

Bid - OrderStopLoss()  > TrailingStop x MyPoint

is the same as:

Bid - TrailingStop x MyPoint > OrderStopLoss() 


I mean not syntax-wise but logic wise. The lines of code are the only ones I changed in the EA,  yet they yielded tremendously different results. My understanding is that both work on the same logic. Could I have missed some workings of the codes? 
Reason: