Download MetaTrader 5
To add comments, please log in or register
Post web links to other trader's signals and make profit
Yourock Acrew
74
Yourock Acrew 2013.04.23 14:41 

Hi Guys,

Sorry if it should be posted in another forum. I started learning programming on mql5 recently and already made 3 simple EAs... but stuck with a little problem now. See my code:

 if(profit>0 && NormalizeDouble(tick.bid - sl,_Digits) >= stop_loss *_Point)

         {

            Print("Bid - sl = ", NormalizeDouble(tick.bid-sl,_Digits)," >= stop loss = ", stop_loss*_Point);

            request.action=TRADE_ACTION_SLTP;

            request.symbol=_Symbol;

            request.sl=sl + trailing_stop * _Point;

            request.tp=tp + trailing_step * _Point;

            

            OrderSend(request,result);

            Print(NormalizeDouble(tick.bid - sl,_Digits));

         }

 

Basically, my goal is to move SL towards profit if the difference between SL and current price increases. Problem is that it works only once. SL gets adjusted and then seems like stay unchanged no matter what happens. Did I miss anything?

 

Thanks for your responses and good luck. 

Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2013.04.23 15:09  
Yourock:

Hi Guys,

Sorry if it should be posted in another forum. I started learning programming on mql5 recently and already made 3 simple EAs... but stuck with a little problem now. See my code:

 <CODE DELETED>

Basically, my goal is to move SL towards profit if the difference between SL and current price increases. Problem is that it works only once. SL gets adjusted and then seems like stay unchanged no matter what happens. Did I miss anything?

When you post code please use the   SRC  :  How to use the   SRC   button. 
Yourock Acrew
74
Yourock Acrew 2013.04.23 22:50  

Oh Sorry, surely will do next time! 

Alain Verleyen
Moderator
28626
Alain Verleyen 2013.04.23 22:54  
Yourock:

Oh Sorry, surely will do next time! 

Why next time, please edit your post.
Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2013.04.23 22:58  
angevoyageur:
Why next time, please edit your post.
The OP can't after there has been a reply.
Alain Verleyen
Moderator
28626
Alain Verleyen 2013.04.23 23:00  
RaptorUK:
The OP can't after there has been a reply.
Ah ok, sorry. I edited it for him.
Alain Verleyen
Moderator
28626
Alain Verleyen 2013.04.23 23:06  
Yourock:

Hi Guys,

Sorry if it should be posted in another forum. I started learning programming on mql5 recently and already made 3 simple EAs... but stuck with a little problem now. See my code:


 

Basically, my goal is to move SL towards profit if the difference between SL and current price increases. Problem is that it works only once. SL gets adjusted and then seems like stay unchanged no matter what happens. Did I miss anything?

 

Thanks for your responses and good luck. 

  • What are the values of profit, sl, stoploss ?
  • Try to put your print statement outside the if statement.
Yourock Acrew
74
Yourock Acrew 2013.04.24 04:21  

Thanks everyone for your help, I am happy to tell that I looked at my code this morning with a fresh state of mind and found the problem: tick.bid! I was reading values for tick only at the time when I send my initial order, then is was staying without change. Now I read tick data on every tick.


Very simple error though... don't code at 3am :D

Good luck

/
To add comments, please log in or register