I am having a problem with including a mqh file.
the mqh file itself has been included and has no error. The errors come when i try to call upon classes from the mqh file. This code is from the mt4 book by Andrew R. Young, At page 148 the end of a simple expert advisor revised for those who have used the book to learn mql4.
you say you have a problem including the file but your comment in the code says the include works fine.... does it include when compiled or not?
In your code you reference object DevlinTrade but where have you created it?
Without more code or proper details of the errors it's a guessing game..
I am having a problem with including a mqh file.
the mqh file itself has been included and has no error. The errors come when i try to call upon classes from the mqh file. This code is from the mt4 book by Andrew R. Young, At page 148 the end of a simple expert advisor revised for those who have used the book to learn mql4.
Have you tried adding the .mqh extension in the file name i.e.
#include <DevlinTrade.mqh>
as opposed to
#include <DevlinTrade>
Also, have you included the relevant global variables to the MQH file as well? I have an external MQH document which contains all the global variables which every source file (EA's, and other MQH files) points to. It may not be getting to the global variables to it can't do the function you're asking it to.
Have you tried adding the .mqh extension in the file name i.e.
as opposed to
Also, have you included the relevant global variables to the MQH file as well? I have an external MQH document which contains all the global variables which every source file (EA's, and other MQH files) points to. It may not be getting to the global variables to it can't do the function you're asking it to.
Sorry the .mqh is in the include file just forgot add it to the comment.
yes the global variables have been assigned.
I also have an error stating that DevlinTrade is an undeclared identifier when trying to call from the mqh file.
//+------------------------------------------------------------------+
//| Devlin_Simple_EA_With_Functions.mq4 |
//| Craig Devlin |
//| |
//+------------------------------------------------------------------+
#property copyright "Craig Devlin"
#property link ""
#property version "1.00"
#property strict
// include and objects
#include <DevlinTrade.mqh>
CTrade Trade;
CCount Count;
// Input variables
input int MagicNumber = 102;
input int Slippage = 10;
input double LotSize = 0.1;
input int StopLoss = 0;
input int TakeProfit = 0;
input int MaPeriod = 5;
input ENUM_MA_METHOD MaMethod = MODE_EMA;
input ENUM_APPLIED_PRICE MaPrice = PRICE_CLOSE;
// Global variables
int gBuyTicket, gSellTicket;
// OnInit() event handler
void OnInit()
{
// Set magic number
DevlinTrade.SetMagicNumber(MagicNumber);
DevlinTrade.SetSlippage(Slippage);
return(INIT_SUCCEEDED);
}
// OnTick() event handler
void OnTick()
{
// Moving average and close price from last bar
double ma = iMA(_Symbol, _Period, MaPeriod, 0, MaMethod, MaPrice, 1);
double close = Close[1];
// Buy order condition
if(close > ma && Count.Buy() == 0 && gBuyTicket == 0)
{
// Close sell orders
DevlinTrade.CloseAllSellOrders();
// Open buy order
gBuyTicket = DevlinTrade.OpenBuyOrder(_Symbol, LotSize);
gSellTicket = 0;
// Add stoploss and take profit
ModifyStopByPoints(gBuyTicket, StopLoss, TakeProfit);
}
// Sell order condition
if(close < ma && Count.Sell() == 0 && gSellTicket == 0)
{
// Close buy orders
DevlinTrade.CloseAllBuyOrders();
// Open sell order
gSellTicket = DevlinTrade.OpenSellOrder(_Symbol, LotSize);
gBuyTicket = 0;
// Add stoploss and take profit to the order
ModifyStopByPoints(gSellTicket, StopLoss, TakeProfit);
}
}
you say you have a problem including the file but your comment in the code says the include works fine.... does it include when compiled or not?
In your code you reference object DevlinTrade but where have you created it?
Without more code or proper details of the errors it's a guessing game..
}
use the code button </> to post code it is unreadable otherwise....
your problem is still the same as I said before, you are not declaring the class instance Devlintrade
use the code button </> to post code it is unreadable otherwise....
your problem is still the same as I said before, you are not declaring the class instance DevlinTrade
You are declaring CTrade Trade then using DevlinTrade instead...
Paul you are an absolute legend down to 1 error I will tackle this one on my own. much appreciated mate thanks.
here you go
it is good practice to have the include file name and the class name to be obviously linked for ease of debugging especially if the include only contains a single class
#include <DevlinTrade.mqh> CTrade DevlinTrade; int OnInit() { int MagicNumber = 12345; int Slippage = 1; DevlinTrade.SetMagicNumber(MagicNumber); // none of this works. DevlinTrade.SetSlippage(Slippage); return(INIT_SUCCEEDED); }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am having a problem with including a mqh file.
the mqh file itself has been included and has no error. The errors come when i try to call upon classes from the mqh file. This code is from the mt4 book by Andrew R. Young, At page 148 the end of a simple expert advisor revised for those who have used the book to learn mql4.