why can'ti place orders.....please coders
New code:
//+------------------------------------------------------------------+ //| Strategy1.mq5 | //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" //--- #include <Trade\Trade.mqh> //--- CTrade m_trade; // object of CTrade class //--- input parameters input double InpVolume = 1.0; // Lot size //--- //+------------------------------------------------------------------+ //|Class and function definitions | //+------------------------------------------------------------------+ class CMyTrade : public CObject { public: CMyTrade(); ~CMyTrade(); //--- check BUY Signal and open BUY position void BuySignal(void); //--- check SELL Signal and open SELL position void SellSignal(void); }; //+------------------------------------------------------------------+ //| Constructor | //+------------------------------------------------------------------+ CMyTrade::CMyTrade() { } //+------------------------------------------------------------------+ //| Dectructor | //+------------------------------------------------------------------+ CMyTrade::~CMyTrade() { } //+------------------------------------------------------------------+ //| Buy Signal | //+------------------------------------------------------------------+ void CMyTrade::BuySignal(void) { //--- position and signal details if(PositionSelect(Symbol())) return; //--- array to hold the bars data MqlRates bar[]; CopyRates(Symbol(),Period(),0,7,bar); //--- check buy signal bool buy_signal=((bar[3].open < bar[2].open && bar[3].close < bar[2].close)&& (bar[2].open < bar[1].open && bar[2].close < bar[1].close)&& (bar[1].open < bar[0].open && bar[1].close < bar[0].close)); if(buy_signal) { double price = SymbolInfoDouble(Symbol(),SYMBOL_ASK); double sl = bar[2].low; double tp = price + ((price - sl) * 3); m_trade.Buy(InpVolume,Symbol(),price,sl,tp,"Long"); } } //+------------------------------------------------------------------+ //| Sell Signal | //+------------------------------------------------------------------+ void CMyTrade::SellSignal(void) { //--- position and signal details if(PositionSelect(Symbol())) return; //--- array to hold the bars data MqlRates bar[]; CopyRates(Symbol(),Period(),0,7,bar); //--- check sell signal bool sell_signal=((bar[3].open > bar[2].open && bar[3].close > bar[2].close)&& (bar[2].open > bar[1].open && bar[2].close > bar[1].close)&& (bar[1].open > bar[0].open && bar[1].close > bar[0].close)); if(sell_signal) { double price = SymbolInfoDouble(Symbol(),SYMBOL_BID); double sl = bar[2].high; double tp = price + ((sl - price) * 3.0); m_trade.Sell(InpVolume,Symbol(),price,sl,tp,"Short"); } } //--- CMyTrade m_mytrade; // object of CMyTrade class //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- m_mytrade.BuySignal(); m_mytrade.SellSignal(); } //+------------------------------------------------------------------+
i appreciate man...but the strategy still does not place trades
i appreciate man...but the strategy still does not place trades
The code that I have provided is working.
He definitely opens up BUY positions.
And as for the SELL positions, you need to slightly change the signal parameter.
And in general - learn to use a strategy tester before saying: "Something does not work for me" :)
Add: SELL positions Open, but very rarely.
- www.mql5.com
One more note: you get OHLC data into the bar array, but you completely forget to expand the array
ArraySetAsSeries(bar,true); Version 1.001:
//+------------------------------------------------------------------+ //| Strategy1.mq5 | //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.001" //--- #include <Trade\Trade.mqh> //--- CTrade m_trade; // object of CTrade class //--- input parameters input double InpVolume = 1.0; // Lot size //--- //+------------------------------------------------------------------+ //|Class and function definitions | //+------------------------------------------------------------------+ class CMyTrade : public CObject { public: CMyTrade(); ~CMyTrade(); //--- check BUY Signal and open BUY position void BuySignal(void); //--- check SELL Signal and open SELL position void SellSignal(void); }; //+------------------------------------------------------------------+ //| Constructor | //+------------------------------------------------------------------+ CMyTrade::CMyTrade() { } //+------------------------------------------------------------------+ //| Dectructor | //+------------------------------------------------------------------+ CMyTrade::~CMyTrade() { } //+------------------------------------------------------------------+ //| Buy Signal | //+------------------------------------------------------------------+ void CMyTrade::BuySignal(void) { //--- position and signal details if(PositionSelect(Symbol())) return; //--- array to hold the bars data MqlRates bar[]; ArraySetAsSeries(bar,true); CopyRates(Symbol(),Period(),0,7,bar); //--- check buy signal bool buy_signal=((bar[3].open < bar[2].open && bar[3].close < bar[2].close)&& (bar[2].open < bar[1].open && bar[2].close < bar[1].close)&& (bar[1].open < bar[0].open && bar[1].close < bar[0].close)); if(buy_signal) { double price = SymbolInfoDouble(Symbol(),SYMBOL_ASK); double sl = bar[2].low; double tp = price + ((price - sl) * 3); m_trade.Buy(InpVolume,Symbol(),price,sl,tp,"Long"); } } //+------------------------------------------------------------------+ //| Sell Signal | //+------------------------------------------------------------------+ void CMyTrade::SellSignal(void) { //--- position and signal details if(PositionSelect(Symbol())) return; //--- array to hold the bars data MqlRates bar[]; ArraySetAsSeries(bar,true); CopyRates(Symbol(),Period(),0,7,bar); //--- check sell signal bool sell_signal=((bar[3].open > bar[2].open && bar[3].close > bar[2].close)&& (bar[2].open > bar[1].open && bar[2].close > bar[1].close)&& (bar[1].open > bar[0].open && bar[1].close > bar[0].close)); if(sell_signal) { double price = SymbolInfoDouble(Symbol(),SYMBOL_BID); double sl = bar[2].high; double tp = price + ((sl - price) * 3.0); m_trade.Sell(InpVolume,Symbol(),price,sl,tp,"Short"); } } //--- CMyTrade m_mytrade; // object of CMyTrade class //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- m_mytrade.BuySignal(); m_mytrade.SellSignal(); } //+------------------------------------------------------------------+
I run this code from the MetaEditor.
My settings
My actions:

You have been warned about duplicating topics. You can expect a ban if you continue to do so.

the strategy codes without compilation errors but won't place orders in live or strategy tester... pls someone help