Help needed to solve this code on MQL5

 

This is a basic EMA for Buy & SL.

But I want to add TSL with the EA, can some experts help me solve this.

This is the code as I want to add a auto trailing stop loss into this below code.

***

This a a code I found on MQL5.com for trailing stop loss

***

Can someone help me to merge this both codes into a single file...


Thanks & Regards,

Novelty_Scalper

Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Symbol Properties - Environment State - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Novelty Scalper :

This is a basic EMA for Buy & SL.

But I want to add TSL with the EA, can some experts help me solve this.

This is the code as I want to add a auto trailing stop loss into this below code.

***

This a a code I found on MQL5.com for trailing stop loss

***

Can someone help me to merge this both codes into a single file...


Thanks & Regards,

Novelty_Scalper

1. Remember that the indicator handle MUST be created ALL ONCE - AND THIS SHOULD BE DONE IN OnInit!!!

2. Please insert the code correctly: when editing a message, press the button   and paste your code into the pop-up window

 
Novelty Scalper #:

Forum on trading, automated trading systems and testing trading strategies

Help needed to solve this code on MQL5

Vladimir Karputov, 2022.02.11 07:48

1. Remember that the indicator handle MUST be created ALL ONCE - AND THIS SHOULD BE DONE IN OnInit!!!


 
Novelty Scalper # :

You are making the same BIG MISTAKE!

Remember that the indicator handle MUST be created ALL ONCE - AND THIS SHOULD BE DONE IN OnInit!!!
 
Novelty Scalper # :
Im not a coder, so i have no idea, how to do it.


Can you please merge the both codes together. And give me a final code..?

Move the handle creation to OnInit.

 

An example of how to create indicators:

//+------------------------------------------------------------------+
//|                                                         Test.mq5 |
//|                              Copyright © 2022, Vladimir Karputov |
//|                      https://www.mql5.com/en/users/barabashkakvn |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2022, Vladimir Karputov"
#property link      "https://www.mql5.com/en/users/barabashkakvn"
#property version   "1.00"
//--- input parameters
//--- MA's parameters
input string               Inp_MA_Symbol              = "USDJPY";    // MA: symbol
input ENUM_TIMEFRAMES      Inp_MA_period              = PERIOD_M30;  // MA: timeframe

input int                  Inp_MA_Fast_ma_period      = 7;           // MA Fast: averaging period
input int                  Inp_MA_Slow_ma_period      = 36;          // MA Slow: averaging period

input int                  Inp_MA_Fast_ma_shift       = 0;           // MA Fast: horizontal shift
input int                  Inp_MA_Slow_ma_shift       = 2;           // MA Slow: horizontal shift

input ENUM_MA_METHOD       Inp_MA_Fast_ma_method      = MODE_SMA;    // MA Fast: smoothing type
input ENUM_MA_METHOD       Inp_MA_Slow_ma_method      = MODE_SMA;    // MA Slow: smoothing type

input ENUM_APPLIED_PRICE   Inp_MA_Fast_applied_price  = PRICE_CLOSE; // MA Fast: type of price
input ENUM_APPLIED_PRICE   Inp_MA_Slow_applied_price  = PRICE_CLOSE; // MA Slow: type of price
//---
int      handle_iMA_Fast;                       // variable for storing the handle of the iCustom indicator
int      handle_iMA_Slow;                       // variable for storing the handle of the iCustom indicator
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create handle of the indicator iMA
   handle_iMA_Fast=iMA(Symbol(),Period(),Inp_MA_Fast_ma_period,Inp_MA_Fast_ma_shift,
                       Inp_MA_Fast_ma_method,Inp_MA_Fast_applied_price);
//--- if the handle is not created
   if(handle_iMA_Fast==INVALID_HANDLE)
     {
      //--- tell about the failure and output the error code
      PrintFormat("Failed to create handle of the iMA indicator 'Fast' for the symbol %s/%s, error code %d",
                  Symbol(),
                  EnumToString(Period()),
                  GetLastError());
      //--- the indicator is stopped early
      return(INIT_FAILED);
     }
//--- create handle of the indicator iMA
   handle_iMA_Slow=iMA(Symbol(),Period(),Inp_MA_Slow_ma_period,Inp_MA_Slow_ma_shift,
                       Inp_MA_Slow_ma_method,Inp_MA_Slow_applied_price);
//--- if the handle is not created
   if(handle_iMA_Slow==INVALID_HANDLE)
     {
      //--- tell about the failure and output the error code
      PrintFormat("Failed to create handle of the iMA indicator 'Slow' for the symbol %s/%s, error code %d",
                  Symbol(),
                  EnumToString(Period()),
                  GetLastError());
      //--- the indicator is stopped early
      return(INIT_FAILED);
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
  }
//+------------------------------------------------------------------+
Files:
Test.mq5  8 kb
 
Novelty Scalper # :
Sir i dont have experience in coding....

You have these scenarios:

1. Start learning to program.

2. If you do not want to study:

2.1. You should start searching for the right code in CodeBase or Market

2.2. If you do not want to search - you can contact the Freelance service.

Trading applications for MetaTrader 5 to order
Trading applications for MetaTrader 5 to order
  • 2022.02.11
  • www.mql5.com
The largest freelance service with MQL5 application developers
 
iMA crossover august
iMA crossover august
  • www.mql5.com
Торговая система на пересечении двух iMA (Moving Average, MA). Поиск сигнала только в момент рождения нового бара. При появлении сигнала противоположная позиция закрывается. Стоп лосс и Тейк профит динамические - по индикатору iATR (Average True Range, ATR)
Reason: