About trailing stop - page 2

 
Learner21:

Nice. Looks good to me everything but 

when I run this code

 it says Error = 4753 which means position not found.

When I use

 it still gives the same error. 

I tried the Print statement that you added in, and for some reason it returns the error when it is placed where you have it in the code when the code itself otherwise works, but it is in the true statement, so when it's executed, it might be trying to find an error because it has been called to do so, but i don't know for sure. However, put the Print statement by itself like this

if(PositionSelect(Symbol())==false)
  Print(" Position select = ", GetLastError());

 That way it only looks for an error if the position couldn't be selected. This worked for me when i tried it. Something else you should have for the code is an if statement like this

if(PositionsTotal()>0)
 {
  //trailingstop code goes here
 }

 The statement makes sure that there are positions to be selected before the code is run. I hope all of this helps.

 

if(PositionsTotal()>0){

for(int b=0;b<=PositionsTotal();b++){
  if(PositionSelect(Symbol())==true && PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
   {
  Print(" Position select = ", GetLastError());
   }
}

}


Hey how comes my code is not coloured ???
 
Press SRC button and insert code. It makes it colored.
MQL5.community - User Memo
  • 2010.02.25
  • MetaQuotes Software Corp.
  • www.mql5.com
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.
 

Looks like working.

Thanks you, guys, for your kind help. 

 

Hello,


How to use this code for stocks?  I saw all trail stop ea includes NomalizeDouble. For stocks, price close is integer and for example price step is 25. Close like 1000 1025 1050 1075.


thanks.

 
ekren Clausewitz: I saw all trail stop ea includes NomalizeDouble.
Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
Reason: