Please, Need HELP. Need TrailingStop and Break even for this EA

 

Hello,

i need help with my EA. i need a simple trailing stop and a simple break even but i dont know how to do this.

Thats my EA Code dont laugh its my first EA ;-)

please do not change so much. if possible just only insert the trailing stop, that i can still simply put there my strategies.

ive made "dont touch" if where possible nothing should be changed

Thanks in advance

i would also pay 10$ for the programming via PayPal

sorry for my bad english

Thanks again

//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, Sebastian Meissner"


extern string  Expert_Name    = "Trading Basti";
extern double iLots=0.1;
extern double iMaximumRisk= 0.02;
extern int iStopLoss=650;
extern int iTakeProfit=50;
extern int iMaxTrades=1;
extern int iMagicNumber=336699;

double stochg,stochr;

int iTotalTrades;
int iOrderOpenStatus;
int iErrorNumber;

string strErrorMessage;

double LotsOptimized()
  {
  double lot=iLots;
//---- select lot size
   lot=NormalizeDouble(AccountFreeMargin()*iMaximumRisk/1000.0,1);
//---- return lot size
   if(lot<0.1) lot=0.1;
   if(lot>50.0) lot=50.0;
   return(lot);
  }

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
   

   
//----
   return(0);
  }
  
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }

//+------------------------------------------------------------------+
//| The functions from this point to the start function are where    |
//| changes are made to test other systems or strategies.            |
//|+-----------------------------------------------------------------+

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {

  stochg = iCustom (NULL,0,"Stochastic",8,3,3,MODE_SMA,0,MODE_MAIN,0);                 //////// dont touch
  stochr = iCustom (NULL,0,"Stochastic",8,3,3,MODE_SMA,0,MODE_SIGNAL,0);               //////// dont touch
  double willd       = 81;                                                             //////// dont touch
  double willu       = 19;                                                             //////// dont touch
  double will1       = 80;                                                             //////// dont touch
  double will2       = 20;                                                             //////// dont touch

   
// Buy-Order ausführen

iTotalTrades=OrdersTotal();

if (( stochg > will2) && (stochg > stochr) && (stochr < will2) && (stochr > willu) && (iTotalTrades < iMaxTrades)) //// dont touch this

{ 
double dBuyStopLoss=Ask-(iStopLoss*Point);
double dBuyTakeProfit=Ask+(iTakeProfit*Point);

iOrderOpenStatus=OrderSend (Symbol(), OP_BUY,LotsOptimized(), Ask, dBuyStopLoss, dBuyTakeProfit, "Trading Basti",iMagicNumber,0,Green);
   if (iOrderOpenStatus<0)
      {
      iErrorNumber=GetLastError();
      Print ("Order fehlgeschlagen!: ", iErrorNumber);
      return;
      }
}
      
// Sell-Order ausführen

iTotalTrades=OrdersTotal();

if (( stochg < will1) && (stochg < stochr) && (stochr > will1) && (stochr < willd) && (iTotalTrades < iMaxTrades)) ///// dont touch

   {
   double dSellStopLoss=Bid+(iStopLoss*Point);
   double dSellTakeProfit=Bid-(iTakeProfit*Point);
 
   
iOrderOpenStatus=OrderSend (Symbol(), OP_SELL,LotsOptimized(), Bid, dSellStopLoss, dSellTakeProfit, "Trading Basti",iMagicNumber,0,Red);
   if (iOrderOpenStatus<0)
      {
      iErrorNumber=GetLastError();
      Print ("Order fehlgeschlagen!: ", iErrorNumber);
      return;
      }
}
   return(0);
  }
//---- 
Files:
bastiea.mq4  4 kb
 
sunnyboy20:

Hello,

i need help with my EA. i need a simple trailing stop and a simple break even but i dont know how to do this.

Thats my EA Code dont laugh its my first EA ;-)

please do not change so much. if possible just only insert the trailing stop, that i can still simply put there my strategies.

ive made "dont touch" if where possible nothing should be changed

Thanks in advance

i would also pay 10$ for the programming via PayPal

sorry for my bad english

Thanks again

I think you need to work to the rest of your code, not just trailing stops . . . for example:

lot=NormalizeDouble(AccountFreeMargin()*iMaximumRisk/1000.0,1);

I suspect this may work on xxxUSD pairs when your account currency is USD . . it also uses iMaximumRisk stated as a %age, i.e. 3 meaning 3%, so iMaximumRisk= 0.02; will give you a risk of 0.02% . . . and after all that, it assumes your SL is 1 pip away.

This will give you the wrong answer if you place any trades manually or from other EAs . . . or the same EA on more than one currency pair . . . filter by Symbol and Magic number

iTotalTrades=OrdersTotal();
 
RaptorUK:

I think you need to work to the rest of your code, not just trailing stops . . . for example:

I suspect this may work on xxxUSD pairs when your account currency is USD . . it also uses iMaximumRisk stated as a %age, i.e. 3 meaning 3%, so iMaximumRisk= 0.02; will give you a risk of 0.02% . . . and after all that, it assumes your SL is 1 pip away.

This will give you the wrong answer if you place any trades manually or from other EAs . . . or the same EA on more than one currency pair . . . filter by Symbol and Magic number


it is my first EA ;-)

the risk is that what i need and i dont wanna change it but i need the TrailingStop and the BreakEven.

This will give you the wrong answer if you place any trades manually or from other EAs . . . or the same EA on more than one currency pair . . . filter by Symbol and Magic number

i know this problem but i dont know how to fix this ;-)

but first i need help with the TrailingStop and the BreakEven ;-)

im noob on MQL4 and learning at the time ;-)

please help me guys

 

Hi sunnyboy20,

here you find a simple way how a Trailing Stop can look like

https://docs.mql4.com/trading/OrderModify

 
sunnyboy20:

but first i need help with the TrailingStop and the BreakEven ;-)

You won't learn much by ignoring issues . . . but anyway, have a read of stuff here: http://crum.be/trailsl
 
please help me please
 
sunnyboy20:
please help me please
OK, read this: https://forum.mql4.com/23384
 

ok i´ve read this, but i dont understand how i can add this in my EA it is too much for me.

can you say me where i must add this code in my EA ?

 
sunnyboy20:

ok i´ve read this, but i dont understand how i can add this in my EA it is too much for me.

can you say me where i must add this code in my EA ?

Now is a great time to start learning . . . "your EA" ? if you don't know how to code how is it yours ? did you pay for it ?
 
RaptorUK:
Now is a great time to start learning . . . "your EA" ? if you don't know how to code how is it yours ? did you pay for it ?

ive code it by my self with help from a learning dvd ;-) i dont know the position where i must add the code, ive tried it 5 times but it wont be work

in general, see my EA structure anyway somehow quite different than the most other EA´s but for me is my structure easily to handle and not so difficult for me
 
sunnyboy20:

ive code it by my self with help from a learning dvd ;-) i dont know the position where i must add the code, ive tried it 5 times but it wont be work

in general, see my EA structure anyway somehow quite different than the most other EA´s but for me is my structure easily to handle and not so difficult for me

OK, fair enough.

You could create a function that looks at the open order(s) and adjusts the SL as per what you want from a trailing SL. You could call this function for each tick at the start of the start function . . . does that help ?

Reason: