Question on Book sample expert + question on base used when calculating S/L and T/P

 

Two items I would appreciate your valued comments on.

.

.

ONE

Reading some site docs and require your observation on this source code found at https://book.mql4.com/samples/expert

In code snippets (1) and (2), > is used

do you agree?


(1)

// Order value
   RefreshRates();                              // Refresh rates
   Min_Lot=MarketInfo(Symb,MODE_MINLOT);        // Minimal number of lots 
   Free   =AccountFreeMargin();                 // Free margin
   One_Lot=MarketInfo(Symb,MODE_MARGINREQUIRED);// Price of 1 lot
   Step   =MarketInfo(Symb,MODE_LOTSTEP);       // Step is changed
 
   if (Lots < 0)                                // If lots are set,
      Lts =Lots;                                // work with them
   else                                         // % of free margin
      Lts=MathFloor(Free*Prots/One_Lot/Step)*Step;// For opening
 
   if(Lts > Min_Lot) Lts=Min_Lot;               // Not less than minimal
   if (Lts*One_Lot > Free)                      // Lot larger than free margin
     {
      Alert(" Not enough money for ", Lts," lots");
      return;                                   // Exit start()
     }

(2)

int New_Stop(int Parametr)                      // Checking stop levels
  {
   int Min_Dist=MarketInfo(Symb,MODE_STOPLEVEL);// Minimal distance
   if (Parametr > Min_Dist)                     // If less than allowed
     {
      Parametr=Min_Dist;                        // Sett allowed
      Alert("Increased distance of stop level.");
     }
   return(Parametr);                            // Returning value
  }

.

TWO

For a long time, I have been ignoring and freaking out over this and finally think should attempt to 'move on' and get this sorted out, so your inputs really wanted :-)

.

T/P and S/L setting has been fully aired many times on this forum yet (to me) the conversations have always been 'self' oriented in that this is how "I" view the issue and how "I" use it in my own software.

I mean that it seems that would be best bet to actually get return of say 10pips instead of 10pips less spread.

I have looked in many source codes and the manner of what base is used varies between Entry and Close price...

.

What about the general punter/user ?

IE, MT docs base T/P and S/L on the closing price

This gives a T/P of: T/P - spread; ie, wanted T/P is gross profit and the realised net profit is T/P minus costs

.

If base T/P and S/L on the entry price

This gives a T/P of: T/P; ie, closing price must not only move the T/P distance but the spread distance too. ie, wanted T/P is net profit

.

Assuming I've described the two alternatives in T/P,S/L calculations correctly, my question boils down to:

What does the general punter/user expect to earn when they specify the T/P, S/L values?

.

the same ideas I believe hold for the S/L setting. Either it is based on EntryPrice OR ClosePrice, with the same exclusive/inclusive of spread end results.

.

Guess I'm asking, should stops and the eventual P/L values include OR exclude spread?

 

Regarding point one, part 1 & 2, I fully agree this should be '<' in both cases

- Jim

 
VirtualReal:

Regarding point one, part 1 & 2, I fully agree this should be '<' in both cases

- Jim

Jim, thanks. Is obvious really but, as they say, is good to talk and have confirmation.

cheers

.

btw Jim - ref: https://www.mql5.com/en/forum/126475

For the seed, have you tried GetTickCount()

Under: MQL4 Reference > Common functions

 
fbj:

Jim, thanks. Is obvious really but, as they say, is good to talk and have confirmation.

cheers



Any time fbj,

I also noticed that strange lots size condition when I observed that code, it confused me as a novice MQL4/C coder.

Glad you had the balls to post it ;)

Happy coding & trading,

Jim

 
fbj:

Jim, thanks. Is obvious really but, as they say, is good to talk and have confirmation.

cheers

.

btw Jim - ref: https://www.mql5.com/en/forum/126475

For the seed, have you tried GetTickCount()

Under: MQL4 Reference > Common functions


Great, that seems to work!
I didn't knew that GetTickCount() statement yet.

Thanks a lot :)


Sidenote: I don't understand why this is so hard in MQ4 (and perhaps C also) since I was used to use the Rand() statement in VBA.

 
VirtualReal:

Great, that seems to work!
I didn't knew that GetTickCount() statement yet.

Thanks a lot :)


Sidenote: I don't understand why this is so hard in MQ4 (and perhaps C also) since I was used to use the Rand() statement in VBA.



since you are a C'er, maybe also familiar with Windows API's ?

anyway, I'm not win programmer but msdn site docs on the API are great source of inspiration!

Reason I mention is vast repository of goodies mt can leverage via #import...

I found refs to interesting? threads:

https://www.mql4.com/search/WinAPI

"Millisecond Time of a Tick" https://www.mql5.com/en/forum/110974

"how to obtain current time in miliseconds precision?" https://www.mql5.com/en/forum/112166

 
fbj:

since you are a C'er, maybe also familiar with Windows API's ?

anyway, I'm not win programmer but msdn site docs on the API are great source of inspiration!

Reason I mention is vast repository of goodies mt can leverage via #import...

I found refs to interesting? threads:

https://www.mql4.com/search/WinAPI

"Millisecond Time of a Tick" https://www.mql5.com/en/forum/110974

"how to obtain current time in miliseconds precision?" https://www.mql5.com/en/forum/112166



After creating some basic dll's and the famous "hello world" in the past I won't call myself a experienced C'er - LOL

For years I was satisfied with coding/working in VBA/Excel but for automatic trading I find it too slow and impractical to use, so thatswhy I recently made a switch to MT.

Because all of this I haven't worked that much with the Windows API so far, but I agree that it could be a great extention.

Thanks for the interesting links.

- Jim

Reason: