codigo:


#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"

#include <Trade/Trade.mqh>

CTrade           trade;
CPositionInfo    pos;
COrderInfo       ord;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

   input group "*** Trading Inputs ***"
   
      
   enum SystemType{Forex=0, Bitcoin=1, _Gold=2, US_Indeces=3};
   input SystemType Stype=0;
   int SysChoice;
   
   
         
         input double RiskPercent         = 3;   // Risk as % of Trading capital)
        
         input ENUM_TIMEFRAMES Timeframe  = PERIOD_CURRENT; //Time frame to run
         input int    InpMagic            = 298347; //EA indentification no
         input string TradeComment = "Scalpin Robot";
         
         
         enum StarHour { Inactive=0, _0100=1, _0200=2, _0300=3, _0400=4, _0500=5, _0600=6, _0700=7, _0800=8, _0900=9, _1000=10, _1100=11, _1200=12, _1300=13, _1400=14, _1500=15, _1600=16, _1700=17, _1800=18, _1900=19, _2000=20, _2100=21, _2200=22, _2300=23};
         input StarHour SHInput=0; // Star Hour
         
         enum EndHour { Inactive=0, _0100=1, _0200=2, _0300=3, _0400=4, _0500=5, _0600=6, _0700=7, _0800=8, _0900=9, _1000=10, _1100=11, _1200=12, _1300=13, _1400=14, _1500=15, _1600=16, _1700=17, _1800=18, _1900=19, _2000=20, _2100=21, _2200=22, _2300=23};
         input EndHour EHInput=0; // End Hour
         
         int SHChoice;
         int EHChoice;
         
         int    BarsN               = 5;
         int    ExpirationBars      = 100;
         double OrderDistPoints     = 100;
         double Tppoints, Slpoints, TslTriggerPoints, TslPoints;
         
         
         input group "=== Forex Trading Inputs ==="
          
            input int TppointsInput = 200; // Take Profit (10 points = 1 pip)
            input int SlpointsInput = 200; // Stoploss Points (16 points = 1 pip)
            input int TslTriggerPointsInput = 15; // Points in profit before Trailing SL is activated (10 points = 1 pip)
            input int TslPointsInput = 10; // Trailing Stop Loss (10 points = 1 pip)
            
         input group "=== Crypto Related Input === (effective only under Bitcoin profile)"
           
            input double TPasPct =0.4; // TP as % of Price
            input double SLasPct = 0.4; // SL as%of Price
            input double TSLasPctofTP=5; // Trail SL as % of TP
            input double TSLTgrasPctofTP=7; // Trigger of Trail SL % of TP
         
         
         input group "=== Gold Related Input === (effective only under Gold profile)"
           
            input double TPasPctGold =0.2; // TP as % of Price
            input double SLasPctGold = 0.2; // SL as% of Price
            input double TSLasPctofTPGold=5; // Trail SL as % of TP
            input double TSLTgrasPctofTPGold=7; // Trigger of Trail SL % of TP
         
         input group "=== Indices Related Input === (effective only under Indices profile)"
          
            input double TPasPctIndices =0.2; // TP as % of Price
            input double SLasPctIndices = 0.2; // SL as 5% of Price
            input double TSLasPctofTPIndices=5; // Trail SL as % of TP
            input double TSLTgrasPctofTPIndices=7; // Trigger of Trail SL % of TP




int OnInit()
  {
//---
   
//---

      trade.SetExpertMagicNumber(InpMagic);
      
         ChartSetInteger(0,CHART_SHOW_GRID,false);
         
         
         SHChoice = SHInput;
         EHChoice = EHInput;
         
         
         if(Stype==0) SysChoice=0;
         if(Stype==1) SysChoice=1;
         if(Stype==2) SysChoice=2;
         if(Stype==3) SysChoice=3;
         
         
         Tppoints = TppointsInput;
         Slpoints = SlpointsInput;
         TslTriggerPoints = TslTriggerPointsInput;
         TslPoints = TslTriggerPointsInput;
      
      

      return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

      TrailStop();

      if(!IsNewBar())return;
      
      MqlDateTime time;
      TimeToStruct(TimeCurrent(),time);
      
      int Hournow = time.hour;
      

      
      if(Hournow<SHChoice){CloseAllOrders(); return;}
      if(Hournow>=EHChoice && EHChoice!=0){CloseAllOrders(); return;}
      
      
      if(SysChoice==1){

         double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
         Tppoints = ask * TPasPct;
         Slpoints = ask * SLasPct;
         OrderDistPoints = Tppoints/2;
         TslPoints = Tppoints * TSLasPctofTP/100;
         TslTriggerPoints= Tppoints * TSLTgrasPctofTP/100;
        }


      
      int BuyTotal=0;
      int SellTotal=0;
      
      
      for (int i=PositionsTotal()-1; i>=0; i--){
         pos.SelectByIndex(i);
         if(pos.PositionType()==POSITION_TYPE_BUY && pos.Symbol()==_Symbol && pos.Magic()==InpMagic) BuyTotal++;
         if(pos.PositionType()==POSITION_TYPE_SELL && pos.Symbol()==_Symbol && pos.Magic()==InpMagic) SellTotal++;
       }
       
       for (int i=PositionsTotal()-1; i>=0; i--){
         ord.SelectByIndex(i);
         if(ord.OrderType()==ORDER_TYPE_BUY_STOP && ord.Symbol()==_Symbol && ord.Magic()==InpMagic) BuyTotal++;
         if(ord.OrderType()==ORDER_TYPE_SELL_STOP && ord.Symbol()==_Symbol && ord.Magic()==InpMagic) SellTotal++;
       }
       
       if(BuyTotal <=0){
          double high = findHigh();
          if(high > 0){
             SendBuyOrder(high);
          }
        }
        
        
        if(SellTotal <=0){
          double low = findLow();
          if(low > 0){
             SendSellOrder(low);
          }
        }
      
   
  }
//+------------------------------------------------------------------+



double findHigh(){
   double highestHigh = 0;
   for(int i = 0; i < 200; i++){
      double high = iHigh(_Symbol,Timeframe,i);
      if(i > BarsN && iHighest(_Symbol,Timeframe,MODE_HIGH,BarsN*2+1,i-BarsN) == i){
         if(high > highestHigh){
            return high;
          }
         
       }
       highestHigh = MathMax(high, highestHigh);
      }
      return -1;

}




double findLow(){
   double LowestLow = DBL_MAX;
   for(int i = 0; i <200; i++){
      double Low = iLow(_Symbol,Timeframe,i);
      if(i > BarsN && iLowest(_Symbol,Timeframe,MODE_LOW,BarsN*2+1,i-BarsN) == i){
         if(Low > LowestLow){
            return Low;
          }
         
       }
       LowestLow = MathMin(Low, LowestLow);
      }
      return -1;

}


bool IsNewBar(){
   static datetime previousTime = 0;
   datetime currentTime = iTime(_Symbol,Timeframe,0);
   if(previousTime!=currentTime){
      previousTime=currentTime;
      return true;   
   }
   return false;
}


void SendBuyOrder(double entry){
   
   double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
    
       if(ask > entry - OrderDistPoints * _Point) return;
       
       double tp = entry + Tppoints * _Point;
       double sl = entry - Slpoints * _Point;
       
    double lots = 0.01;
    if(RiskPercent > 0) lots = calcLots(entry-sl);
    
    datetime expiration = iTime(_Symbol,Timeframe,0) + ExpirationBars * PeriodSeconds(Timeframe);
      
       trade.BuyStop(lots,entry,_Symbol,sl,tp,ORDER_TIME_SPECIFIED,expiration);
}



void SendSellOrder(double entry){
   
   double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);
    
       if(bid < entry + OrderDistPoints *_Point) return;
       
       double tp = entry - Tppoints*_Point;
       double sl = entry + Slpoints*_Point;
       
    double lots = 0.01;
    if(RiskPercent > 0) lots = calcLots(sl-entry);
    
    datetime expiration = iTime(_Symbol,Timeframe,0) + ExpirationBars * PeriodSeconds(Timeframe);
      
       trade.SellStop(lots,entry,_Symbol,sl,tp,ORDER_TIME_SPECIFIED,expiration);
}





double calcLots(double slPoints){
   double risk = AccountInfoDouble(ACCOUNT_BALANCE) * RiskPercent / 100;
   
   double ticksize =SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE);
   double tickvalue = SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_VALUE);
   double lotstep = SymbolInfoDouble( _Symbol,SYMBOL_VOLUME_STEP);
   double minvolume=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN);
   double maxvolume=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX);
   double volumelimit = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_LIMIT);
   
   double moneyPerLotstep = slPoints / ticksize * tickvalue * lotstep;
   double lots = MathFloor(risk / moneyPerLotstep) * lotstep;
   
   if(volumelimit!=0) lots = MathMin(lots,volumelimit);
   if(maxvolume!=0) lots = MathMin(lots,SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX));
   if(minvolume!=0) lots = MathMax(lots,SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN));
   lots = NormalizeDouble(lots,2);
   
   return lots;
}



void CloseAllOrders(){
   
   for(int i=OrdersTotal()-1;i>=0;i--){
      ord.SelectByIndex(i);
      ulong ticket = ord.Ticket();
      if(ord.Symbol()==_Symbol && ord.Magic()==InpMagic){
         trade.OrderDelete(ticket);
      }
   }
}


void TrailStop() {

   double sl = 0;
   double tp = 0;
   
   double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
   
   for (int i = PositionsTotal() - 1; i >= 0; i--) {
      if (pos.SelectByIndex(i)) {
         ulong ticket = pos.Ticket();
         
         if (pos.Magic() == InpMagic && pos.Symbol() == _Symbol) {
         
            if (pos.PositionType() == POSITION_TYPE_BUY) {
               if (bid - pos.PriceOpen() > TslTriggerPoints * _Point) {
                  tp = pos.TakeProfit();
                  sl = bid - (TslPoints * _Point);
                  
                  if (sl > pos.StopLoss() && sl != 0) {
                     trade.PositionModify(ticket, sl, tp);
                  }
               }
            }
             else if (pos.PositionType() == POSITION_TYPE_SELL) {
               if (ask +(TslTriggerPoints* _Point)<pos.PriceOpen()){
                  tp = pos.TakeProfit();
                  sl = ask + (TslPoints * _Point);
                  
                  if (sl > pos.StopLoss() && sl != 0) {
                     trade.PositionModify(ticket, sl, tp);
                  }
               }
            }
         }   
      }
   }
}


transcrição do video:

FULL Code || Forex Trading Robot || 90% WIN (backtest) || Tight StopLoss || (Part 1) - YouTube
https://www.youtube.com/watch?v=ZsxDG2fPc2U

Transcript:
(00:00) if you have a computer internet connection and 1 hour of time then by the end of this video you will have a scalloping robot which has more than 90% win rate with a very tighty stop loss of 20 Pips even if you know nothing about coding mql language or metatrader as a trading platform we'll go step by step we'll cover these topics and I'm putting the time Mark so if you're already comfortable with certain sections then you can easily skip forward sections that you don't need to see so we'll look at a strategy back test and result then
(00:27) we'll look at the strategy itself then we're going to download metatrader and open up the coding environment then we'll write all the codes and then we'll execute the EA and then we're going to set up all the inputs that we need to provide to the EA and we will apply it to charts to show you the strategy results up front in a back test I've already written the code and executed the file so I've loaded it into metat Trader we're going to use it on USD JPY on a 5- minute chart from 2023 beginning until today and I'm starting with a balance of
(01:00) €1,000 and let's start the test so here we are in the testing environment and as you can see the EA has started to perform the trading operations it has a very tight stop loss and it performs the scalloping operations so you can see a lot of Trades opening and closing very very quickly on a 5minute chart now I'm going to speed up the test because I don't want to take too much of your time so the test has finished and if if we look through the testing details what we see is a lot of Trades opening and at the end we are finishing
(01:40) with around € 26,000 of profit if we go back to metat Trader and go to the back test Tab and what we can see is we started with an initial deposit of €1,000 and we're finishing with a net profit of close 26,000 Euros a running draw down of close to 22% but that's also dependent on the risk settings that we will go in deep details what we have is 91% short trades that we won and close to 91% long trades that we won if you look at the graph of equity you basically see no running draw downs and that is because of the
(02:14) tightest stop- loss that the strategy employs the overall performance is up and up there are periods of stagnation there are also periods of draw down but overall the strategy keeps making money and we're ending with around 26 27,000 of profit strategy works best on USD JPY gpp USD and Euro USD it can work on any pair as long as the spreads are low so let's very quickly run it on Euro USD as well and I'll remove the visual mode because we have already seen the visual mode with usdjpy and I'll speed up the test so once again what we see is no
(02:50) running draw Downs because of tius stop losses the performance is up and up there are periods of decline as well here for example and here as well but we're ending up with something like 4,000 500 in the end overall the back test result 14% draw down 91% short trade one 95% long trade one and a total profit of 3568 if we run it also on [Music] gbpusd and again I'll speed up the the test once again no running draw Downs because of the tightest stop loss some periods of stagnation between July and January but overall performance is up
(03:33) and up if we look at the back test results we've got 21% of draw down we've got 92% of short trades one and 92% of long trades one we started with a balance of 1,000 we're ending up with a net profit of 3,600 and now the strategy itself strategy in itself is very very simple what we're betting on is that if the price is moving in a certain direction that it will continue to move in the same direction for at least one more pip now you can use various entry methods like EMA crossovers RSI crossing a certain threshold ichimoku clouds
(04:10) whatever your criteria is as long as the market is moving in a certain direction and you take the trade in the same direction as well the criteria we're using in this example or in this EA is the last High and the last low so we place a buy order at the last high and we place uh a sell order at the last low and we put a 20 pip take profit and a 20 pip stop loss that's where the tight stop loss comes into the picture now if the price comes down and hits that level again it is moving in that direction then and if it is moving in the downward
(04:44) direction that what we basically saying is that if the price comes down to that level that we're betting that it will go at least one more pip so at this point the cell order will convert into a sell and then as soon as the price moves more than one one and a half two Pips defined in the criteria we will start to Trail the stop loss extremely aggressively until the price comes back and either hits the stop loss or it continues in the direction that it is continuing or it is coming and hits our take profit so that
(05:17) is the entire strategy for those of you who are hearing the word metat Trader for the first time it's a trading platform and you will learn about it as we go but you can head to Google just type meta Crea a download and click on the first link and you can download it for Windows and you can download it for uh MacBooks as well once you have downloaded it and youve installed it and you open it you will basically see a screen similar to this you need to head to the accounts by the way if it is not visible it's basically the market watch and the
(05:51) Navigator which are turned on currently in the view this is the Navigator and in the accounts you can open up an account or if you already have a trading account then you can log into it you can select the servers basically uh depending on who your broker is and then provide the login and password and hit okay and you will connect to that server here in the market watch you basically have all the pairs if you're not missing any pairs then you can click on the plus button to add those pairs right clicking let's use
(06:20) gpp USD right clicking on it you can go show the chart window and there you have this charting software which is deploying the prices in The View Bar as well again you can go to strategy tester and that is the one that we were using to test the strategies here you will have all the robots that you have written now in order to code an EA and apply it to the charts you need to head to the development environment by clicking the button IDE when you click this button The Meta Trader is going to open up the meta editor and you're going
(06:55) to end up with an screen like this so this is about the meta Trader and meta editor so once you have downloaded metat Trader and you have opened up the meta editor now we can start writing the codes so let's start coding I'm going to create a folder in the exper folder by creating a new folder and let's call it the scalloping robot by selecting this and clicking new then you're going to be creating the expert advisor in that folder let's give it a name and let's call it escallop robot and when you hit next next and
(07:31) then finish you get this template now in meta editor all of the CES which are written after these two lines meta editor treats them as Commons so it doesn't read them it just goes and reads all of the codes which are without these two dashes I'm going to remove these commment dashes lines to make it clean and after the clean up we end up with a template like this now there are three functions that come automatic Ally when you create a new template the on init the on D init and onti on init is basically on initialization so when we
(08:08) will attach the EA to a chart that's the initialization of the EA and every code that we write here is going to be run when the is applied to the Chart then the initialization as you can imagine is on De initialization so when you remove the E from the chart the chodes written here are going to be run and that leaves us with ontick function now on tick function if I go back to metat Trader every time the price data changes that is a tick in mql terminology so whenever there's a new data about the price comes in that's
(08:42) what metatrader treats as tick and then on tick is basically whenever a new tick arrives all of the codes which are going to be written between these two curly brackets are going to be run now we will create some functions of our own as well below here because these three functions available to us are not going to be enough to write the entire code but we'll go step by step and I'll I'll explain every step in details but for now let's first go back to metatrader because we're going to see the input tabs the input tab is where all of the
(09:16) variables for the EA are defined so when you will be applying the EA to a chart or when you're doing a back test you will be able to come here and Define all of these input variables now let's go one by one because I'll explain them and then we will we use them to start our coding so the first one is how much risk as a percentage on each trade that I'm willing to take so if you have ,000 in balance a 2% risk will mean that in case the trade comes back and hits your stop- loss you lose 2% of 1,000 which is €20
(09:48) then the next ones are about the trailing stop as we already saw in the strategy description that we will be trailing the stop loss very very aggressively so there are two points to it the first one is how how much do we want the stop loss to be away from the price so if the price is moving in our Direction how aggressively do we want to trail that stop loss now 10 points equals one pip so if I say 10 that basically means that we want to Trail the stop- loss behind the price by one pip then the next one is points in
(10:18) profit before the trailing stop is activated is basically if we have taken the the trade on a certain price level how much do we want the trade to go in profit before we start trailing the stop stop loss and I'm defining here as 15 points which is 1 and 1/2 pip so once the price has moved in our favor by 1 and 1/2 pip that's when we start trailing the stop- loss by one pip then the time frame to run on that basically is which time frame do you want to run it on 5 minutes chart 10 minutes chart 15 minutes chart 30 minutes chart 1 hour
(10:51) chart I normally use 5 minutes chart and we will Define it here so that the EA in the background knows what time frame to all always run the code on even if you change on the chart itself because what you can do is here on the chart currently it's at 1 hour but what I can do is I just want to quickly see how the price looks on 15minute chart but if I change it and the EA was defined as current then the EA will start treating 15 minutes to be the chart that it's running on and not the 1 hour or the 5 minute but if we Define it as 5 minutes
(11:28) here in the EA itself as an input variable then even when you're changing the chart on the metat trader the EA in the background knows that it still needs to continue running the EA on 5 minutes irrespective of what the time frame on the chart is then the EA identification number and that is basically for the EA to identify the trades that it places by itself so for example if you had an account and let's say if you had three or four different charts let's open up another chart let's say on Euro New Zealand you had another EA cordos
(12:04) another RSI EA which is running here and on gpp USD you had our scalloping robot running then the year is going to get confused which traits it has played itself and which trades are coming from the other EA and this is why we need to define a unique identification code for the EA so the EA always knows which trades are its own trades and which trades are not its own trade you can put any random number you like but at least now the EA knows that if the trade has this number then this is a trade that the EA has placed itself so any changes
(12:38) to that trade it will make it is making changes only to its own trade then I also like to have the start hour and the end hour defined because during the midnight portion the spreads go so Bonkers that I do not want the EA to be trading in that time so what we want to be able to Define is let's say I want to say my ear only starts trading at 800 hours in the morning and it stops at 2100 hours so it does not trade between the hours of 2100 and 800 hours the next morning then there are some variables that I have defined for the background
(13:13) chart and color but these are only my preferences these have nothing to do with the e but if you want to code them what they basically do is if you go back once you apply the chart I like to have no grades a black background yellow as my bull candles and red as my bear candles and this is what I'm defining here that I want chart to be in Candlestick but you can also have it as a bar chart or a line chart I want the background to be black I don't want to show the grid lines I want the bull candles to be yellow but you can change
(13:43) it to God knows whatever you like and then also my bare candles are going to be this color this is just my own preferences of wanting to see the chart like this and not like this it just looks ugly that way to my eyes so now in order to be able to write these into the coding that we will do we will need to ask the user for risk percentage and the trailing stops parameter which chart to run on and the hours of trading and the unique EA code just remember this because we're going to be using it in the coding now back to meta editor the
(14:17) top portion here before these functions is the portion where you define all of the variables so this is where we're going to be asking the user for input and then we're going to also Define some variables where we're going to use those variables in the coding but we're not going to ask any input from the user so let's start with creating a section and by section I means here you see that these all variables are under trading input and all of these variables are under chart background so back in meta editor if we write the code input group
(14:48) then basically the the metat trader is going to create a header section if you write input group and then within apostrophes whatever you write so if you write D D Dash trading input it's going to create a section called trading input now let's start asking our user for the inputs and the first input we need from the user is the risk percentage so we write input and if we write if we start the code in the line as input then the EA or the metat trader is going to or when we writing the code and executing it EA is going to identified is this is
(15:25) something which the user needs to input and we Define a variable and we call it risk percent for example and we give it a value of three so basically three and we're going to be using it later on as 3% now what does this double mean meta editor works with different kinds of variable so if you are going to store in a variable uh an integer say 1 2 3 4 then you basically say in and meta editor is going to know that whatever variable you're going to Define next is going to be storing an integer value now if you
(16:02) want to store something which will have decimal then you have to start with or defining the variable as double what we have done in this case so when we say double then we can store decimal values you can store 3.5 3.6 and because risk percentage depending on the user whether they want to Define it as 2 2.1 2.
(16:23) 2 if they get really fancy with it I'm going to create the variable as double now remember this part which is you start with input if you say input then meta editor is going to know that it is going to be asking the user for an input double is defining what kind of variable it is going to be followed by the name that we are defining the variable and then if you want to store a value you can leave it blank as well like this but then the variable on creation is going to be empty if you say three equals to three then meta editor is
(17:01) going to start with a value of three on the onset of the EA so even if the user does not define anything or forgets to Define it there is a default value now let's convert this small code that we have written so far into an EA by clicking the button compile and we have zero errors zero warnings which basically means that this EA has been created or updated so now if I go back to metatrader what I will see here is that in the experts in our folder that we created as scalping robot our new robot is now available if I
(17:35) select it and then go back to input stab what you can see here is that that the section trading input has been created and the part risk percent has been created with a value of two if I go back to default yeah it's three and this is the three that we had defined here now if you put a double hash here and say let's say risk as percentage of trading capital and compile it again now if we go back to metat Trader what we will see is that the variable is not called risk percent it's actually called risk as a percentage of trading Capital risk as a
(18:11) percentage of trading Capital so this is a way of because we Define the variables as very like unique words and the user might not be able to to understand them so if you put double hashes and then say what you want to say here the actual name of the variable is going to change in metat Trader now the next variable that we wanted to collect input on from the user was take profit points how much is the take profit and I will ask the user to provide an input so I'll start with input integer because we're going
(18:45) to we're not going to store decimal values in this and I'm defining the variable as TP points 200 and we say it's the take profit and 10 points equals 10 one pip then if I go again again and say and this should be in a small so now if I say input again integer and now we say stop-loss points and we can again Define it as 200 points and say this are the stop loss points and 10 points equals one p just to prompt the user that when they're defining it in points they're defining it in points they don't confuse it with Pip now if I
(19:31) compile it again and now if we go back to metat Trader we will see that these variables are also now created coming back to meta editor the next variables that we need input on are on trailing stops and the first one was when do we start stop loss to be triggered so I'm going to create a variable again integer because we're not going to store decimal values in it and I'm calling it trailing stoploss TSL trigger points so when to start triggering when to start moving moving the stop loss and I'm giving it a name
(20:01) or or defining it a giving it a description that points in profit before the trailing loss is activated once again if I compile it and then I go back I will see here that now the user can also Define when the trailing stop is activated back again to meta editor the next variable we're going to ask for is to Define as an input the TSL points which is how much the stop loss need to Trail the price buy so once it is triggered let's say the price has gone in our favor by 1 and 1/2 pip now we need to start trailing the stop loss how
(20:38) far do we want the trailing stop loss to be from the price and that's what we're defining here as one pip or 10 points and then we ask the user for their input on the time frame so I'll say input but now time frame is not a double it's not an integer and in mql it is defined as enum meaning enumerated enum time frames so that's the type of the variable and once you have defined the type then we need to give it a name and let's call it time frame and once I hit enter now this once you start writing period it will open up
(21:17) the drop- down button and from there you can select what the default value is going to be one day chart 1 hour chart 12 hour chart 2our chart I'll set the default as perian C which basically means that whatever chart you're applying it to whatever is the time frame on that chart at that point in time that's what the year is going to use I hit enter and then every code in meta editor finishes with a colon that's basically where of telling mql that the code has finished or the instruction has finished and it needs to move on to the
(21:51) next instruction let's give it a description and let's call it time frame to run now if I compile it and go back to metat Trader then we basically have the variables defined here as well they can select it from a drop down or they can Define the value directly another input that I need from the user is the magic number which is the unique code for identification of the EA and then the last input that I'm going to ask the user to provide is a comment and again this here I'm saying input as a string and a string basically
(22:27) mean text so integer was 1 2 3 4 5 double with decimal time frames are enumerated time frames as a variable type and then input is strings basically mean the variable is going to store text because I also want to put a trade comment and let's call it es scalping robot for now so now if I compile it and go back here are all the variables that we we are giving the users the possibility to Define for themselves so these are all the variables where we're asking the user to provide an input but we're also going to need some variables where we
(23:01) don't want the user to provide any input we're going to hard code them now guys I've tried my best to within a week write the entire coding and record it and edit it but it's just a bit too much I mean it takes forever to to capture the entire thing and then editing is a pain in the back side already in this video we have looked at the E and everything we have looked at the user inputs we' have coded the user inputs in the next video we will go through writing the CES for finding the high High finding the lower lows and then
(23:31) also creating the trading conditions so that the trades can be placed and then we can start trailing the stop losses but I also appreciate your patience with it I'll see you next week stay safe trade safe [Music]

me mostre o trecho queue ele diz no video queue é responsavel pelos placed, as ordens pendentes eu quero saber onde é feito a quantidade q seja colocada em placed