Hi, I am new to MQL 4 coding and trying to get up to speed.
This is my first EA and the strategy tester runs successfully but just does not place any trades.
Any help would be greatly appreciated.
You don't check the error code in case you haven't got a ticket number!!
E.g.:
sellticket = OrderSend(Symbol(),OP_SELL,LotSize,Bid,3,0,0,NULL,MagicNumber,0,Red);
if(sellticket<0) Print("no ticket number: "+(string)GetLastError()); // -1 if error!! very simple not checked!!
else int sellmodify=(OrderModify(sellticket,OrderOpenPrice(),sl,tp,0,CLR_NONE));
Hi, I am new to MQL 4 coding and trying to get up to speed.
This is my first EA and the strategy tester runs successfully but just does not place any trades.
Any help would be greatly appreciated.
You have both OnTick() (with empty body) and start() in the same EA. In that case empty OnTick() is executed - your code in the start() is never reached
Anyway : some more code changes made and now it trades. Happy coding :)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi, I am new to MQL 4 coding and trying to get up to speed.
This is my first EA and the strategy tester runs successfully but just does not place any trades.
Any help would be greatly appreciated.
//| Burko's Bollinger EA.mq4 |
//| Copyright 2016, Paul Burkett |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, Paul Burkett"
#property link ""
#property version "1.00"
#property strict
extern int TakeProfit = 100;
extern int StopLoss = 50;
extern double LotSize = 0.10;
extern double EntryDeviation = 1.5;
extern int TrendDirectionBuffer =0; //This is a buffer of how many pips to put between Floor & Roof
extern int PadAmount=5;
extern int CandlesBack=0;
extern double RiskPercent=5;
extern double reward_ratio=2;
extern int MagicNumber=1234;
extern int FloorMA=220;
int FloorMAShift=0;
int FloorMAMethod=1;
int FloorMAAppliedTo=0;
extern int RoofMA=144;
int RoofMAShift=0;
int RoofMAMethod=1;
int RoofMAAppliedTo=0;
int TrendDirection = 0; // 0=Up,1=Down,2=No Direction
double pips;
int longentry;
int shortentry;
int sellticket;
int buyticket;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int Init()
//---
{
double ticksize= MarketInfo(Symbol(),MODE_TICKSIZE);
if(ticksize == 0.00001|| ticksize == 0.001)
pips=ticksize*10;
else pips=ticksize;
return(0);
}
//---
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
}
//+------------------------------------------------------------------+
int start()
{
double CurrentFloor = iMA(NULL,0,FloorMA,FloorMAShift,FloorMAMethod,FloorMAAppliedTo,1);
double CurrentRoof = iMA(NULL,0,RoofMA,RoofMAShift,RoofMAMethod,RoofMAAppliedTo,1);
//+------------------------------------------------------------------+
//| Get Trend Direction |
//+------------------------------------------------------------------+
if (CurrentFloor+TrendDirectionBuffer<CurrentRoof) TrendDirection = 0;
if (CurrentFloor>CurrentRoof+TrendDirectionBuffer) TrendDirection = 1;
else TrendDirection = 2;
//+------------------------------------------------------------------+
//| Long Entry Criteria |
//+------------------------------------------------------------------+
if (TrendDirection == 0)
if (OpenOrdersThisPair(Symbol()) == 0)
CheckForLongBollingerBandTrade ();
//+------------------------------------------------------------------+
//| Short Entry Criteria |
//+------------------------------------------------------------------+
if (TrendDirection == 1)
if (OpenOrdersThisPair(Symbol()) == 0)
CheckForShortBollingerBandTrade ();
//+------------------------------------------------------------------+
//| Long Exit Criteria |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Short Exit Criteria |
//+------------------------------------------------------------------+
return (0);
}
//+------------------------------------------------------------------+
//Checks to see if Bollinger has been broken to the down side |
//and then come back in on current candle. |
//+------------------------------------------------------------------+
int LowEntry()
{
if (Low[1]< iBands(NULL,0,20,2,0,PRICE_OPEN,MODE_LOW,1))
if (Ask > iBands(NULL,0,20,EntryDeviation,0,PRICE_OPEN,MODE_LOW,0))longentry = 1;
return (longentry);
}
//+------------------------------------------------------------------+
//Checks to see if Bollinger has been broken to the up side |
//and then come back in on current candle. |
//+------------------------------------------------------------------+
int HighEntry()
{
if (High[1]> iBands(NULL,0,20,2,0,PRICE_OPEN,MODE_HIGH,0))
if (Bid < iBands(NULL,0,20,EntryDeviation,0,PRICE_OPEN,MODE_HIGH,1))shortentry = 1;
return (shortentry);
}
//+------------------------------------------------------------------+
//checks to see if any orders open on this currency pair. |
//+------------------------------------------------------------------+
int OpenOrdersThisPair(string pair)
{
int total=0;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){continue;}
if(OrderSymbol()==pair) total++;
}
return (total);
}
//+------------------------------------------------------------------+
//order entry function |
//+------------------------------------------------------------------+
void OrderEntry(int direction)
{
if(direction==0)
{
double tp=Ask+TakeProfit*pips;
double sl=Ask-StopLoss*pips;
if(OpenOrdersThisPair(Symbol())==0)
buyticket = OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,0,0,NULL,MagicNumber,0,Green);
if(buyticket>0)int buymodify=(OrderModify(buyticket,OrderOpenPrice(),sl,tp,0,CLR_NONE));
}
if(direction==1)
{
double tp=Bid-TakeProfit*pips;
double sl=Bid+StopLoss*pips;
if(OpenOrdersThisPair(Symbol())==0)
sellticket = OrderSend(Symbol(),OP_SELL,LotSize,Bid,3,0,0,NULL,MagicNumber,0,Red);
if(sellticket>0)int sellmodify=(OrderModify(sellticket,OrderOpenPrice(),sl,tp,0,CLR_NONE));
}
}
//+------------------------------------------------------------------+
//| Check for short Bollinger trade |
//+------------------------------------------------------------------+
void CheckForShortBollingerBandTrade ()
{
double High2DevBand=iBands(NULL,0,20,2,0,PRICE_OPEN,MODE_HIGH,0);
double HighEntryDeviationBand = iBands(NULL,0,20,EntryDeviation,0,PRICE_OPEN,MODE_HIGH,0);
if ((High[0]>High2DevBand) && (Bid < HighEntryDeviationBand))OrderEntry(1);
}
//+------------------------------------------------------------------+
//| Check for long Bollinger trade |
//+------------------------------------------------------------------+
void CheckForLongBollingerBandTrade ()
{
double Low2DevBand=iBands(NULL,0,20,2,0,PRICE_OPEN,MODE_LOW,0);
double LowEntryDeviationBand = iBands(NULL,0,20,EntryDeviation,0,PRICE_OPEN,MODE_LOW,0);
if ((Low[0]< Low2DevBand) && (Ask > LowEntryDeviationBand))OrderEntry(0);
}