Download MetaTrader 5

Just a little help on programming side

To add comments, please log in or register
Yourock Acrew
74
Yourock Acrew  

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
18021
Simon Gniadkowski  
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  

Oh Sorry, surely will do next time! 

Alain Verleyen
Moderator
32842
Alain Verleyen  
Yourock:

Oh Sorry, surely will do next time! 

Why next time, please edit your post.
Simon Gniadkowski
Moderator
18021
Simon Gniadkowski  
angevoyageur:
Why next time, please edit your post.
The OP can't after there has been a reply.
Alain Verleyen
Moderator
32842
Alain Verleyen  
RaptorUK:
The OP can't after there has been a reply.
Ah ok, sorry. I edited it for him.
Alain Verleyen
Moderator
32842
Alain Verleyen  
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  

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