Pine script code need to convert to mql5

 

Can any body convert this pine script code to mql5:

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © forkh

//@version=5
strategy("Momentum Strategy", overlay=true)
length = input(12)
price = close
momentum(seria, length) =>
    mom = seria - seria[length]
    mom
mom0 = momentum(price, length)
mom1 = momentum( mom0, 1)
if (mom0 > 0 and mom1 > 0)
    strategy.entry("MomLE", strategy.long, stop=high+syminfo.mintick, comment="MomLE")
else
    strategy.cancel("MomLE")
if (mom0 < 0 and mom1 < 0)
    strategy.entry("MomSE", strategy.short, stop=low-syminfo.mintick, comment="MomSE")
else
    strategy.cancel("MomSE")
//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)

Thank yor for your coopration 

 
  1. ALI ALI: Can any body

    How To Ask Questions The Smart Way. (2004)
              Prune pointless queries.


  2. ALI ALI: convert this
    You have only four choices:
    1. Search for it (CodeBase or Market). Do you expect us to do your research for you?

    2. Try asking at:

    3. MT4: Learn to code it.
      MT5: Begin learning to code it.

      If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into your code.
                I need HEEEELP, please, it's URGENT...really ! - General - MQL5 programming forum (2017)

    4. Or pay (Freelance) someone to code it. Top of every page is the link Freelance.
                Hiring to write script - General - MQL5 programming forum (2019)

    We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using CODE button) and state the nature of your problem.
              No free help (2017)

 
ALI ALI:

Can any body convert this pine script code to mql5:

Thank yor for your coopration 

Hi, If you provide further explanations about the strategy implemented in pine script we could help much better.
But out of my knowledge about pine script I guess the following code is almost the equivalent of what you need:

#include <Trade/Trade.mqh>

input int length = 12;
input double LOT = 0.01;
CTrade trade;

int OnInit() {
   return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason) {}

void OnTick() {

   double mom0, mom1;
   
   mom0 = Momentum(length);
   mom1 = Momentum(length, 1);
   
   if (mom0 > 0 && mom1 > 0) {

      double entryPrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK) + SymbolInfoDouble(_Symbol, SYMBOL_POINT);
      double stopLoss = SymbolInfoDouble(_Symbol, SYMBOL_ASKLOW) - SymbolInfoDouble(_Symbol, SYMBOL_POINT);
      
      
      if (PositionsTotal()) 
         trade.PositionClose(_Symbol);
         
      trade.BuyStop(LOT, entryPrice, _Symbol, stopLoss);
      
   }
   else if (mom0 < 0 && mom1 < 0) {
   
      double entryPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID) - SymbolInfoDouble(_Symbol, SYMBOL_POINT);
      double stopLoss = SymbolInfoDouble(_Symbol, SYMBOL_BIDHIGH) + SymbolInfoDouble(_Symbol, SYMBOL_POINT);
      
      
      if (PositionsTotal()) 
         trade.PositionClose(_Symbol);
         
      trade.SellStop(LOT, entryPrice, _Symbol, stopLoss);
  }
  
}  
  
  
//+------------------------------------------------------------------+
//| Calculate Momentum                                               |
//+------------------------------------------------------------------+
double Momentum(int length, int shift=0) {
   double mom = iClose(_Symbol, PERIOD_CURRENT, shift) - iClose(_Symbol, PERIOD_CURRENT, shift+length);
   return (mom);
}
//+------------------------------------------------------------------+

You may consider preventing from opening a new order on every tick by adding custom code to filter number of open orders/positions.

Good Luck!