Just a little help on programming side

 

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. 

 
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. 
 

Oh Sorry, surely will do next time! 

 
Yourock:

Oh Sorry, surely will do next time! 

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

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