Remote Licensing System for expert advisors

指定

//+------------------------------------------------------------------+
//|                                                      Hedging.mq4 |
//|                                  Copyright 2023, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict


input int consecutiveBullCandles = 4;
input int consecutiveBearCandles = 4;

input double TP                  = 60.0;
input double LotSize             = 0.01;

input int maxAllowedPositions     = 1; //Set the max Buy positions
input int maxSellAllowedPositions = 1;//Set the max Sell positions



double bTakeProfit; 
double sTakeProfit;


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
  bTakeProfit = takeProfit(Symbol(), OP_BUY, TP);
  sTakeProfit = takeProfit(Symbol(), OP_SELL, TP);
  
   

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

bool CheckConsecutiveBullish()
{
    bool isConsecutiveBullish = true;
    
    for (int i = 1; i <= consecutiveBullCandles; i++)
    {
        if (Close[i] <= Open[i])
        {
            isConsecutiveBullish = false;
            break;
        }
        
    }

    return isConsecutiveBullish;
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool CheckConsecutiveBearish()
{
   bool isConsecutiveBearish = true;
   
   for (int i = 1; i<= consecutiveBearCandles; i++)
   {
      if (Close[i] >= Open[i])
      {
         isConsecutiveBearish = false;
         break;
      }
   }
   
   return isConsecutiveBearish;
}


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double stopLoss(string symbol, ENUM_ORDER_TYPE type, double slPips)
{
   
   if(slPips>0)
     {
         if(type==OP_BUY)
           {
              return (Ask - (slPips*SymbolInfoDouble(Symbol(), SYMBOL_POINT)*10));
           }
           
         else
           {
              return (Bid + (slPips*SymbolInfoDouble(Symbol(), SYMBOL_POINT)*10));
           }
     }
   else  return 0;
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

double takeProfit(string symbol, ENUM_ORDER_TYPE type, double tpPips)
{
   
   if(tpPips>0)
     {
         if(type==OP_BUY)
           {
              return (Ask + (tpPips*SymbolInfoDouble(Symbol(), SYMBOL_POINT)*10));
           }
           
         else
           {
              return (Bid - (tpPips*SymbolInfoDouble(Symbol(), SYMBOL_POINT)*10));
           }
     }
   else  return 0;
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

int MaxBuyOpenPositions(int maxAllowed)
{
   int totalPositions = OrdersTotal(); // Get the total number of open positions
   
   if (totalPositions >= maxAllowed)
   {
      Print("Maximum number of open positions reached!");
      return maxAllowed;
   }
   
   return totalPositions;
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

int MaxSellOpenPositions(int maxAllowed)
{
   int totalSellPositions = OrdersTotal(); // Get the total number of open positions
   
   if (totalSellPositions >= maxAllowed)
   {
      Print("Maximum number of open positions reached!");
      return maxAllowed;
   }
   
   return totalSellPositions;
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+


void OpenPosition()
{
   int totalPositions = MaxBuyOpenPositions(maxAllowedPositions);
   int totalSellPositions = MaxSellOpenPositions(maxSellAllowedPositions);
    
   if (CheckConsecutiveBullish() && totalPositions < maxAllowedPositions)
   {
      int Buy = OrderSend(NULL, OP_BUY, LotSize, Ask, 10, 0, bTakeProfit,NULL);
   }
   
   if (CheckConsecutiveBearish() && totalSellPositions < maxSellAllowedPositions)
   {
      int Sell = OrderSend(NULL, OP_SELL, LotSize, Bid, 10, 0, sTakeProfit,NULL);
   }
   
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

void CloseBuyOrder()
{
   for(int i=0; i<OrdersTotal(); i++)
   {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {
         if(OrderType()==OP_BUY)
         {
            int CloseBuy = OrderClose(OrderTicket(), OrderLots(), MarketInfo(Symbol(),MODE_BID),Red);
            if(CloseBuy < 0) Print("Close Buy Error: " + string(GetLastError()));
         }
      }
   }
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CloseSellOrder()
{
   for(int i=0; i<OrdersTotal(); i++)
   {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {
         if(OrderType()==OP_SELL)
         {
            int CloseSell = OrderClose(OrderTicket(),OrderLots(),MarketInfo(Symbol(),MODE_ASK), Red);
            if(CloseSell < 0) Print("Close Sell Error: " + string(GetLastError()));
         }
      }
   }
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void ClosePendingOrder()
{
   for(int i=0; i<OrdersTotal(); i++)
   {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {
         if(OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP)
         {
            int Delete = OrderDelete(OrderTicket());
            if(Delete < 0) Print("Delete Error: " + string(GetLastError()));
         }
      }
   }
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

void CloseTradeOnTP()
{
   
   for(int i=0; i<OrdersHistoryTotal(); i++)
   {
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
      {
         if(OrderTakeProfit()==OrderClosePrice())
         if(TimeCurrent() - OrderCloseTime() <= 5)
         {
            CloseBuyOrder();
            CloseSellOrder();
            ClosePendingOrder();
         }
      }
   }
   
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

bool newBar()
{
   datetime          currentTime =  iTime(Symbol(), Period(), 0);
   static datetime   priorTime   =  currentTime;
   bool              result      =  (currentTime!=priorTime);
   priorTime                     =  currentTime;
   
   return result;
}



//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
/*double GetLastOpenPositionLotSize()
{
    int totalOrders = OrdersTotal();
    
    if (totalOrders > 0)
    {
        int lastPositionIndex = totalOrders - 1;
        
        if (OrderSelect(lastPositionIndex, SELECT_BY_POS, MODE_TRADES))
        {
            double lastPositionLotSize = OrderLots();
            return lastPositionLotSize;
        }
    }
    
    // If no open positions found, return 0.0
    return 0.0;
}*/

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double orderLotsize()
{
   if(OrdersTotal()>0)
   {
      for(int i=0; i<OrdersTotal(); i++)
      {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && (OrderType()<=1))
         {
            double Lotsize = OrderLots() * 2;
            return Lotsize;
         }
      }
   }
   return 0.0;
}


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

bool CheckPendingOrderLimit2(int maxOrders)
{
    int totalPendingOrders = 0;
    

    for (int i = 0; i < OrdersTotal(); i++)
    {
        if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
            if (OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP)
            {
                totalPendingOrders++;
                if (totalPendingOrders >= maxOrders)
                    return false; // Maximum limit reached
            }
        }
    }

    return true; // Within the limit
}


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void LastOpenPrice2()
{
   double previousStopPrice = 0;
   
   int maxPendingOrders = 2; // Maximum allowed number of pending orders

   // Check if the number of pending orders is within the limit
   if (!CheckPendingOrderLimit2(maxPendingOrders))
   {
       Print("Pending order limit reached. Cannot open new pending order.");
       return;
   }

   for(int i = 0; i < OrdersTotal(); i++)
   {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      {
         if(OrderType() == OP_BUY || OrderType() == OP_SELL)
         {
            double openPrice = OrderOpenPrice();
            string symbol = OrderSymbol();

            if(previousStopPrice == 0)
            {
               if(OrderType() == OP_BUY)
               {
                  double stopPrice = openPrice - (30 * SymbolInfoDouble(symbol, SYMBOL_POINT) * 10);
                  int sellStop = OrderSend(symbol, OP_SELLSTOP, orderLotsize(), stopPrice, 10, 0, sTakeProfit);
                  if(sellStop > 0)
                  {
                     previousStopPrice = stopPrice;
                  }
               }
               else if(OrderType() == OP_SELL)
               {
                  double stopPrice = openPrice + (30 * SymbolInfoDouble(symbol, SYMBOL_POINT) * 10);
                  int buyStop = OrderSend(symbol, OP_BUYSTOP, orderLotsize(), stopPrice, 10, 0, bTakeProfit);
                  if(buyStop < 0)
                  {
                     Print("Error: " + string(GetLastError()));
                  }
                  if(buyStop > 0)
                  {
                     previousStopPrice = stopPrice;
                  }
               }
            }
         }
      }
   }
}

Hi developers.

I'm interested in creating an online licensing system for my expert advisors.  This will allow me control the EA remotely. 

When the user places the EA on the chart, it automatically synchronises with the expiry date and account number to know whether the user is a valid user or not.

応答済み

1
開発者 1
評価
(199)
プロジェクト
287
52%
仲裁
0
期限切れ
1
0%
2
開発者 2
評価
(196)
プロジェクト
200
28%
仲裁
0
期限切れ
3
2%
3
開発者 3
評価
(328)
プロジェクト
387
33%
仲裁
2
100% / 0%
期限切れ
0
仕事中
4
開発者 4
評価
(58)
プロジェクト
89
38%
仲裁
26
4% / 77%
期限切れ
39
44%
仕事中
5
開発者 5
評価
(18)
プロジェクト
26
27%
仲裁
0
期限切れ
2
8%
類似した注文
hi. I hv a strategy on tradingview need to convert to MT4/MT5 expert advisor for algo trading. would like to add some tradingview strategy setting to the EA(not included in my tradingview code): recalculate after order is filled, order size: xx% of equity
looking for help to get my ibkr automated, i have strategies already built in composer and have JSON for them, i really just need to he setup and explanation on how to maintain it and add new strategies
Specify your Requirements Specification here point by point. Try to describe your requirements briefly and clearly, so that your potential developer is able to correctly assess its complexity and cost, as well as the required execution time. A bad or too generic description will result in your order being ignored, or you will spend a lot of time negotiating the details with each applicant. Remember: It is better to
I need a AI signal generating bot for forex trading. The bot should operate such that when i put it in a chart it will analyse the market, after several minutes it will display whether the trade is buying or selling. It should display the one minute, five minute,15minute, 30 minute, one hour, 4 hours and daily time frame whether they are buying or selling. If it is buying the arrow should be green and if it is
Using Bollinger Band only. When price closes above upper BB, open Buy. If the length of the candle body that closed above the upper BB is more than Y pips, then do not Buy and remove the EA. Otherwise, continue to open Buy if crosses and close above upper BB and the number of positions is not more than Max No of Positions. The user will choose either Buy or Sell only. When price closes below the lower BB, close all
Hello freelancers here, I need an expert to help me with coding my script which is already working in pinescript, Moreover, i want a system whereby i can sell my trading bot and can give access with a license, I need an expert that can help me with this
Hello freelancers here, I need an expert to help me with coding my script which is already working in pinescript, Moreover, i want a system whereby i can sell my trading bot and can give access with a license, I need an expert that can help me with this, and my budget is $20, Thank you
Hello freelancers here, I need an expert freelancer to help me convert an expert advisor from MT4 to MT5. I have the MT4 source code, As for now i only got $15 for this project i don't have much on me at the moment, So i need someone who can work long terms cause i still have other projects i need him to work on for me
Hi, Do you have an indicator or expert and would like to protect and control it? What you will get protection and control Customer control panel The number of products is unlimited. You can add any number of your own experts and consultations You can give a trial period for your product, for example a week or a month, after which the customer subscribes Monthly, annually, or for life, depending on the customer’s
An EA based on Fibonacci 100 - 750 USD
I am in need of 3 EA based on Fibonacci re-tracement after a high or low is made,each EA will have a hedge trade on it.the hedge trade will be at the 50 percent of the Fibonacci..this will be present on all 3 EA, all three EA will have different levels of re-tracement, while the hedge trade will be a continuation (buy/sell stop), while the re-tracement trades will be (buy/sell limit)This EA must work on timeframe

プロジェクト情報

予算
50+ USD
開発者用
45 USD
締め切り
最高 10 日