• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 11:26am
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 11:26am
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

Compiler problem or code problem ? 3 replies

problem, problem, is it MT4 platform or EA, Please help................ 1 reply

Oanda Spread Problem 15 replies

MT4 Connection Problem?? HELP!! 7 replies

Charting problem 1 reply

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
  • 10
Attachments: Problem With EA
Exit Attachments
Tags: Problem With EA
Cancel

Problem With EA

  • Last Post
  •  
  • Page 1 2
  • Page 1 2
  •  
  • Post #1
  • Quote
  • First Post: Edited 9:49am Jun 18, 2016 4:56am | Edited 9:49am
  •  mdswamp
  • | Joined Sep 2013 | Status: Member | 55 Posts
Hi guys, I've made an entering & exiting Indicator and now I want to make them work in an EA.. I used moving average EA codes to make my own EA; but it does not seem to work. I have one Buffer in Exit indicator & three Buffers in Enter indicator... I don't have that knowledge to understand all the coding, but it seems that the EA doesn't use indicators... so I'm here. i know its too much to ask, but I would greatly appreciate it if somebody help me with this. Thanks..
Attached File(s)
File Type: mq4 EA-MEE.mq4   8 KB | 160 downloads
  • Post #2
  • Quote
  • Jun 18, 2016 10:54am Jun 18, 2016 10:54am
  •  j11
  • | Joined Jun 2016 | Status: Member | 95 Posts
From a quick look ...

on line 106/7/8 you set CEB[2] to a value

then...

on line 110 you only ask to open an order if && CEB[2]==EMPTY_VALUE
cannot be empty as I understand it as just set to value.

(Don't know what "Currencies_Enter Origin" indi is ??)

J.
If it was easy then I would do it !!
 
 
  • Post #3
  • Quote
  • Jun 18, 2016 5:47pm Jun 18, 2016 5:47pm
  •  mdswamp
  • | Joined Sep 2013 | Status: Member | 55 Posts
Hi j11... sorry, I should explain this before, my indicator (Currencies_Enter Origin) show the wrong signals. when color of Heiken Ashi changes & the indicator show nothing under the first changed color candle, I should buy/sell... I should fix this lunatic method, but I needed this method to see wrong signals easily..
I have another buffer in Currencies_Enter Origin indicator except (No buy/No sell) buffers and it sometimes happens under the second changed color heiken ashi candle, and it shows me that i should stay in buy/sell signal longer..
now I've written my conditions in this EA, but it doesn't work...
Attached Image (click to enlarge)
Click to Enlarge

Name: Untitled.png
Size: 23 KB
 
 
  • Post #4
  • Quote
  • Jun 19, 2016 7:04am Jun 19, 2016 7:04am
  •  j11
  • | Joined Jun 2016 | Status: Member | 95 Posts
With the info provided it is not possible to help further.
If you provide the mq4 files that you are working with maybe somebody could help.

Sorry no time now.

J.
If it was easy then I would do it !!
 
 
  • Post #5
  • Quote
  • Jun 19, 2016 8:17am Jun 19, 2016 8:17am
  •  mdswamp
  • | Joined Sep 2013 | Status: Member | 55 Posts
Ok, Suppose we have an indicator names "Currencies_Enter Origin" that shows the wrong signals..
Attached File(s)
File Type: mq4 Currencies_Enter Origin.mq4   4 KB | 131 downloads
 
 
  • Post #6
  • Quote
  • Jun 19, 2016 4:40pm Jun 19, 2016 4:40pm
  •  mdswamp
  • | Joined Sep 2013 | Status: Member | 55 Posts
...
 
 
  • Post #7
  • Quote
  • Jun 20, 2016 2:23am Jun 20, 2016 2:23am
  •  j11
  • | Joined Jun 2016 | Status: Member | 95 Posts
Yo have an indi that gives you wrong signals!!!!

May I respectfully suggest that you work with indi, or change it, so that it gives correct signals.

OR ... show correct conditions for entry and that would be easier to code.

J.
If it was easy then I would do it !!
 
 
  • Post #8
  • Quote
  • Jun 20, 2016 4:00am Jun 20, 2016 4:00am
  •  mdswamp
  • | Joined Sep 2013 | Status: Member | 55 Posts
Ok. I changed it...
now it shows the right signals..
we have two buffers for buy and sell and there is extra buffer (yellow one) to show that we should stay in trade longer (for example 25pip instead of 12pip)
Attached File(s)
File Type: mq4 Currencies_Enter Origin.mq4   4 KB | 130 downloads
 
 
  • Post #9
  • Quote
  • Jun 20, 2016 9:42am Jun 20, 2016 9:42am
  •  j11
  • | Joined Jun 2016 | Status: Member | 95 Posts
Sorry but really is a mess!

I changed a little so might work now if conditions are met ....

BUT .... Ext3Buffer[];never returns a value I think so you need to check logic.
Therefore .... any parts of EA that look for CEY to return a value will NOT work !

Up to you now to work through it and check your logic (I do not have the time for it!).

Both attachments have been changed

J.
Attached File(s)
File Type: mq4 Currencies_Enter Origin.mq4   5 KB | 132 downloads
File Type: mq4 EA-MEE J11.mq4   8 KB | 130 downloads
If it was easy then I would do it !!
 
 
  • Post #10
  • Quote
  • Jun 20, 2016 1:39pm Jun 20, 2016 1:39pm
  •  j11
  • | Joined Jun 2016 | Status: Member | 95 Posts
Had time to take another quick look ......

1. EA now places the trades.
2. Indi conditions need checking as highlighted in attached on lines 78 & 84
3. Yellow signals of indi do show up in higher TF's so may need to adjust values in the conditions (I tried it on EURGBP)
4. Added PrPeriod in EA so that different TF's can be used.


Hope this helps

J.
Attached File(s)
File Type: mq4 Currencies_Enter Origin.mq4   5 KB | 151 downloads
File Type: mq4 EA-MEE J11.mq4   8 KB | 143 downloads
If it was easy then I would do it !!
 
 
  • Post #11
  • Quote
  • Jun 20, 2016 6:00pm Jun 20, 2016 6:00pm
  •  mdswamp
  • | Joined Sep 2013 | Status: Member | 55 Posts
Hi j... Thank you man, I just needed something to work and now its working,...
now I have to place my conditions, thank you very much
 
 
  • Post #12
  • Quote
  • Jun 23, 2016 9:29am Jun 23, 2016 9:29am
  •  mdswamp
  • | Joined Sep 2013 | Status: Member | 55 Posts
Hi J. sorry bother you again... ea is working, but close action doesn't work. this is the code... it should close the order if heiken ashi changes its color on the third candle open or Exit indicator send signal (Exit indicator doesn't matter now), no matter that we have profit or loss. Thanks

Inserted Code
//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+  
void CheckForOpen()
  {
   int    res;
   double Poin = Point;
   if ((Point == 0.00001) || (Point == 0.001)) Poin *= 10;
//--- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
   CEB =iCustom(NULL,TimeFrame,"Currencies_Enter Origin",0,2);
   CER =iCustom(NULL,TimeFrame,"Currencies_Enter Origin",1,2);
   CEY =iCustom(NULL,TimeFrame,"Currencies_Enter Origin",2,1);
//--- buy conditions
   if (((O4>C4 && O3>C3 && O2<C2 && O1<C1) || (O5>C5 && O4<C4 && O3>C3 && O2<C2 && O1<C1)) && CER==EMPTY_VALUE && CEB==EMPTY_VALUE && CEY==EMPTY_VALUE)
     {
      res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,1,0,NormalizeDouble(Ask+12*Poin,Digits),"",MagicNum,0,clrBlue);
      return;
     }
   if (((O4>C4 && O3>C3 && O2<C2 && O1<C1) || (O5>C5 && O4<C4 && O3>C3 && O2<C2 && O1<C1)) && CER==EMPTY_VALUE && CEB==EMPTY_VALUE && CEY!=EMPTY_VALUE)
     {
      res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,1,0,NormalizeDouble(Ask+25*Poin,Digits),"",MagicNum,0,clrBlue);
      return;
     }
//--- sell conditions
   if (((O4<C4 && O3<C3 && O2>C2 && O1>C1) || (O5<C5 && O4>C4 && O3<C3 && O2>C2 && O1>C1)) && CEB==EMPTY_VALUE && CER==EMPTY_VALUE && CEY==EMPTY_VALUE)
     {
      res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,1,0,NormalizeDouble(Bid-12*Poin,Digits),"",MagicNum,0,clrRed);
      return;
     }
   if (((O4<C4 && O3<C3 && O2>C2 && O1>C1) || (O5<C5 && O4>C4 && O3<C3 && O2>C2 && O1>C1)) && CEB==EMPTY_VALUE && CER==EMPTY_VALUE && CEY!=EMPTY_VALUE)
     {
      res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,1,0,NormalizeDouble(Bid-25*Poin,Digits),"",MagicNum,0,clrRed);
      return;
     }
  }
//+------------------------------------------------------------------+
//| Check for close order conditions                                 |
//+------------------------------------------------------------------+
void CheckForClose()
  {
   bool ClosedF=false;
//--- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
//--- get Moving Average
   CEX = iCustom(NULL,TimeFrame,"Currencies_Exit Origin",0,0,0,0,0);
//---
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderMagicNumber()!=MagicNum || OrderSymbol()!=Symbol()) continue;
      //--- check order type
      if(OrderType()==OP_BUY)
        {
         if (((OE4<CE4 && OE3<CE3 && OE2>CE2 && OE1>CE1) || (OE5<CE5 && OE4>CE4 && OE3<CE3 && OE2>CE2 && OE1>CE1)) || CEX!=EMPTY_VALUE)
           {
            ClosedF=OrderClose(OrderTicket(), OrderLots(), Bid, 2, clrWhite);
              if(!OrderClose(OrderTicket(),OrderLots(),Bid,2,clrWhite))
                 Print("OrderClose error ",GetLastError());
           }
         break;
        }
      if(OrderType()==OP_SELL)
        {
         if (((OE4>CE4 && OE3>CE3 && OE2<CE2 && OE1<CE1) || (OE5>CE5 && OE4<CE4 && OE3>CE3 && OE2<CE2 && OE1<CE1)) || CEX!=EMPTY_VALUE)
           {
            ClosedF=OrderClose(OrderTicket(), OrderLots(), Ask, 2, clrWhite);
              if(!OrderClose(OrderTicket(),OrderLots(),Ask,2,clrWhite))
                 Print("OrderClose error ",GetLastError());
           }
         break;
        }
     }
}
 
 
  • Post #13
  • Quote
  • Jun 23, 2016 12:09pm Jun 23, 2016 12:09pm
  •  mdswamp
  • | Joined Sep 2013 | Status: Member | 55 Posts
when you take trade you should be in that trade until the color changes and then it is closed on the third bar of the opposite color;but somehow it misses the first color change and keeps the trade till the second time color change,something that should not happen.
Attached Image (click to enlarge)
Click to Enlarge

Name: Untitled.png
Size: 20 KB
 
 
  • Post #14
  • Quote
  • Jun 23, 2016 12:54pm Jun 23, 2016 12:54pm
  •  mdswamp
  • | Joined Sep 2013 | Status: Member | 55 Posts
anybody?
 
 
  • Post #15
  • Quote
  • Jun 23, 2016 3:00pm Jun 23, 2016 3:00pm
  •  hanzov
  • | Joined Nov 2012 | Status: Member | 128 Posts
Print("OrderClose error ",GetLastError());

put getlasterror code or message from MT4 journal.

ClosedF=OrderClose(OrderTicket(), OrderLots(), Ask, 2, clrWhite); if(!OrderClose(OrderTicket(),OrderLots(),Ask,2,clrWhite)) Print("OrderClose error ",GetLastError());

you are trying to close order twice, what you do?
 
 
  • Post #16
  • Quote
  • Jun 23, 2016 3:59pm Jun 23, 2016 3:59pm
  •  mdswamp
  • | Joined Sep 2013 | Status: Member | 55 Posts
hi hanzov...
it seems my loop was wrong:
http://www.forexfactory.com/showthread.php?t=511029
i changed it and its worok hanzov, you mean i should delete this line too?? :
" if(!OrderClose(OrderTicket(),OrderL ots(),Ask,2,clrWhite)) Print("OrderClose error ",GetLastError()); "
 
 
  • Post #17
  • Quote
  • Jun 23, 2016 5:14pm Jun 23, 2016 5:14pm
  •  hanzov
  • | Joined Nov 2012 | Status: Member | 128 Posts
For example, you can do it

ClosedF=OrderClose(OrderTicket(), OrderLots(), Ask, 2, clrWhite);
if (!ClosedF) Print("OrderClose error ",GetLastError());

but better find example of the script. MT4 has the same script as example.
 
 
  • Post #18
  • Quote
  • Jun 24, 2016 6:44am Jun 24, 2016 6:44am
  •  mdswamp
  • | Joined Sep 2013 | Status: Member | 55 Posts
Thanks man.
 
 
  • Post #19
  • Quote
  • Edited 12:10pm Jun 24, 2016 11:43am | Edited 12:10pm
  •  mdswamp
  • | Joined Sep 2013 | Status: Member | 55 Posts
sorry guys, im here again, if someone with coding experience could help me with that...
this is my latest ea, after i changed closed condition loop to "for(int i = OrdersTotal()-1; i >= 0; i--)", ea just trade the first order and closing it (with profit or loss), it does not work anymore.. the smily on and auto trade is on, allow live trade ticks.. idk what the problem might be in this ea..
Attached File(s)
File Type: mq4 EA-MEE.mq4   9 KB | 138 downloads
 
 
  • Post #20
  • Quote
  • Jun 24, 2016 2:52pm Jun 24, 2016 2:52pm
  •  hanzov
  • | Joined Nov 2012 | Status: Member | 128 Posts
ye,
you are out of loop after break;
if(OrderType()==OP_BUY)
{
if (((OE4<CE4 && OE3<CE3 && OE2>CE2 && OE1>CE1) || (OE5<CE5 && OE4>CE4 && OE3<CE3 && OE2>CE2 && OE1>CE1)) || CEX!=EMPTY_VALUE)
{
ClosedF=OrderClose(OrderTicket(), OrderLots(), Bid, 2, clrWhite);
if(!ClosedF) Print("OrderClose error ",GetLastError());
}
break; // exit from loop. Put continue; or nothing..
}


also change
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
for if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) continue;

"break" means immediate exit from loop
 
 
  • Platform Tech
  • /
  • Problem With EA
  • Reply to Thread
    • Page 1 2
    • Page 1 2
0 traders viewing now
  • More
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2023