You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Required lines in yellow
Yellow lines required
Now tell me how to make a profit here... Or is it to build a game?
Hi everyone, can you please help me find an error in the code of the EA, I think I have looked through it all, it seems to be all written correctly in the code, but the program does not trade correctly for some reason! The idea is this: The advisor has to look for two long candles of the same direction (the length between the candles is adjustable in the advisor, ie between the two minimum or maximum candles, depending on the direction), if the price in the opposite direction breaks the minimum or maximum of the last candle, a deal should open (Example picture situations on the chart attached to the file). The adviser should open deals at every such suitable situation, but for some reason it opens deals only on the trading windows between days. Here is the situation, who is not difficult from programmers, please help, fix the error. EA code see below as well as in attached file.
Hi everyone, can you please help me find an error in the code of the EA, I think I have looked through it all, it seems to be all written correctly in the code, but the program does not trade correctly for some reason! The idea is this: The advisor has to look for two long candles of the same direction (the length between the candles is adjustable in the advisor, ie between the two minimum or maximum candles, depending on the direction), if the price in the opposite direction breaks the minimum or maximum of the last candle, a deal should open (Example picture situations on the chart attached to the file). The adviser should open deals at every such suitable situation, but for some reason it opens deals only on the trading windows between days. Here is the situation, who is not difficult from programmers, please help, fix the error. See the EA code below as well as in the attached file.
It is better to first write the part of the EA that would mark on the chart the candles found, so that everything becomes clear. And the following lines are unnecessary in your case:
Now tell me how to make a profit here... Or do you need it to build a game?
There is no way to get a profit yet. There is an algorithm for calculation of two probable price targets, along the trend, by five major points, but it is calculated on a special server with a paid subscription. I want to calculate targets myself, the work on the algorithm is not over yet.
What will your program look like in MQL4?
If you have a good strategy and are willing to share it, i can write an EA. i invite you to discuss it either publicly or in private messages.
Anton, help me out, I've added trailing stop function to the EA, I've tested it and it shows two errors. - I've got my head bashed, I cannot figure out how to fix them to get an owl. However trades are closed according to old strategy after the price has touched the upper limit of the channel and the lower one, respectively. I guess something has to be changed here as well. - Call back to the dnr army guys.
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
//---------------------------------------------------------
extern double Lots = 0.01;
extern int TakeProfit = 600;
extern int StopLoss = 25;
extern int Magic = 0001;
extern int Slippage = 3;
extern int TralType = 0; // 0-SAR, 1-ATR, 2-HMA.
extern double SAR_Step = 0.02;
extern double SAR_Max = 0.2;
extern int ATR_Period = 14;
extern double ATR_K = 2.0;
extern inttern HMA_Period = 16;
extern intern HMA_Method = 3;
extern inttern HMA_Shift = 0;
datetime LBT;
//---------------------------------------------------------
extern string TMA = "TMA indicator parameters";
extern string TimeFrame = "current time frame";
extern int HalfLength = 56;
extern int Price = "PRICE_CLOSE;
extern double ATRMultiplier = 2.0;
extern inttern ATRPeriod = 100;
extern bool Interpolate = true;
//---------------------------------------------------------
double PriceHigh, PriceLow, SL, TP;
int ticket;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
if (Digits == 3 || Digits == 5)
{
TakeProfit *= 10;
StopLoss *= 10;
Slippage *= 10;
}
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
PriceHigh = iCustom(NULL, 0, "TMA_Fair", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 1, 0);
PriceLow = iCustom(NULL, 0, "TMA_Fair", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 2, 0);
if(CountSell() == 0 && Bid >= PriceHigh)
{
ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, "TMA robot", Magic, 0, Red);
if (ticket > 0)
{
SL = NormalizeDouble(Bid + StopLoss*Point, Digits);
TP = NormalizeDouble(Bid - TakeProfit*Point, Digits);
if (OrderSelect(ticket, SELECT_BY_TICKET))
if (!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0))
Print(" Ordermodification error!)
}
}
if (CountBuy() == 0 && Ask <= PriceLow)
{
ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, "TMA robot", Magic, 0, Blue);
if (ticket > 0)
{
TP = NormalizeDouble(Ask + TakeProfit*Point, Digits);
SL = NormalizeDouble(Ask - StopLoss*Point, Digits);
if (OrderSelect(ticket, SELECT_BY_TICKET))
if(!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0))
Print("Error modifying the buy order!)
} else Print("Error opening the Buy order");
}
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//--------
//--------
return (0);
}
//+------------------------------------------------------------------+
//| expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
PriceHigh = iCustom(NULL, 0, "TMA_Fair", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 1, 0);
PriceLow = iCustom(NULL, 0, "TMA_Fair", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 2, 0);
if(CountSell() == 0 && Bid >= PriceHigh)
{
ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, "TMA robot", Magic, 0, Red);
if (ticket > 0)
{
SL = NormalizeDouble(Bid + StopLoss*Point, Digits);
TP = NormalizeDouble(Bid - TakeProfit*Point, Digits);
if (OrderSelect(ticket, SELECT_BY_TICKET))
if (!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0))
Print("Error modifying the sell order!)
} else Print("Error opening the sell order!)
}
if (CountBuy() == 0 && Ask <= PriceLow)
{
ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, "TMA robot", Magic, 0, Blue);
if (ticket > 0)
{
TP = NormalizeDouble(Ask + TakeProfit*Point, Digits);
SL = NormalizeDouble(Ask - StopLoss*Point, Digits);
if (OrderSelect(ticket, SELECT_BY_TICKET))
if(!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0))
Print("Error modifying the buy order!)
} else Print("Error opening the Buy order");
}
if (Ask <= PriceLow && CountSell() > 0)
{
for (int i = OrdersTotal() -1; i>0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderMagicNumber() == Magic && OrderType() == OP_SELL)
if (!OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, Black))
Print("Sell order close error!)
}
}
}
if (Bid >= PriceHigh && CountBuy() > 0)
{
for (int i = OrdersTotal() -1; i>0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderMagicNumber() == Magic && OrderType() == OP_BUY)
if(!OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, Black))
Print("OrderClose Buy error!)
}
}
}
}
//+------------------------------------------------------------------+
int CountSell()
{
int count = 0;
for (int trade = OrdersTotal()-1; trade>=0; trade--)
{
if(OrderSelect(trade, SELECT_BY_POS, MODE_TRADES))
{
if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_SELL)
count++;
}
}
return(count);
}//+------------------------------------------------------------------+
int CountBuy()
{
int count = 0;
for (int trade = OrdersTotal()-1; trade>=0; trade--)
{
if(OrderSelect(trade, SELECT_BY_POS, MODE_TRADES))
{
if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_BUY)
count++;
}
}
return(count);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//+-------
//+-------
return (0)
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int Start()
{
//-----
bool error = fals;
if (LBT!=Time[0]) {
if (OrdersTotal()!=0) {
for (int i=0; i<OrdersTotal(); i++) {
if (OrderSelect(i,SELECT_BY_POS)&&OrderSymbol()==Symbol()&&OrderType()<2) {
double SL = OrderStopLoss();
if OrderType()==0) {
switch (TralType) {
case 0: SL = iSAR(NULL,0,SAR_Step,SAR_Max,0);
break;
case 1: SL = High[1] - iATR(NULL,0,ATR,Period,1)*ATR_K;
break;
case 2: SL = iCustom(NULL,0, "VininI_HMAsound&",HMA_Period,HMA_Method,3,HMA_Shift, fals,fals,",1,0,0);
break;
}
if (SL<OrderStopLoss())
SL = OrderStopLoss();
}
if (OrderType()==1) {
switch (TralType) {
case 0: SL = iSAR(NULL,0,SAR_Step,SAR_Max,0);
break;
case 1: SL = Low[1] + iATR(NULL,0,ATR,Period,1)*ATR_K;
break;
case 2: SL = iCustom(NULL,0, "VininI_HMAsound&",HMA_Period,HMA_Method,3,HMA_Shift, fals,fals,",1,0,0);
break;
}
if (SL>OrderStopLoss())
SL = OrderStopLoss();
}
if (SL!=OrderStopLoss()) {
if(!OrderModify(OrderTicket(),OrderOpenPrice(),SL,OrderTakeProfit(),0))
error = true;
}
}
}
}
if (!error)
LBT = Time[0];
}
return (0);
}
//+------------------------------------------------------------------+
To gain experience in this area, I will write 25 EAs for free for your interesting ideas and strategies
Only 19 EAs left
I haveadded trailing stop function to EA and I have commented it and it has two errors. - I may have some errors, but I do not know how to fix them. However trades are closed according to old strategy after the price has touched the upper limit of the channel and the lower one, respectively. I guess something has to be changed here as well. - Call back to the dnr army guys.
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
//---------------------------------------------------------
extern double Lots = 0.01;
extern int TakeProfit = 600;
extern int StopLoss = 25;
extern int Magic = 0001;
extern int Slippage = 3;
extern int TralType = 0; // 0-SAR, 1-ATR, 2-HMA.
extern double SAR_Step = 0.02;
extern double SAR_Max = 0.2;
extern int ATR_Period = 14;
extern double ATR_K = 2.0;
extern inttern HMA_Period = 16;
extern intern HMA_Method = 3;
extern inttern HMA_Shift = 0;
datetime LBT;
//---------------------------------------------------------
extern string TMA = "TMA indicator parameters";
extern string TimeFrame = "current time frame";
extern int HalfLength = 56;
extern int Price = "PRICE_CLOSE;
extern double ATRMultiplier = 2.0;
extern inttern ATRPeriod = 100;
extern bool Interpolate = true;
//---------------------------------------------------------
double PriceHigh, PriceLow, SL, TP;
int ticket;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
if (Digits == 3 || Digits == 5)
{
TakeProfit *= 10;
StopLoss *= 10;
Slippage *= 10;
}
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
PriceHigh = iCustom(NULL, 0, "TMA_Fair", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 1, 0);
PriceLow = iCustom(NULL, 0, "TMA_Fair", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 2, 0);
if(CountSell() == 0 && Bid >= PriceHigh)
{
ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, "TMA robot", Magic, 0, Red);
if (ticket > 0)
{
SL = NormalizeDouble(Bid + StopLoss*Point, Digits);
TP = NormalizeDouble(Bid - TakeProfit*Point, Digits);
if (OrderSelect(ticket, SELECT_BY_TICKET))
if (!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0))
Print(" Ordermodification error!)
}
}
if (CountBuy() == 0 && Ask <= PriceLow)
{
ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, "TMA robot", Magic, 0, Blue);
if (ticket > 0)
{
TP = NormalizeDouble(Ask + TakeProfit*Point, Digits);
SL = NormalizeDouble(Ask - StopLoss*Point, Digits);
if (OrderSelect(ticket, SELECT_BY_TICKET))
if(!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0))
Print("Error modifying the buy order!)
} else Print("Error opening the Buy order");
}
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//--------
//--------
return (0);
}
//+------------------------------------------------------------------+
//| expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
PriceHigh = iCustom(NULL, 0, "TMA_Fair", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 1, 0);
PriceLow = iCustom(NULL, 0, "TMA_Fair", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 2, 0);
if(CountSell() == 0 && Bid >= PriceHigh)
{
ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, "TMA robot", Magic, 0, Red);
if (ticket > 0)
{
SL = NormalizeDouble(Bid + StopLoss*Point, Digits);
TP = NormalizeDouble(Bid - TakeProfit*Point, Digits);
if (OrderSelect(ticket, SELECT_BY_TICKET))
if (!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0))
Print("Error modifying the sell order!)
} else Print("Error opening the sell order!)
}
if (CountBuy() == 0 && Ask <= PriceLow)
{
ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, "TMA robot", Magic, 0, Blue);
if (ticket > 0)
{
TP = NormalizeDouble(Ask + TakeProfit*Point, Digits);
SL = NormalizeDouble(Ask - StopLoss*Point, Digits);
if (OrderSelect(ticket, SELECT_BY_TICKET))
if(!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0))
Print("Error modifying the buy order!)
} else Print("Error opening the Buy order");
}
if (Ask <= PriceLow && CountSell() > 0)
{
for (int i = OrdersTotal() -1; i>0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderMagicNumber() == Magic && OrderType() == OP_SELL)
if (!OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, Black))
Print("Sell order close error!)
}
}
}
if (Bid >= PriceHigh && CountBuy() > 0)
{
for (int i = OrdersTotal() -1; i>0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderMagicNumber() == Magic && OrderType() == OP_BUY)
if(!OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, Black))
Print("OrderClose Buy error!)
}
}
}
}
//+------------------------------------------------------------------+
int CountSell()
{
int count = 0;
for (int trade = OrdersTotal()-1; trade>=0; trade--)
{
if(OrderSelect(trade, SELECT_BY_POS, MODE_TRADES))
{
if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_SELL)
count++;
}
}
return(count);
}//+------------------------------------------------------------------+
int CountBuy()
{
int count = 0;
for (int trade = OrdersTotal()-1; trade>=0; trade--)
{
if(OrderSelect(trade, SELECT_BY_POS, MODE_TRADES))
{
if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_BUY)
count++;
}
}
return(count);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//+-------
//+-------
return (0)
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int Start()
{
//-----
bool error = fals;
if (LBT!=Time[0]) {
if (OrdersTotal()!=0) {
for (int i=0; i<OrdersTotal(); i++) {
if (OrderSelect(i,SELECT_BY_POS)&&OrderSymbol()==Symbol()&&OrderType()<2) {
double SL = OrderStopLoss();
if OrderType()==0) {
switch (TralType) {
case 0: SL = iSAR(NULL,0,SAR_Step,SAR_Max,0);
break;
case 1: SL = High[1] - iATR(NULL,0,ATR,Period,1)*ATR_K;
break;
case 2: SL = iCustom(NULL,0, "VininI_HMAsound&",HMA_Period,HMA_Method,3,HMA_Shift, fals,fals,",1,0,0);
break;
}
if (SL<OrderStopLoss())
SL = OrderStopLoss();
}
if (OrderType()==1) {
switch (TralType) {
case 0: SL = iSAR(NULL,0,SAR_Step,SAR_Max,0);
break;
case 1: SL = Low[1] + iATR(NULL,0,ATR,Period,1)*ATR_K;
break;
case 2: SL = iCustom(NULL,0, "VininI_HMAsound&",HMA_Period,HMA_Method,3,HMA_Shift, fals,fals,",1,0,0);
break;
}
if (SL>OrderStopLoss())
SL = OrderStopLoss();
}
if (SL!=OrderStopLoss()) {
if(!OrderModify(OrderTicket(),OrderOpenPrice(),SL,OrderTakeProfit(),0))
error = true;
}
}
}
}
if (!error)
LBT = Time[0];
}
return (0);
}
//+------------------------------------------------------------------+
I'veadded trailing stop function to the Expert Advisor, and I've compiled it and got two errors. - I have lost my mind, I cannot figure out how to fix them to get an owl. However trades are closed according to old strategy after the price has touched the upper limit of the channel and the lower one, respectively. I guess something has to be changed here as well. - Give it back to the guys from the army of the DPR.
You shouldn't spam.
I apologise if I did something wrong. I still don't understand how I spammed... I think I addressed two messages to two comrades. Or is that not allowed? - My bad.