CSimpleCandlesStrategy

MQL5 Uzmanlar

İş Gereklilikleri

//+------------------------------------------------------------------+
//| Trading strategy using unidirectional candlesticks               |
//+------------------------------------------------------------------+
class CSimpleCandlesStrategy : public CVirtualStrategy {
protected:
   string            m_symbol;            // Symbol (trading instrument)
   ENUM_TIMEFRAMES   m_timeframe;         // Chart period (timeframe)

   //---  Open signal parameters
   int               m_signalSeqLen;      // Number of unidirectional candles
   int               m_periodATR;         // ATR period

   //---  Position parameters
   double            m_stopLevel;         // Stop Loss (in points or % ATR)
   double            m_takeLevel;         // Take Profit (in points or % ATR)

   //---  Money management parameters
   int               m_maxCountOfOrders;  // Max number of simultaneously open positions

   CSymbolInfo       *m_symbolInfo;       // Object for getting information about the symbol properties

  // ...   

public:
   // Constructor
                     CSimpleCandlesStrategy(string p_params);
   
   virtual string    operator~() override;   // Convert object to string
   virtual void      Tick() override;        // OnTick event handler
};
//+------------------------------------------------------------------+
//| Constructor                                                      |
//+------------------------------------------------------------------+
CSimpleCandlesStrategy::CSimpleCandlesStrategy(string p_params) {
   // Read parameters from the initialization string
   m_params = p_params;
   m_symbol = ReadString(p_params);
   m_timeframe = (ENUM_TIMEFRAMES) ReadLong(p_params);
   m_signalSeqLen = (int) ReadLong(p_params);
   m_periodATR = (int) ReadLong(p_params);
   m_stopLevel = ReadDouble(p_params);
   m_takeLevel = ReadDouble(p_params);
   m_maxCountOfOrders = (int) ReadLong(p_params);

   if(IsValid()) {
      // Request the required number of objects for virtual positions
      CVirtualReceiver::Get(&this, m_orders, m_maxCountOfOrders);

      // Add tracking a new bar on the required timeframe
      IsNewBar(m_symbol, m_timeframe);
      
      // Create an information object for the desired symbol
      m_symbolInfo = CSymbolsMonitor::Instance()[m_symbol];
   }
}
//+------------------------------------------------------------------+
//| Convert an object to a string                                    |
//+------------------------------------------------------------------+
string CSimpleCandlesStrategy::operator~() {
   return StringFormat("%s(%s)", typename(this), m_params);
}
//+------------------------------------------------------------------+
//| "Tick" event handler function                                    |
//+------------------------------------------------------------------+
void CSimpleCandlesStrategy::Tick() override {
// If a new bar has arrived for a given symbol and timeframe
   if(IsNewBar(m_symbol, m_timeframe)) {
// If the number of open positions is less than the allowed number
      if(m_ordersTotal < m_maxCountOfOrders) {
         // Get an open signal
         int signal = SignalForOpen();

         if(signal == 1) {          // If there is a buy signal, then 
            OpenBuy();              // open a BUY position
         } else if(signal == -1) {  // If there is a sell signal, then
            OpenSell();             // open a SELL_STOP position
         }
      }
   }
}
//+------------------------------------------------------------------+
//| Signal for opening pending orders                                |
//+------------------------------------------------------------------+
int CSimpleCandlesStrategy::SignalForOpen() {
// By default, there is no signal
   int signal = 0;

   MqlRates rates[];
// Copy the quote values (candles) to the destination array
   int res = CopyRates(m_symbol, m_timeframe, 1, m_signalSeqLen, rates);

// If the required number of candles has been copied
   if(res == m_signalSeqLen) {
      signal = 1; // buy signal

      // Loop through all the candles
      for(int i = 0; i < m_signalSeqLen; i++) {
         // If at least one upward candle occurs, cancel the signal
         if(rates[i].open < rates[i].close ) {
            signal = 0;
            break;
         }
      }

      if(signal == 0) {
         signal = -1; // otherwise, sell signal

         // Loop through all the candles
         for(int i = 0; i < m_signalSeqLen; i++) {
            // If at least one downward candle occurs, cancel the signal
            if(rates[i].open > rates[i].close ) {
               signal = 0;
               break;
            }
         }
      }

   }

   return signal;
}
//+------------------------------------------------------------------+
//| Open BUY order                                                   |
//+------------------------------------------------------------------+
void CSimpleCandlesStrategy::OpenBuy() {
// Retrieve the necessary symbol and price data
   double point = m_symbolInfo.Point();
   int digits = m_symbolInfo.Digits();

// Opening price
   double price = m_symbolInfo.Ask();

// Update SL and TP levels by calculating ATR
   UpdateLevels();

// StopLoss and TakeProfit levels
   double sl = NormalizeDouble(price - m_sl * point, digits);
   double tp = NormalizeDouble(price + m_tp * point, digits);

   bool res = false;
   for(int i = 0; i < m_maxCountOfOrders; i++) {   // Iterate through all virtual positions
      if(!m_orders[i].IsOpen()) {                  // If we find one that is not open, then open it
         // Open a virtual SELL position
         res = m_orders[i].Open(m_symbol, ORDER_TYPE_BUY, m_fixedLot,
                                0,
                                NormalizeDouble(sl, digits),
                                NormalizeDouble(tp, digits));

         break; // and exit
      }
   }

   if(!res) {
      PrintFormat(__FUNCTION__" | ERROR opening BUY virtual order", 0);
   }
}
//+------------------------------------------------------------------+
//| Update SL and TP levels based on calculated ATR                  |
//+------------------------------------------------------------------+
void CSimpleCandlesStrategy::UpdateLevels() {
// Calculate ATR
   double channelWidth = (m_periodATR > 0 ? ChannelWidth() : 1);

// Update SL and TP levels
   m_sl = m_stopLevel * channelWidth;
   m_tp = m_takeLevel * channelWidth;
}
//+------------------------------------------------------------------+
//| Calculate the ATR value (non-standard implementation)            |
//+------------------------------------------------------------------+
double CSimpleCandlesStrategy::ChannelWidth(ENUM_TIMEFRAMES p_tf = PERIOD_D1) {
   int n = m_periodATR; // Number of bars for calculation
   MqlRates rates[];    // Array for quotes

   // Copy quotes from the daily (default) timeframe
   int res = CopyRates(m_symbol, p_tf, 1, n, rates);

   // If the required amount has been copied
   if(res == n) {
      double tr[];         // Array for price ranges
      ArrayResize(tr, n);  // Change its size
   
      double s = 0;        // Sum for calculating the average
      FOREACH(rates, {
         tr[i] = rates[i].high - rates[i].low; // Remember the bar size
      });
      
      ArraySort(tr); // Sort the sizes

      // Sum the inner two quarters of the bar sizes
      for(int i = n / 4; i < n * 3 / 4; i++) {
         s += tr[i];
      }
      
      // Return the average size in points
      return 2 * s / n / m_symbolInfo.Point();
   }

   return 0.0;
}
// 1. Define a constant with the EA name
#define  __NAME__ "SimpleCandles" + MQLInfoString(MQL_PROGRAM_NAME)

// 2. Connect the required strategy
#include "Strategies/SimpleCandlesStrategy.mqh";

// 3. Connect the general part of the first stage EA from the Advisor library
#include <antekov/Advisor/Experts/Stage1.mqh>

//+------------------------------------------------------------------+
//| 4. Strategy inputs                                               |
//+------------------------------------------------------------------+
sinput string     symbol_              = "GBPUSD";
sinput ENUM_TIMEFRAMES period_         = PERIOD_H1;

input group "===  Opening signal parameters"
input int         signalSeqLen_        = 5;     // Number of unidirectional candles
input int         periodATR_           = 30;    // ATR period

input group "===  Pending order parameters"
input double      stopLevel_           = 3750;  // Stop Loss (in points)
input double      takeLevel_           = 50;    // Take Profit (in points)

input group "===  Money management parameters"
input int         maxCountOfOrders_    = 3;     // Maximum number of simultaneously open orders


//+------------------------------------------------------------------+
//| 5. Strategy initialization string generation function            |
//|    from the inputs                                               |
//+------------------------------------------------------------------+
string GetStrategyParams() {
   return StringFormat(
             "class CSimpleCandlesStrategy(\"%s\",%d,%d,%d,%.3f,%.3f,%d)",
             symbol_, period_,
             signalSeqLen_, periodATR_, stopLevel_, takeLevel_, maxCountOfOrders_
          );
}
//+------------------------------------------------------------------+
2018.01.01 00:00:00   CVirtualFactory::Create | ERROR: Constructor not found for:
2018.01.01 00:00:00   class CSimpleCandlesStrategy("GBPUSD",16385,5,30,2.95,3.92,3)
// Create an object from the initialization string
   static CFactorable* Create(string p_params) {
      // Read the object class name
      string className = CFactorable::ReadClassName(p_params);
      
      // Pointer to the object being created
      CFactorable* object = NULL;

      // Call the corresponding constructor  depending on the class name
      if(className == "CVirtualAdvisor") {
         object = new CVirtualAdvisor(p_params);
      } else if(className == "CVirtualRiskManager") {
         object = new CVirtualRiskManager(p_params);
      } else if(className == "CVirtualStrategyGroup") {
         object = new CVirtualStrategyGroup(p_params);
      } else if(className == "CSimpleVolumesStrategy") {
         object = new CSimpleVolumesStrategy(p_params);
      } else if(className == "CHistoryStrategy") {
         object = new CHistoryStrategy(p_params);
      } 
            
      // If the object is not created or is created in the invalid state, report an error
      if(!object) {
         ...
      }

      return object;
   }
} else if(className == "CSimpleVolumesStrategy") {
   object = new CSimpleVolumesStrategy(p_params);
}
} else if(className == "CSimpleCandlesStrategy") {
   object = new CSimpleCandlesStrategy(p_params);
}
static CFactorable* Create(string p_params)
// Preliminary class definition
class CFactorable;

// Type declaration - pointer to the function for creating objects of the CFactorable class
typedef CFactorable* (*TCreateFunc)(string);

//+------------------------------------------------------------------+
//| Class of creators that bind names and static                     |
//| constructors of CFactorable descendant classes                   |
//+------------------------------------------------------------------+
class CFactorableCreator {
public:
   string            m_className;   // Class name
   TCreateFunc       m_creator;     // Static constructor for the class

   // Creator constructor
                     CFactorableCreator(string p_className, TCreateFunc p_creator);

   // Static array of all created creator objects
   static CFactorableCreator* creators[];
};

// Static array of all created creator objects
CFactorableCreator* CFactorableCreator::creators[];

//+------------------------------------------------------------------+
//| Creator constructor                                              |
//+------------------------------------------------------------------+
CFactorableCreator::CFactorableCreator(string p_className, TCreateFunc p_creator) :
   m_className(p_className),
   m_creator(p_creator) {
// Add the current creator object to the static array
   APPEND(creators, &this);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Class of the EA handling virtual positions (orders)              |
//+------------------------------------------------------------------+
class CVirtualAdvisor : public CAdvisor {

protected:
   //...
                     CVirtualAdvisor(string p_param);    // Private constructor
public:
                     static CFactorable* Create(string p_params) { return new CVirtualAdvisor(p_params) };
                    //...
};

CFactorableCreator CVirtualAdvisorCreator("CVirtualAdvisor", CVirtualAdvisor::Create);
// Declare a static constructor inside the class
#define STATIC_CONSTRUCTOR(C) static CFactorable* Create(string p) { return new C(p); }

// Add a static constructor for the new CFactorable descendant class
// to a special array by creating a global object of the CFactorableCreator class 
#define REGISTER_FACTORABLE_CLASS(C) CFactorableCreator C##Creator(#C, C::Create);
//+------------------------------------------------------------------+
//| Class of the EA handling virtual positions (orders)              |
//+------------------------------------------------------------------+
class CVirtualAdvisor : public CAdvisor {
protected:
   // ...
                     CVirtualAdvisor(string p_param);    // Constructor
public:
                     STATIC_CONSTRUCTOR(CVirtualAdvisor);
                    // ...
};

REGISTER_FACTORABLE_CLASS(CVirtualAdvisor);
//+------------------------------------------------------------------+
//| Trading strategy using unidirectional candlesticks               |
//+------------------------------------------------------------------+
class CSimpleCandlesStrategy : public CVirtualStrategy {
protected:
   string            m_symbol;            // Symbol (trading instrument)
   ENUM_TIMEFRAMES   m_timeframe;         // Chart period (timeframe)

   //---  Open signal parameters
   int               m_signalSeqLen;      // Number of unidirectional candles
   int               m_periodATR;         // ATR period

   //---  Position parameters
   double            m_stopLevel;         // Stop Loss (in points or % ATR)
   double            m_takeLevel;         // Take Profit (in points or % ATR)

   //---  Money management parameters
   int               m_maxCountOfOrders;  // Max number of simultaneously open positions

   CSymbolInfo       *m_symbolInfo;       // Object for getting information about the symbol properties

   double            m_tp;                // Stop Loss in points
   double            m_sl;                // Take Profit in points

   //--- Methods
   int               SignalForOpen();     // Signal to open a position
   void              OpenBuy();           // Open a BUY position
   void              OpenSell();          // Open a SELL position

   double            ChannelWidth(ENUM_TIMEFRAMES p_tf = PERIOD_D1); // Calculate the ATR value
   void              UpdateLevels();      // Update SL and TP levels

   // Private constructor
                     CSimpleCandlesStrategy(string p_params);

public:
   // Static constructor
                     STATIC_CONSTRUCTOR(CSimpleCandlesStrategy);

   virtual string    operator~() override;   // Convert object to string
   virtual void      Tick() override;        // OnTick event handler
};

// Register the CFactorable descendant class
REGISTER_FACTORABLE_CLASS(CSimpleCandlesStrategy);
//+------------------------------------------------------------------+
//| Base class of objects created from a string                      |
//+------------------------------------------------------------------+
class CFactorable {
 // ...

public:
   // ...

   // Create an object from the initialization string
   static CFactorable* Create(string p_params);
};


//+------------------------------------------------------------------+
//| Create an object from the initialization string                  |
//+------------------------------------------------------------------+
CFactorable* CFactorable::Create(string p_params) {
// Pointer to the object being created
   CFactorable* object = NULL;

// Read the object class name
   string className = CFactorable::ReadClassName(p_params);

// Find and call the corresponding constructor depending on the class name
   int i;
   SEARCH(CFactorableCreator::creators, className == CFactorableCreator::creators[i].m_className, i);
   if(i != -1) {
      object = CFactorableCreator::creators[i].m_creator(p_params);
   }

// If the object is not created or is created in the invalid state, report an error
   if(!object) {
      PrintFormat(__FUNCTION__" | ERROR: Constructor not found for:\n%s",
                  p_params);
   } else if(!object.IsValid()) {
      PrintFormat(__FUNCTION__
                  " | ERROR: Created object is invalid for:\n%s",
                  p_params);
      delete object; // Remove the invalid object
      object = NULL;
   }

   return object;
}

Yanıtlandı

1
Geliştirici 1
Derecelendirme
(1)
Projeler
1
0%
Arabuluculuk
0
Süresi dolmuş
0
Serbest
2
Geliştirici 2
Derecelendirme
Projeler
0
0%
Arabuluculuk
0
Süresi dolmuş
0
Serbest
3
Geliştirici 3
Derecelendirme
(255)
Projeler
262
30%
Arabuluculuk
0
Süresi dolmuş
3
1%
Serbest
Yayınlandı: 2 kod
4
Geliştirici 4
Derecelendirme
(1)
Projeler
0
0%
Arabuluculuk
5
0% / 80%
Süresi dolmuş
0
Serbest
5
Geliştirici 5
Derecelendirme
Projeler
0
0%
Arabuluculuk
0
Süresi dolmuş
0
Serbest
6
Geliştirici 6
Derecelendirme
(5)
Projeler
6
0%
Arabuluculuk
1
0% / 100%
Süresi dolmuş
0
Serbest
7
Geliştirici 7
Derecelendirme
(3)
Projeler
3
0%
Arabuluculuk
1
0% / 100%
Süresi dolmuş
0
Çalışıyor
8
Geliştirici 8
Derecelendirme
(144)
Projeler
186
41%
Arabuluculuk
24
58% / 21%
Süresi dolmuş
13
7%
Serbest
9
Geliştirici 9
Derecelendirme
(509)
Projeler
977
74%
Arabuluculuk
27
19% / 67%
Süresi dolmuş
101
10%
Serbest
Yayınlandı: 1 makale, 6 kod
10
Geliştirici 10
Derecelendirme
(1)
Projeler
0
0%
Arabuluculuk
1
0% / 100%
Süresi dolmuş
0
Serbest
11
Geliştirici 11
Derecelendirme
(64)
Projeler
144
46%
Arabuluculuk
19
42% / 16%
Süresi dolmuş
32
22%
Serbest
12
Geliştirici 12
Derecelendirme
(50)
Projeler
74
27%
Arabuluculuk
12
58% / 17%
Süresi dolmuş
14
19%
Serbest
Benzer siparişler
Need trading robot 50 - 70 USD
I need a robot for trading gold and currencies . I need to use it with metatrader 4 and 5 . My budget is not high . Max . 70 USD. I need to be able to start and stop it at any time without restrictions
am looking for an experienced MQL5 developer to build a high-frequency trading Expert Advisor (EA) for XAUUSD (Gold) on M1 and M5 timeframes . The EA must include advanced execution logic, dynamic pending orders, risk management, and news/session filters. Clean, efficient, and well-documented code is required. Strategy type: Scalping (fast trades, quick profit). Very fast execution logic (optimized for speed). Goal
Title: MT5 EA Needed – Prop‑Firm Compliance Tool (SL/TP at Entry, 60‑Second Hold, Daily Profit Cap, 0.5% XAUUSD Risk) Description: I need an MT5 Expert Advisor that enforces prop‑firm compliance rules for Instant Funding accounts. The EA must NOT trade automatically — it should only monitor and control my manual XAUUSD trading. I trade all sessions, so there should be no time restrictions. MY TRADING STYLE (Important
​1. Project Overview ​ Asset: XAUUSD (Gold) ​ Timeframe: M1 (1-Minute) for execution; M5/M15 for trend filtering. ​ Objective: Execute high-frequency scalps during peak liquidity (London/NY overlap) to capture 10–30 pip movements with high precision. ​ Core Logic: The "Poverty Bot" strategy relies on Mean Reversion combined with Momentum Burst (Price Action + RSI/EMA filters). ​2. Strategy Logic (The "Poverty"
I need any highly profitable robot which can trade small account like 50-100USD and any currency pair(s) The robot should avoid trading around news time and have good risk management. It should use any strategy which is profitable and not those unacceptable by brokers. Demo versions will be required before selection
Hi, I hope you doing Greate, Let me share details , so the original EA already working but you can check and verify everything fine.First you verify that all original EA features are working correctly then add a user dashboard showing the number of detected zones, buy sell both none status, and an on off button. also ensure mitigated zones disappear properly and that trades follow the zone rules, and integrate the
I need a high-speed Expert Advisor (EA) for MT5 designed specifically for XAUUSD (Gold) scalping. The bot should focus on fast entries and quick profits with high efficiency. Main requirements: 1. Symbol: XAUUSD (Gold only). 2. Platform: MetaTrader 5. 3. Strategy type: Scalping (fast trades, quick profit). 4. The bot should open trades frequently based on fast market movements. 5. Small Take Profit (quick profit
Gold_m1_ob_bot. 30+ USD
import MetaTrader5 as mt5 import pandas as pd import time from datetime import datetime # ================== CONFIG ================== SYMBOL = "XAUUSD" TIMEFRAME = mt5.TIMEFRAME_M1 LOT = 0.01 MAX_OBS = 12 # keeps signals frequent ATR_PERIOD = 14 IMPULSE_FACTOR = 1.5 # strong candle = impulse SESSION_START = 8 # GMT (London open) SESSION_END = 20 # GMT (NY close) MAX_SPREAD = 30 #
I have existing compiled indicator and script files (EX4) and would like to have them recreated in both MQL4. ⚠️ Important: This project is NOT for decompiling or reverse engineering. Instead, the goal is to: Analyze the behavior and output of the provided files Recreate equivalent functionality from scratch Deliverables: 1 MQL4 indicator source code (.mq4) 1 MQL4 script source code (.mq4) Requirements: The recreated
I need a good programmer to help convert an existing indicator to a trading EA that can work on both MT4 and MT5. The expected features on the EA is as follows: Max Spread: Magic Number: Take Profit: Stop Loss: Trailing Stop: Fixed Lot Size: Money Management: false/true Min Lot Size: Max Lot Size: Risk to Trade %: Daily Profit Target %: Add news filter. Get my jobs with source code

Proje bilgisi

Bütçe
30+ USD
Son teslim tarihi
from 30 gün