Download MetaTrader 5

I need add one function to this code

To add comments, please log in or register
BHANU
11
BHANU  
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property version   "1.00"
#property strict
#property show_inputs
enum Operation{
   buy=OP_BUY,    //BUY
   sell=OP_SELL,   //SELL
};

extern double Lots=1;           //Specify position size, this is ignored if you use the Risk %
extern double RiskPercentage=2; //%risk is 2
input Operation Command=buy;   //order type
extern int TakeProfit=60;      //Take profit is 60pips
extern int StopLoss=30;       //stop loss is 30pips
extern int Slippage=2;        //Slippage in pips
extern string Cmt="";         //Comment for the order if you want one
//Function to normalize the digits
double CalculateNormalizedDigits()
{
   if(Digits<=3){
      return(0.01);
   }
   else if(Digits>=4){
      return(0.0001);
   }
   else return(0);
}
void OnStart()
  {
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
int Cmd=Command;
   
   //Normalize the digits and calculate the position size
   double nTickValue=MarketInfo(Symbol(),MODE_TICKVALUE);
   double nDigits=CalculateNormalizedDigits();
   if(Digits==3 || Digits==5){
      Slippage=Slippage*10;
      nTickValue=nTickValue*10;
   }
   if(RiskPercentage==2){
      Lots=(AccountBalance()*RiskPercentage/100)/(StopLoss*nTickValue);
      Lots=MathRound(Lots/MarketInfo(Symbol(),MODE_LOTSTEP))*MarketInfo(Symbol(),MODE_LOTSTEP);
   }
   
   //Set the open, stop loss and take profit prices
   double OpenPrice=0;
   double TakeProfitPrice=0;
   double StopLossPrice=0;
   
   if(Cmd==OP_BUY){
      OpenPrice=NormalizeDouble(MarketInfo(Symbol(),MODE_ASK),Digits);
      if(TakeProfit!=0) TakeProfitPrice=NormalizeDouble(OpenPrice+TakeProfit*nDigits,Digits);
      if(StopLoss!=0) StopLossPrice=NormalizeDouble(OpenPrice-StopLoss*nDigits,Digits);
      
   } 
   if(Cmd==OP_SELL){
      OpenPrice=NormalizeDouble(MarketInfo(Symbol(),MODE_BID),Digits);
      if(TakeProfit!=0) TakeProfitPrice=NormalizeDouble(OpenPrice-TakeProfit*nDigits,Digits);
      if(StopLoss!=0) StopLossPrice=NormalizeDouble(OpenPrice+StopLoss*nDigits,Digits);
   } 
   
   //Print on screen the informations to see what we are submitting
   Print("Opening an Order ",Command," size ",Lots, " open price ",OpenPrice," slippage ",Slippage," SL ",StopLossPrice," TP ",TakeProfitPrice," comment ",Cmt);
   
   //Submit the order, check the it has been accepted
   int OrderNumber;
   OrderNumber=OrderSend(Symbol(),Cmd,Lots,OpenPrice,Slippage,StopLossPrice,TakeProfitPrice,Cmt);
   if(OrderNumber>0){
      Print("Order ",OrderNumber," open");
   }
   else{
      Print("Order failed with error - ",GetLastError());
   
   }
  }
   
  
//+------------------------------------------------------------------+

 I need ea or script for the following data

       Input: risk-2%

                  TP-60 pips

                  Sl-30Pips 

                  Type of order- Buy/sell

It will be executed order but i need to add "Once order is executed,After price is reached to 75% of Tp Automatically Sl should be Break Even point".

                 

                   Can anyone code it and share it here? 

                                     Thank you .

Alain Verleyen
Moderator
33334
Alain Verleyen  

Forum on trading, automated trading systems and testing trading strategies



Welcome,

  • Usually people who can't code don't receive free help on this forum, though it could happen if you are lucky, be patient.
  • If you show your attempts and describe well your problem, you will most probably receive an answer from the community.
  • If you don't want to learn to code, nothing bad, you can either look at the Codebase if something free already exists, or in the Market for paid products (sometimes free also).
  • Finally, you also have the option to hire a programmer in the Freelance section.

Good luck.


whroeder1
15917
whroeder1  
BHANU: ,just i need to add this condition to  code
So do it! learn to code it, or pay (Freelance) someone to code it. We're not going to code it for you. We are willing to help you when you post your attempt (using SRC) and the nature of your problem.
BHANU
11
BHANU  
whroeder1:
So do it! learn to code it, or pay (Freelance) someone to code it. We're not going to code it for you. We are willing to help you when you post your attempt (using SRC) and the nature of your problem.


Thank you for your information.

                            I already have a code for the above data but I need to add only one condition that is BE level after reached to tp 40 pips Sl should be BE level so can you please suggest me how to write that function ? .

                            I'm a beginner to the  programming.  

honest_knave
Moderator
2326
honest_knave  
BHANU:


Thank you for your information.

                            I already have a code for the above data but I need to add only one condition that is BE level after reached to tp 40 pips Sl should be BE level so can you please suggest me how to write that function ? .

                            I'm a beginner to the  programming.  


Try reading up on OrderModify() 

There is an example in the documentation.

HTH

OrderModify - Trade Functions - MQL4 Reference
OrderModify - Trade Functions - MQL4 Reference
  • docs.mql4.com
OrderModify - Trade Functions - MQL4 Reference
To add comments, please log in or register