Forex
Google
www.rentasignal.com Metatrader Signals Marketplace

Go Back   Forex Trading > Programming > Metatrader Programming

Notices


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
Thread Tools Display Modes
  #1061 (permalink)  
Old 07-03-2008, 04:09 PM
Junior Member
 
Join Date: May 2008
Posts: 7
areon25 is on a distinguished road
Hi all..

i have a problem with the EA that i wrote.. actually, the EA based on MACD indicator.. when the MACD become like 'n' shape, open post Sell, and when MACD become like 'u' shape, the EA will open Buy..

the problem is, the EA didn't open any post.. after i doing some backtest also, there no open post by this EA.. can someone please help me find what's wrong with the code??
here is the code..

Code:
extern double TakeProfit = 20;
extern double Lots = 0.1;
extern double StopLoss = 20;
extern double MagicNumber = 17384;
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;

//+------------------------------------------------------------------+
//| expert initialization function                                                        |
//+------------------------------------------------------------------+
double     MacdBuffer1[];
double     MacdBuffer2[];
double     MacdBuffer3[];
double     MacdBuffer4[];
double     MacdBuffer5[];
double     MacdBuffer6[];
double     MacdBuffer7[];
double     MacdBuffer8[];

int init()
  {
//----
   //SetIndexBuffer(0, lag1_buffer);
   //SetIndexBuffer(1, lag2_buffer);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
     int limit;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
   for(int i=0; i<limit; i++)
      
      MacdBuffer1[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
      MacdBuffer2[i-1]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i-1)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i-1);
      MacdBuffer3[i+1]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i+1)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i+1);
      MacdBuffer4[i-2]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i-2)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i-2);
      MacdBuffer5[i+2]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i+2)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i+2);
      MacdBuffer6[i-3]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i-3)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i-3);
      MacdBuffer7[i+3]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i+3)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i+3);

   /*Alert( "MacdBuffer7[i+3] =",MacdBuffer7[i+3]);
   Alert( "MacdBuffer5[i+2] =",MacdBuffer5[i+2]);
   Alert( "MacdBuffer3[i+1] =",MacdBuffer3[i+1]);
   Alert( "MacdBuffer1[i] =",MacdBuffer1[i]);
   Alert( "MacdBuffer2[i-1] =",MacdBuffer2[i-1]);
   Alert( "MacdBuffer4[i-2] =",MacdBuffer4[i-2]); 
   Alert( "MacdBuffer6[i-3] =",MacdBuffer6[i-3]);*/
//----
   int ticket_buy, ticket_sell, total;
   total=OrdersTotal();
   
   //MACD become 'u' shape
   if (MacdBuffer7[i+3]>MacdBuffer5[i+2]&&MacdBuffer5[i+2]>MacdBuffer3[i+1]&&MacdBuffer3[i+1]>MacdBuffer1[i]
       &&MacdBuffer1[i]<MacdBuffer2[i-1]&&MacdBuffer2[i-1]<MacdBuffer4[i-2]&&MacdBuffer4[i-2]<MacdBuffer6[i-3]) 
        {
      if (total < 1) {
         
         ticket_buy=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"scalp 1 min - buy",MagicNumber,0,Green);
         if(ticket_buy>0)
           {
            if(OrderSelect(ticket_buy,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
           }
         else Print("Error opening BUY order : ",GetLastError()); 
         return(0);
      } else {
         
      }
   }
 
   //MACD become 'n' shape
   if(MacdBuffer7[i+3]<MacdBuffer5[i+2]&&MacdBuffer5[i+2]<MacdBuffer3[i+1]&&MacdBuffer3[i+1]<MacdBuffer1[i]
       &&MacdBuffer1[i]>MacdBuffer2[i-1]&&MacdBuffer2[i-1]>MacdBuffer4[i-2]&&MacdBuffer4[i-2]>MacdBuffer6[i-3]) 
       {
      
      if (total < 1) {
         
         ticket_sell=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"scalp 1 min - sell",MagicNumber,0,Red);
         
         if(ticket_sell>0)
           {
            if(OrderSelect(ticket_sell,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
           }
         else Print("Error opening SELL order : ",GetLastError()); 
         return(0);
      } else {
         
      }
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+
hope someone can help me solve the problem.. i'm not a good in programming codes.. thanks..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1062 (permalink)  
Old 07-03-2008, 06:57 PM
Senior Member
 
Join Date: Feb 2006
Posts: 579
Michel is on a distinguished road
It's an EA, not an indicator, you should not mix both.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1063 (permalink)  
Old 07-03-2008, 10:17 PM
Junior Member
 
Join Date: May 2008
Posts: 7
areon25 is on a distinguished road
hi all..

Quote:
It's an EA, not an indicator, you should not mix both.
actually, i take some code from MACD indicator and from that i make an EA.. can someone help me which code should i correct it??


thanks..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1064 (permalink)  
Old 07-03-2008, 10:42 PM
Senior Member
 
Join Date: Nov 2006
Posts: 267
luxinterior is on a distinguished road
Try looking at a few of the EA's you already have. Study the code and try to see if you can figure out some of the logic. Try speaking the flow of the program out loud. It helps a lot!

Good Luck

Lux
__________________
Build An Expert Advisor. FREE E-course As Seen On TV
ForexArea.com
Users of Gap Trader from 'Forex-Assistant' MUST Read This
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1065 (permalink)  
Old 07-04-2008, 12:07 AM
Junior Member
 
Join Date: May 2008
Posts: 7
areon25 is on a distinguished road
hi all..

thanks luxinterrior for the reply..

Quote:
Try looking at a few of the EA's you already have. Study the code and try to see if you can figure out some of the logic. Try speaking the flow of the program out loud. It helps a lot!

Good Luck
i have 7 buffer.. buffer1 until buffer7.. each buffer will save MACD bar value.. the EA will open
BUY post when the MACD become 'u' shape..
the condition when..
Code:
if (MacdBuffer7[i+3]>MacdBuffer5[i+2]&&MacdBuffer5[i+2]>MacdBuffer3[i+1]&&MacdBuffer3[i+1]>MacdBuffer1[i]
       &&MacdBuffer1[i]<MacdBuffer2[i-1]&&MacdBuffer2[i-1]<MacdBuffer4[i-2]&&MacdBuffer4[i-2]<MacdBuffer6[i-3])
SELL post when the MACD become 'n' shape..
the condition when..
Code:
   if(MacdBuffer7[i+3]<MacdBuffer5[i+2]&&MacdBuffer5[i+2]<MacdBuffer3[i+1]&&MacdBuffer3[i+1]<MacdBuffer1[i]
       &&MacdBuffer1[i]>MacdBuffer2[i-1]&&MacdBuffer2[i-1]>MacdBuffer4[i-2]&&MacdBuffer4[i-2]>MacdBuffer6[i-3])
hope anyone can help me solve the problem.. thanks..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1066 (permalink)  
Old 07-04-2008, 02:39 AM
TheRumpledOne's Avatar
Banned
 
Join Date: Nov 2006
Posts: 802
TheRumpledOne is an unknown quantity at this point
Is there a way to force the program to calculate?

Right now it waits for the next tick.

I have 6 charts open and the same indicator is on all six charts.

If one chart receives a tick, it updates but the other charts don't so they are "stale".

Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1067 (permalink)  
Old 07-04-2008, 08:06 AM
IN10TION's Avatar
Senior Member
 
Join Date: Mar 2007
Posts: 618
Blog Entries: 1
IN10TION is on a distinguished road
:: if it's suitable then try to form it in a EA, there you can loop & use sleep function, I've tried several simple setups to have only processes/calculations not related to ticks, but then you have the refresh screen issue ... so ... I've changed everything back to normal ... the importance to do so was not that great ... perhaps in MQL5 coming up

:: indicators can't deal with sleep() function

:: you can write a dll, fetch all the windows in your terminal... then do/send a "refresh screen/window" to every child window. But then you have to send dll file together with your indicator to others ... again ... making it complicated ...
Quote:
Originally Posted by TheRumpledOne View Post
Is there a way to force the program to calculate?

Right now it waits for the next tick.

I have 6 charts open and the same indicator is on all six charts.

If one chart receives a tick, it updates but the other charts don't so they are "stale".

Thanks.
__________________
..mini UPDATE..05.May.09.. IN10TION newsReader v09.95 Lite - the best forex news reader on your chart
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1068 (permalink)  
Old 07-04-2008, 08:55 AM
Junior Member
 
Join Date: Dec 2007
Posts: 13
amatrader is on a distinguished road
Hi there,

I hope you don't mind me butting in here, I'm looking at a similar situation and I have a thaught on the issue... what about if you code a loop at the end of your program that says "if no order is open run through again". and let it loop maybe 3 or 4 times.

If it does that then any missed orders (which happens quite often) should surely get picked up. or is there something wrong with my thinking.

I think it would look something like this...

Quote:
for (int k = OrdersTotal() ==0; k >=2; k++)
{
if ( ! OrderSelect ( k, SELECT_BY_POS, MODE_TRADES ))continue;
if (k > 2) break;
}


return(0);
}
I'm still new to this so if it doesn't make sense please explain to me why.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1069 (permalink)  
Old 07-04-2008, 05:00 PM
Member
 
Join Date: Oct 2006
Posts: 79
Big Be is on a distinguished road
To Lux, ajk, Raygun, Devil2000, IN10TION

Thanks for the tips.
I will try them and I hope come up with the answer.
I will post later.

Big Be
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1070 (permalink)  
Old 07-04-2008, 09:43 PM
TheRumpledOne's Avatar
Banned
 
Join Date: Nov 2006
Posts: 802
TheRumpledOne is an unknown quantity at this point
Quote:
Originally Posted by amatrader View Post
Hi there,

I hope you don't mind me butting in here, I'm looking at a similar situation and I have a thaught on the issue... what about if you code a loop at the end of your program that says "if no order is open run through again". and let it loop maybe 3 or 4 times.

If it does that then any missed orders (which happens quite often) should surely get picked up. or is there something wrong with my thinking.

I think it would look something like this...



I'm still new to this so if it doesn't make sense please explain to me why.
Hey, that's a good idea!

I could check the time and if X seconds or minutes have elapsed then exit the loop.

THANKS!!

P.S. This was not for an EA. I don't code EAs.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks

Tags
#include, candle time, CHinGsMAroonCLK, coders guru, conditionally, eli hayun, Eur_harvester.ex4, expert adviser, expert advisor, forex, how to code, indicator, I_XO_A_H, kehedge, mechanical trading, metatrader command line, MT4-LevelStop-Reverse, OrderReliable.mqh, programming, rectangle tool, trading, volty channel stop

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to code this? iscuba11 Metatrader 4 mql 4 - Development course 1 08-03-2007 04:22 PM


All times are GMT. The time now is 12:24 PM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.