trader needs helping hand

 

Hello fellow traders/coders I have a problem with creating a simple EA. But I am doing my best :(


I wish to create an EA that will buy and sell when arrows appear( blue=buy,red=sell),all the time in the game,no stop loss no take profit.


My first step was calling the indicator into EA and I did it but I am not sure if it is correct,the indicator code is attached.




I used the iCustom function like this:


Crossup=iCustom(NULL,0,"2MA CrossoverWithPrice",0,1);

Crossdown=iCustom(NULL,0,"2MA CrossoverWithPrice",0,1);



I have read a lot over the forums and I think that I should put (0,0) and (1,1) in iCustom cuz of the SetIndexBuffer but I don't get the same numbers then in Journal tab.( some kind of error,I get the number =2147483647.0000000)

How do I make a buy/sell orders and buy/sell conditions for this indicators?


Any advice will help tnx :)

 
atomi50 wrote >>

Hello fellow traders/coders I have a problem with creating a simple EA. But I am doing my best :(

I wish to create an EA that will buy and sell when arrows appear( blue=buy,red=sell),all the time in the game,no stop loss no take profit.

My first step was calling the indicator into EA and I did it but I am not sure if it is correct,the indicator code is attached.



I used the iCustom function like this:

Crossup=iCustom(NULL,0,"2MA CrossoverWithPrice",0,1);

Crossdown=iCustom(NULL,0,"2MA CrossoverWithPrice",0,1);

I have read a lot over the forums and I think that I should put (0,0) and (1,1) in iCustom cuz of the SetIndexBuffer but I don't get the same numbers then in Journal tab.( some kind of error,I get the number =2147483647.0000000)

How do I make a buy/sell orders and buy/sell conditions for this indicators?

Any advice will help tnx :)

When calling iCustom, you must pass all external parameters found in the underlying indicator.

you must pass all of these parametes in icustom():

extern string note1 = "First Moving Average";
extern int MA1 = 5;
extern string note2 = "0=sma, 1=ema, 2=smma, 3=lwma";
extern int MA1Mode = 1; //0=sma, 1=ema, 2=smma, 3=lwma
extern string note2b = " 0=close, 1=open, 2=high, 3=low,";
extern string note2c = " 4=median(high+low)/2,";
extern string note2d = " 5=typical(high+low+close)/3,";
extern string note2e = " 6=weighted(high+low+close+close)/4";
extern int MA1Price = 0;//0=close, 1=open, 2=high, 3=low, 4=median(high+low)/2, 5=typical(high+low+close)/3, 6=weighted(high+low+close+close)/4
extern string note3 = "--------------------------------------------";
extern string note4 = "Second Moving Average";
extern int MA2 = 10;
extern string note5 = "0=sma, 1=ema, 2=smma, 3=lwma";
extern int MA2Mode = 1; //0=sma, 1=ema, 2=smma, 3=lwma
extern string note5b = " 0=close, 1=open, 2=high, 3=low,";
extern string note5c = " 4=median(high+low)/2,";
extern string note5d = " 5=typical(high+low+close)/3,";
extern string note5e = " 6=weighted(high+low+close+close)/4";
extern int MA2Price = 0;//0=close, 1=open, 2=high, 3=low, 4=median(high+low)/2, 5=typical(high+low+close)/3, 6=weighted(high+low+close+close)/4
extern string note6 = "--------------------------------------------";
extern string note7 = "Arrow Type";
extern string note8 = "0=Thick, 1=Thin, 2=Hollow, 3=Round";
extern string note9 = "4=Fractal, 5=Diagonal Thin";
extern string note10 = "6=Diagonal Thick, 7=Diagonal Hollow";
extern string note11 = "8=Thumb, 9=Finger";
extern int ArrowType=2;
extern string note12 = "--------------------------------------------";
extern string note13 = "turn on Alert = true; turn off = false";
extern bool AlertOn = true;
extern string note14 = "--------------------------------------------";
extern string note15 = "send Email Alert = true; turn off = false";
extern bool SendAnEmail=false;

These are all prefaced with "extern" indicating that they are changeable by the user.

Next step is to call iCustom four times (twice for each direction) to get the current value and the previous value of the arrows so that you can compare them to each other.

UpArrowNow = icustom(all variable passed,0,0);

UpArrowPrev = icustom(all variable passed,0,1);

DnArrowNow = icustom(all variable passed,1,0);

DnUpArrowPrev = icustom(all variable passed,1,1);

to determine if it is time to trade:

if(UpArrowNow != EMPTY_VALUE && UpArrowPrev == EMPTY_VALUE)

Trade Long here;

if(UpArrowNow != EMPTY_VALUE && UpArrowPrev == EMPTY_VALUE)

Trade Short Here;

Your trade subroutine should check if you are already in a trade so that you can either avoid trading duplicates or exit your current trade before entering your new trade.

failure to do this will cause the system to enter a trade on every tick and, thus, exaust you account.

 
wadem000:

When calling iCustom, you must pass all external parameters found in the underlying indicator.

you must pass all of these parametes in icustom():

extern string note1 = "First Moving Average";
extern int MA1 = 5;
extern string note2 = "0=sma, 1=ema, 2=smma, 3=lwma";
extern int MA1Mode = 1; //0=sma, 1=ema, 2=smma, 3=lwma
extern string note2b = " 0=close, 1=open, 2=high, 3=low,";
extern string note2c = " 4=median(high+low)/2,";
extern string note2d = " 5=typical(high+low+close)/3,";
extern string note2e = " 6=weighted(high+low+close+close)/4";
extern int MA1Price = 0;//0=close, 1=open, 2=high, 3=low, 4=median(high+low)/2, 5=typical(high+low+close)/3, 6=weighted(high+low+close+close)/4
extern string note3 = "--------------------------------------------";
extern string note4 = "Second Moving Average";
extern int MA2 = 10;
extern string note5 = "0=sma, 1=ema, 2=smma, 3=lwma";
extern int MA2Mode = 1; //0=sma, 1=ema, 2=smma, 3=lwma
extern string note5b = " 0=close, 1=open, 2=high, 3=low,";
extern string note5c = " 4=median(high+low)/2,";
extern string note5d = " 5=typical(high+low+close)/3,";
extern string note5e = " 6=weighted(high+low+close+close)/4";
extern int MA2Price = 0;//0=close, 1=open, 2=high, 3=low, 4=median(high+low)/2, 5=typical(high+low+close)/3, 6=weighted(high+low+close+close)/4
extern string note6 = "--------------------------------------------";
extern string note7 = "Arrow Type";
extern string note8 = "0=Thick, 1=Thin, 2=Hollow, 3=Round";
extern string note9 = "4=Fractal, 5=Diagonal Thin";
extern string note10 = "6=Diagonal Thick, 7=Diagonal Hollow";
extern string note11 = "8=Thumb, 9=Finger";
extern int ArrowType=2;
extern string note12 = "--------------------------------------------";
extern string note13 = "turn on Alert = true; turn off = false";
extern bool AlertOn = true;
extern string note14 = "--------------------------------------------";
extern string note15 = "send Email Alert = true; turn off = false";
extern bool SendAnEmail=false;

These are all prefaced with "extern" indicating that they are changeable by the user.

Next step is to call iCustom four times (twice for each direction) to get the current value and the previous value of the arrows so that you can compare them to each other.

UpArrowNow = icustom(all variable passed,0,0);

UpArrowPrev = icustom(all variable passed,0,1);

DnArrowNow = icustom(all variable passed,1,0);

DnUpArrowPrev = icustom(all variable passed,1,1);

to determine if it is time to trade:

if(UpArrowNow != EMPTY_VALUE && UpArrowPrev == EMPTY_VALUE)

Trade Long here;

if(UpArrowNow != EMPTY_VALUE && UpArrowPrev == EMPTY_VALUE)

Trade Short Here;

Your trade subroutine should check if you are already in a trade so that you can either avoid trading duplicates or exit your current trade before entering your new trade.

failure to do this will cause the system to enter a trade on every tick and, thus, exaust you account.

Tnx a lot for a reply wadem000


I did what you said and added some stuff like one entry per bar so now the code looks like this


extern string note1 = "First Moving Average";
extern int MA1 = 5;
extern string note2 = "0=sma, 1=ema, 2=smma, 3=lwma";
extern int MA1Mode = 1; //0=sma, 1=ema, 2=smma, 3=lwma
extern string note2b = " 0=close, 1=open, 2=high, 3=low,";
extern string note2c = " 4=median(high+low)/2,";
extern string note2d = " 5=typical(high+low+close)/3,";
extern string note2e = " 6=weighted(high+low+close+close)/4";
extern int MA1Price = 0;//0=close, 1=open, 2=high, 3=low, 4=median(high+low)/2, 5=typical(high+low+close)/3, 6=weighted(high+low+close+close)/4
extern string note3 = "--------------------------------------------";
extern string note4 = "Second Moving Average";
extern int MA2 = 10;
extern string note5 = "0=sma, 1=ema, 2=smma, 3=lwma";
extern int MA2Mode = 1; //0=sma, 1=ema, 2=smma, 3=lwma
extern string note5b = " 0=close, 1=open, 2=high, 3=low,";
extern string note5c = " 4=median(high+low)/2,";
extern string note5d = " 5=typical(high+low+close)/3,";
extern string note5e = " 6=weighted(high+low+close+close)/4";
extern int MA2Price = 0;//0=close, 1=open, 2=high, 3=low, 4=median(high+low)/2, 5=typical(high+low+close)/3, 6=weighted(high+low+close+close)/4
extern string note6 = "--------------------------------------------";
extern string note7 = "Arrow Type";
extern string note8 = "0=Thick, 1=Thin, 2=Hollow, 3=Round";
extern string note9 = "4=Fractal, 5=Diagonal Thin";
extern string note10 = "6=Diagonal Thick, 7=Diagonal Hollow";
extern string note11 = "8=Thumb, 9=Finger";
extern int ArrowType=2;
extern string note12 = "--------------------------------------------";
extern string note13 = "turn on Alert = true; turn off = false";
extern bool AlertOn = true;
extern string note14 = "--------------------------------------------";
extern string note15 = "send Email Alert = true; turn off = false";
extern bool SendAnEmail=false;
extern bool OneEntryPerBar= true;

datetime CheckEntryTime;


double UpArrowNow;
double UpArrowPrev;
double DownArrowNow;
double DownArrowPrev;

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

UpArrowNow=iCustom(NULL,0,"2MA CrossoverWithPrice",note1,MA1,note2,MA1Mode,note2b,note2c,note2d,
note2e,MA1Price,note3,note4,MA2,note5,MA2Mode,note5b,note5c,note5d,note5e,MA2Price,note6,
note7,note8,note9,note10,note11,ArrowType,note12,note13,AlertOn,note14,note15,SendAnEmail,0,0);

UpArrowPrev=iCustom(NULL,0,"2MA CrossoverWithPrice",note1,MA1,note2,MA1Mode,note2b,note2c,note2d,
note2e,MA1Price,note3,note4,MA2,note5,MA2Mode,note5b,note5c,note5d,note5e,MA2Price,note6,
note7,note8,note9,note10,note11,ArrowType,note12,note13,AlertOn,note14,note15,SendAnEmail,0,1);

DownArrowNow=iCustom(NULL,0,"2MA CrossoverWithPrice",note1,MA1,note2,MA1Mode,note2b,note2c,note2d,
note2e,MA1Price,note3,note4,MA2,note5,MA2Mode,note5b,note5c,note5d,note5e,MA2Price,note6,
note7,note8,note9,note10,note11,ArrowType,note12,note13,AlertOn,note14,note15,SendAnEmail,1,0);

DownArrowPrev=iCustom(NULL,0,"2MA CrossoverWithPrice",note1,MA1,note2,MA1Mode,note2b,note2c,note2d,
note2e,MA1Price,note3,note4,MA2,note5,MA2Mode,note5b,note5c,note5d,note5e,MA2Price,note6,
note7,note8,note9,note10,note11,ArrowType,note12,note13,AlertOn,note14,note15,SendAnEmail,1,1);

//----------------------- ONE ENTRY PER BAR

if(OneEntryPerBar==true)
{
if(CheckEntryTime==iTime(NULL,0,0)) return(0); else CheckEntryTime = iTime(NULL,0,0);
}


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

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()

//BUY ORDER
{
if(UpArrowNow != EMPTY_VALUE && UpArrowPrev == EMPTY_VALUE)
{
OrderSend(Symbol(),OP_BUY,0.01,Ask,2,0,0,"Opening Buy Order",0,0,CLR_NONE);
}

// SELL ORDER
if(DownArrowNow != EMPTY_VALUE && DownArrowPrev == EMPTY_VALUE)
{
OrderSend(Symbol(),OP_SELL,0.01,Bid,2,0,0,"Opening Sell Order",0,0,CLR_NONE);
}
//----

//----
return(0);
}


Of course I didn't generate any trades because something is wrong buy I don't know what so if you could check it out.I Know there is a lot more to do but I want to see it do something, atleast to open a trade in some direction.Just to hear the heartbeat.


When compiling I don't have any warnings or errors but when attached I don't generate trades.





return(0);
}

 
Just looked over briefly and one thing that potentially is causing you troubles is that you have set the lot size to 0.01 instead of the (my guess) intended 0.1 . Bare in mind that 0.1 is the minimum lot size.
 
Garnak:
Just looked over briefly and one thing that potentially is causing you troubles is that you have set the lot size to 0.01 instead of the (my guess) intended 0.1 . Bare in mind that 0.1 is the minimum lot size.

no it's not


I am trading on Alpari UK and I trade 0.01 lot size ( Micro Account )

 
atomi50 wrote >>

no it's not

I am trading on Alpari UK and I trade 0.01 lot size ( Micro Account )

I have modified your code somewhat and I got it to trade but I had to force it. I had to remove

references to EMPTY_VAlUE

I get the same error as you do unless I do the above: 2147483647.0000000)

The UpArrow variable calls in the init() subroutine should not be there.

move them to the top ofthe start() subroutine; these have to be called every tick. init() is only called once

Still working on it.

 
wadem000:

I have modified your code somewhat and I got it to trade but I had to force it. I had to remove

references to EMPTY_VAlUE

I get the same error as you do unless I do the above: 2147483647.0000000)

The UpArrow variable calls in the init() subroutine should not be there.

move them to the top ofthe start() subroutine; these have to be called every tick. init() is only called once

Still working on it.


Sry wadem000 I kinda lost you now :(


It would be a lot easier if you would post your code here.


I moved all the iCustom calls from int() to start() - I think that is what you mean but I am not sure.


I still get 2147 ... numbers but yesterday I had some action, a lot of it, the EA opend more than 100 positions in like 15 minutes so I guess the BUY ORDER part of the code is ok, now only to match the buy conditions, and Sell also ( I didnt have any sell orders ).


and again,really appriciate your help man.

 
atomi50 wrote >>

Sry wadem000 I kinda lost you now :(

It would be a lot easier if you would post your code here.

I moved all the iCustom calls from int() to start() - I think that is what you mean but I am not sure.

I still get 2147 ... numbers but yesterday I had some action, a lot of it, the EA opend more than 100 positions in like 15 minutes so I guess the BUY ORDER part of the code is ok, now only to match the buy conditions, and Sell also ( I didnt have any sell orders ).

and again,really appriciate your help man.

Send me your code - I take another look

email it MQL4@MidNightHost.com

 
wadem000:

Send me your code - I take another look

email it MQL4@MidNightHost.com

ok I sent you the code,trid some new stuff but no luck

 
atomi50:

Hello fellow traders/coders I have a problem with creating a simple EA. But I am doing my best :(


I wish to create an EA that will buy and sell when arrows appear( blue=buy,red=sell),all the time in the game,no stop loss no take profit.


My first step was calling the indicator into EA and I did it but I am not sure if it is correct,the indicator code is attached.




I used the iCustom function like this:


Crossup=iCustom(NULL,0,"2MA CrossoverWithPrice",0,1);

Crossdown=iCustom(NULL,0,"2MA CrossoverWithPrice",0,1);



I have read a lot over the forums and I think that I should put (0,0) and (1,1) in iCustom cuz of the SetIndexBuffer but I don't get the same numbers then in Journal tab.( some kind of error,I get the number =2147483647.0000000)

How do I make a buy/sell orders and buy/sell conditions for this indicators?


Any advice will help tnx :)



Reason: