Forex



Go Back   Forex Trading > Programming > MetaTrader
Forex Forum Register More recent Blogs Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
Thread Tools Display Modes
  #2051 (permalink)  
Old 09-19-2009, 10:58 AM
mladen's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,271
mladen is on a distinguished road
...

Your EA will always load (if it does not have a coding error that would prevent it to compile)

You just have to decide where do you want it to stop doing the "usual job" it does and prevent it from doing it for an unauthorized ones. Normally you put that checking routine at the beginning of the start() - something like this :
PHP Code:
//+------------------------------------------------------------------+
//|                                                     Dll_call.mq4 |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
   static 
bool alerted false;
   
int    a  907671;
   
int    b AccountNumber();
      if (
!= a)
      {
         if (!
alerted)
         {
            
Comment("Checking Account No! (" DoubleToStr(b0) + ") wrong Acc");
            
alerted true;
         }            
         return (
0);
      }
      
      
//
      //
      //    the part that is not executed when account number is wrong
      //
      //
      
      
alerted false;
      
Comment("continuing the rest of the job");
      return(
0);
   } 
But also, this kind of checking is hackable by a decompiler in a matter of minutes.
PS: changed the Alert() to Comment() so you can check it in visual back test

Quote:
Originally Posted by jimmynz View Post
thanks for the help, but still no.

werid thing is i tried making an EA with the usual code to check acc #:

int a = 907671;
int b = AccountNumber();
if (b != a) {
Alert("Checking Account No! (" + DoubleToStr(li_16, 0) + ") wrong Acc");
return (0)}

as an EA it loads no matter what the number is, but if i make it as an indi it works fine?

ggrrr

Last edited by mladen; 09-19-2009 at 11:02 AM.
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
  #2052 (permalink)  
Old 09-19-2009, 09:38 PM
wolfe's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 818
wolfe is on a distinguished road
Quote:
Originally Posted by jimmynz View Post
this is the def file. look ok?
does it need to go in librarys with the DLL?
I created a short dll example project to try and show you how this works, unfortunately we cannot attach a dll file in the forum. If you PM me with an e-mail address I could e-mail you the dll to try.

The code for the dll.cpp is as follows:

PHP Code:
#include <windows.h>
#include <iostream>

using namespace std;

#define MT4_EXPFUNC __declspec(dllexport)

MT4_EXPFUNC double __stdcall GetDoubleFromDLL()
 {
  return(
1234.5678);
 } 
Then you need to have the linked .def file in your solution:

PHP Code:
LIBRARY DLL_Example

EXPORTS 
        GetDoubleFromDLL 
You put the dll in system32 and the test with a simple mq4 EA (make sure allow dll imports is selected):

PHP Code:
//+------------------------------------------------------------------+
//|                                                     Dll_call.mq4 |
//|                      Copyright © 2009, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#import "DLL_Example.dll"
double   GetDoubleFromDLL();
#import


//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
  
Comment("\nReturn from DLL_Example = ",GetDoubleFromDLL());
  }
  
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
  
  }

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
   {
   
   } 
Hope this helps, I know how frustrating this can be!

-wolfe
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
  #2053 (permalink)  
Old 09-21-2009, 11:41 AM
Junior Member
 
Join Date: Nov 2008
Posts: 21
wayhuck is on a distinguished road
Quote:
Originally Posted by luxinterior View Post
So you're great plan is to take two free EA's that you probably found here and 'merge' them together and sell it for 2K a pop? You've got some nerve buddy! Maybe if you're really lucky one of the two guys that actually gave up their time, effort and knowledge for free will offer to do it for you.

Oh but wait! If the code is 'messed up' then the EA's are mostly likely commercial EA's that have been decompiled. Is that it? Moron!!!

Lux
Oh, nice speech. Let me tell you this:

No matter what EA you're looking at, most likely there will be someone with the same idea already have the EA made. Free EA's? Are you kidding me? Which EA right on this forum had that potentials?

Also, there's alot of people calling themselves developers are also copying from others, selling for $3000 club subscriptions. And worst, with EA's that will blow your accounts flat. .... ZERO

Also, I had never took any EA's from here. Which EA is worth for the merge on this forum? Also, if the code is messed up, it could be me asking programmers to code an EA. Then as more features needed, I'm asking different programmers...TO HELP !

Different coding styles could over the time, messed up codes.

Also, I didn't decompile any commercial EA. The reason you said I am, is the fact that you're doing it yourself. I don't know what type of mess a decompiler will caused. But for sure, if you are so sure that a decompiler could caused a mess, then you've probably been using it. Otherwise you'd never know.

One advice, before calling others moron or try to act like a police / hero saving the day, judge yourself first. If not, those words coming from your mouth could forced you to swallow them back in.

Thank you.
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
  #2054 (permalink)  
Old 09-22-2009, 12:27 AM
Junior Member
 
Join Date: Sep 2009
Posts: 2
smsfm is on a distinguished road
Help regarding iMAOnArray()

Hi,

I'm new to MT4... I've been despeately trying to include the following piece of code in an expert but have been unable to do so

" iMAOnArray(ind_buffer1,Bars,SignalEMA,0,MODE_EMA,i ); "


Yes, i know that the above can't be used directly in an EA, but is it possible to achieve same results by recoding the above MA? if so, i'd really appreciate some help on that.

Regards.
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
  #2055 (permalink)  
Old 09-22-2009, 12:44 AM
Pheniox's Avatar
Senior Member
 
Join Date: Apr 2007
Location: Canada
Posts: 330
Pheniox is on a distinguished road
Using External *.set files

I have tried and tried but can not figure this out so hopefully someone can see the tree through the forest here.

I want to program an EA to use either it's programmed settings or else use an external *.set file.

So if:

extern bool UseExternSet = true;

it will use the settings in the external set file rather than the programmed settings.

Know it can be done but simple lost here.

Any ea example will do

Bernard
__________________
" Those that say it can not be done should leave those that are doing it alone "
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
  #2056 (permalink)  
Old 09-22-2009, 11:58 PM
Junior Member
 
Join Date: Jun 2009
Posts: 19
username1 is on a distinguished road
Question Compiler problem or code problem ?

Code:
extern int ma1period=5;
extern int ma1method=1;
extern int ma1tf=0;
extern int ma2period=5;
extern int ma2method=1;
extern int ma2tf=10080;
extern double lots=1;

int init(){}
int deinit(){}

double CMA (int tf,int period, int shift, int method)
   {
      double MA=iMA(NULL,tf,period,0,method,0,shift)
      return(MA)
   }
  

int start()
  {
    int BarsCount=0;
   
    if (Bars> BarsCount)
    {
     BarsCount=Bars;
    
     double ma1.1=CMA(ma1tf,ma1period,1,ma1method);
     double ma1.2=CMA(ma1tf,ma1period,2,ma1method);
     double ma2.1=CMA(ma2tf,ma2period,1,ma2method);
     double ma2.2=CMA(ma2tf,ma2period,2,ma2method);
     
     bool ma1upsignal   =ma1.2<ma1.1;
     bool ma1downsignal =ma1.2>ma1.1;
     bool ma2upsignal   =ma2.2<ma2.1;
     bool ma2downsignal =ma2.2>ma2.1;
    
     if (ma1upsignal&&ma2upsignal)
     {
     OrderSend(Symbol(),OP_BUY,lots,Ask,3,NULL,NULL,NULL,NULL,0,Green);
     }
    
     if (ma1downsignal&&ma2downsignal)
     {
     OrderSend(Symbol(),OP_SELL,lots,Bid,3,NULL,NULL,NULL,NULL,0,Green);
     }
    
     if ((ma1upsignal&&ma2downsignal)||(ma1downsignal&&ma2upsignal))
     {
      int total=OrdersTotal(); //Script to close all open orders.
      for(int i=total-1;i>=0;i--)
      {
        OrderSelect(i, SELECT_BY_POS);
        int type   = OrderType();
           
        switch(type)
        {
          //Close opened long positions
          case OP_BUY       : OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
                              break;
          //Close opened short positions
          case OP_SELL      : OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
        }
      }
     }
   
   
  }
Capture2.PNG

This is the piece of code i'm working on. The compiler says "the variable BarsCount is not defined". What do i do? As far as I can see, the variable has been initialized and given a value.

Is it my compiler problem or code problem ?
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
  #2057 (permalink)  
Old 09-23-2009, 12:18 AM
Senior Member
 
Join Date: Feb 2006
Posts: 587
Michel is on a distinguished road
[quote=username1;306593][code]
double CMA (int tf,int period, int shift, int method)
{
double MA=iMA(NULL,tf,period,0,method,0,shift);
return(MA);
}
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
  #2058 (permalink)  
Old 09-23-2009, 12:42 AM
Junior Member
 
Join Date: Jun 2009
Posts: 19
username1 is on a distinguished road
[quote=Michel;306594]
Quote:
Originally Posted by username1 View Post
[code]
double CMA (int tf,int period, int shift, int method)
{
double MA=iMA(NULL,tf,period,0,method,0,shift);
return(MA);
}
Michel,

Thanks. That solved the problem. :-)
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
  #2059 (permalink)  
Old 09-23-2009, 01:03 AM
nondisclosure007's Avatar
Senior Member
 
Join Date: Apr 2007
Posts: 124
nondisclosure007 is on a distinguished road
Counting consecutive bars

Anyone got some code on how to count consecutive buy/sell bars in a row? I want to count how many times on a chart (enter number of bars to check) there are 1 sell bars in a row, 32sell bars in a row, 3 sell bars in a row, 4 sell bars in a row (same w/ buy) etc.

I know I need to loop it, but I can't quite figure out how.

Results can go in a Comment().

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
  #2060 (permalink)  
Old 09-23-2009, 05:41 AM
Junior Member
 
Join Date: Jun 2009
Posts: 5
bellco is on a distinguished road
Exclamation Why does not my prog not work?

Wrote a simple prog.
It is supposed to enter only one order at a time,& exit w/ a take profit or a stop loss.
It is set up for M30 on GBPUSD.
Ie: some of the constants sed in the prog are found by "eyeball" estimates. This should not greatly effect the prog... it also does not work w/ different constants. (At least, when tested w/ the Strategy Tester, set on fast or medium: not "tick by tick". (too slow...)
Anyhow the prog, when tested does not enter an order AND does not ever! check in the "up" direction. (This, via the "print"/trace)

(it is supposed to check: enter w/ a buy or enter w/ a sell)

Incidental logic: check 2 consecutive bars. If bar 1 has both: a higher high & a higher low, prog thinks that the next bar will be up.
(Symetrically for down.)
Take profit & stop loss are set accordingly.
The prog also did not work when the "if" statements were nested....

Thanks for looking at this.

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
bool TrendUp1; double TakeProfitUp; double EE = .00500;
bool OrdTot_OK;double lot;double slip;
double SL_Trailing_Up;bool High2Up;bool Low2Up;
int ticketup;int ticketdown;bool DownAndBig; bool UpAndBig;
bool TrendDown; double SL_Trailing_Down;double TakeProfitDown;
bool High2down; bool Low2down;
int ABC = OrdersTotal();
double Size1 = .00630;bool BigUp; double A = High[1];double B= Low[2];//41
double C= High[2]; double D= Low[1];bool BigDown;





//------------------------------------down order start
if (ABC == 0)// no orders out is true
OrdTot_OK = true;
if (ABC == 0)// no orders out is true
Print ("on down order sequence, no orders were out");
if ((C-D) > Size1)//high of 2 less low of 1 > .0063
BigDown = true;
if ((C-D) > Size1)//high of 2 less low of 1 > .0063
Print ("on down order sequence, found a big breakout down");
if (High[1]< High[2])
High2down=true;
if (High[1]< High[2])
Print ("on down order sequence, the consecutive bars have decreasing highs");
if(Low[1]< Low[2])
Low2down=true;
if(Low[1]< Low[2])
Print ("on down order sequence, the consecutive bars have decreasing lows");
if (High2down && Low2down)
TrendDown=true;
if (High2down && Low2down)
Print ("on down order sequence, TrendDown flag is set");
if (TrendDown)
SL_Trailing_Down = High[1];
if (TrendDown)
Print ("on down order sequence, did set the stop_loss");
if (TrendDown)
TakeProfitDown = Bid - (.005);
if (TrendDown)
Print ("on down order sequence, got a takeprofit", TakeProfitDown);
if (TrendDown && BigDown)
DownAndBig = true;
if (DownAndBig && OrdTot_OK)
ticketdown= OrderSend(Symbol(),OP_SELL,lot, Bid,slip,SL_Trailing_Down,TakeProfitDown,Blue);
if (DownAndBig && OrdTot_OK)
Print ("on down order sequence, tried to enter a ticket", ticketdown);
if (ticketdown < 0)
Print("OrderSend_Down failed with error #",GetLastError());
return(0);

//----------------------------------------------down order done
//---------------------------------------------------up order start
if (ABC == 0)
OrdTot_OK = true;
if (ABC == 0)
Print ("on the going up sequence, no orders were out");
if ((A - B) > Size1)
BigUp = true;
if ((A - B) > Size1)
Print ("on the going up sequence, the size test for the two bars was ok");
if (High[1] > High[2])
High2Up = true;//44
if (High[1] > High[2])
Print ("on the going up sequence, the test for increasing highs was ok");
if(Low[1] > Low[2])
Low2Up=true;
if(Low[1] > Low[2])
Print ("on the going up sequence, the test for increasing lows was ok");
if (High2Up && Low2Up)
TrendUp1=true;
if (High2Up && Low2Up)
Print ("on the going up sequence, did set the flag for going up");
if (TrendUp1)
SL_Trailing_Up = Low[1] ;
if (TrendUp1)
Print ("on the going up sequence, established the stoploss");
if (TrendUp1)
TakeProfitUp = Ask + (.005);
if (TrendUp1)
Print ("on the going up sequence, established the takeprofit", TakeProfitUp);
if (TrendUp1 && BigUp)
UpAndBig = true;
if ( UpAndBig && OrdTot_OK)
ticketup = OrderSend(Symbol(), OP_BUY,lot, Ask,slip, SL_Trailing_Up,TakeProfitUp,Red);
if (UpAndBig && OrdTot_OK)
Print ("on the going up sequence, tried to send in an order", ticketup);
if (ticketup < 0)
Print("OrderSend_Up failed with error #",GetLastError());
return(0);

//-------------------------------------------------up order done

//----
return(0);// not sure about this line

//+------------------------------------------------------------------+
//----
return(0);
}
//+------------
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, code, coders guru, conditionally, dll, eli hayun, Eur_harvester.ex4, expert adviser, expert advisor, forex, higher high, how to code, indicator, I_XO_A_H, kehedge, mechanical trading, metatrader command line, mt4, MT4-LevelStop-Reverse, OrderReliable.mqh, programming, rectangle tool, trading, volty channel stop


Currently Active Users Viewing This Thread: 2 (1 members and 1 guests)
cutzpr
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 05:22 PM


All times are GMT. The time now is 04:56 PM.



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