How to code? - page 279

 
g.pociejewski:
[lang=pl]On more question is your time i GMT or not? If it's no GMT i will made little change in this EA.

I've just made it please check it i PM me if every thing is ok.

Distance beetwen low and high stopLoss and TP i made as extern variabels.

Cheers Grzesiek.[/lang]

Dear Grzesiek

I pasted this indicator in experts folder and today I monitored to learn how it works. The problem it has is that once it make first trade and it closes order either on stop or t/p then immediately EA again starts the trade on the price it closed recent order. How can I stop it in the code? thanks

 

Any one can help me with it?

Hello Forum

this Code has one problem, when it executes trade its OK but when it closes order again EA opens new trade at the price and on the time when previous order was closed. I did not see any error in the code. Who wrote this is very busy guy and is not online. Can anyone suggest what's the problem?

extern double stopLoss = 35.0;

extern double takeProfit = 50.0;

extern string Begin="00:00";

extern string End="08:00";

extern double distance = 5;

bool isECN = true;

bool cond = false;

bool cond2 = false;

double low;

double high;

extern double lots = 1;

int magic = 123;

int slippage = 1;

string comment = "test";

int ticket;

//+------------------------------------------------------------------+

//| expert initialization function |

//+------------------------------------------------------------------+

int init()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

int start()

{

//----

if(isGoodTime(Begin,End))

{

if(!cond)

{

low = Bid;

high = Ask;

}

cond = true;

if(Bid < low) low = Bid;

if(Ask > high) high = Ask;

}

if((high - low)*1000>distance)

{

cond2 = true;

}

if(!isGoodTime(Begin,End))

{

cond = false;

}

if(!isGoodTime(Begin,End) && cond2)

{

if(countOrders(magic,OP_SELL) == 0 )

{

if(Bid<=(low-0.0010))

{

if(isECN == false)

{

OrderSend(Symbol(),OP_SELL,lots,Bid, slippage,sltpValue(Ask+ stopLoss*Point,stopLoss) ,sltpValue(Ask- takeProfit*Point,takeProfit),comment,magic);

}

if(isECN)

{

ticket=OrderSend(Symbol(),OP_SELL,lots,Bid, slippage,0,0,comment,magic);

OrderSelect(ticket,SELECT_BY_TICKET);

OrderModify(ticket,OrderOpenPrice(),sltpValue(Ask +stopLoss*Point, stopLoss),sltpValue(Bid- takeProfit*Point,takeProfit),0);

}

}

}

if(countOrders(magic,OP_BUY) == 0)

{

if((Ask-high)>=0.0010)

{

if(isECN==false)

{

OrderSend(Symbol(),OP_BUY,lots,Ask, slippage,sltpValue(Ask - stopLoss*Point, stopLoss),sltpValue(Bid+ takeProfit*Point,takeProfit),comment,magic);

}

if(isECN)

{

ticket=OrderSend(Symbol(),OP_BUY,lots,Ask, slippage,0,0,comment,magic);

OrderSelect(ticket,SELECT_BY_TICKET);

OrderModify(ticket,OrderOpenPrice(),sltpValue(Bid - stopLoss*Point, stopLoss),sltpValue(Ask+ takeProfit*Point,takeProfit),0);

}

}

}

}

//----

return(0);

}

//+------------------------------------------------------------------+

bool isGoodTime(string Begin, string End) {

if(TimeCurrent()>StrToTime(Begin) && TimeCurrent()<StrToTime(End)) {

return(true);

}

return(false);

}

int countOrders(int oMagic,int oType) {

int count=0;

for(int i=0;i<OrdersTotal();i++) {

if(OrderSelect(i,SELECT_BY_POS)) {

if(OrderMagicNumber()==oMagic) {

if(OrderSymbol()==Symbol()) {

if(OrderType()==oType || oType<0) {

count++;

}

}

}

}

}

return(count);

}

double sltpValue(double w1, int w2)

{

if(w2 == 0)

return (0);

return (NormalizeDouble(w1, Digits));

}

 

Hi Avasys,

As far as i can tell there is nothing wrong with the code, based on your description it does exactly what it is programmed to do (buy when Ask is higher than high and sell when bid is lower than low) it basically continue to buy and sell as the high and low are broken, respectively.

Cheers,

 
Avasys:
Thanks for your comment

Is there any way to tell code to trade only once in day and only first break out.

The author of this code is very busy man he could not contribute much time as it seems

help is appreciated

[lang=pl]//+------------------------------------------------------------------+

//| simple EA.mq4 |

//| Copyright © 2011, luktom.biz |

//| www.luktom.biz/en |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2011, luktom.biz."

#property link "http://www.luktom.biz"

extern double stopLoss = 300.0;

extern double takeProfit = 500.0;

extern string Begin="2:00";

extern string End="10:00";

extern double distance = 60;

bool isECN = true;

bool cond = false;

bool cond2 = false;

double low;

double high;

extern double lots = 0.1;

int magic = 1232344524285020;

int slippage = 1;

string comment = "";

int ticket;

int short = 0;

int long = 0;

//+------------------------------------------------------------------+

//| expert initialization function |

//+------------------------------------------------------------------+

int init()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//----

Print(countOrders(magic,OP_BUY));

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

int start()

{

Print(AccountCurrency());

//----

if(isGoodTime(Begin,End))

{

short = 0;

long = 0;

if(!cond)

{

low = Bid;

high = Ask;

}

cond = true;

if(Bid < low) low = Bid;

if(Ask > high) high = Ask;

}

if((high - low)*1000>distance)

{

cond2 = true;

}

if(!isGoodTime(Begin,End))

{

cond = false;

}

if(!isGoodTime(Begin,End) && cond2)

{

if(countOrders(magic,OP_SELL) == 0 )

{

if(Bid<=(low-0.0005) && short == 0)

{

short++;

if(isECN == false)

{

OrderSend(Symbol(),OP_SELL,lots,Bid, slippage,sltpValue(Ask+ stopLoss*Point,stopLoss) ,sltpValue(Ask- takeProfit*Point,takeProfit),comment,magic);

}

if(isECN)

{

ticket=OrderSend(Symbol(),OP_SELL,lots,Bid, slippage,0,0,comment,magic);

OrderSelect(ticket,SELECT_BY_TICKET);

OrderModify(ticket,OrderOpenPrice(),sltpValue(Ask +stopLoss*Point, stopLoss),sltpValue(Bid- takeProfit*Point,takeProfit),0);

}

}

}

if(countOrders(magic,OP_BUY) == 0)

{

if((Ask-high)>=0.005 && long ==0)

{

long++;

if(isECN==false)

{

OrderSend(Symbol(),OP_BUY,lots,Ask, slippage,sltpValue(Ask - stopLoss*Point, stopLoss),sltpValue(Bid+ takeProfit*Point,takeProfit),comment,magic);

}

if(isECN)

{

ticket=OrderSend(Symbol(),OP_BUY,lots,Ask, slippage,0,0,comment,magic);

OrderSelect(ticket,SELECT_BY_TICKET);

OrderModify(ticket,OrderOpenPrice(),sltpValue(Bid - stopLoss*Point, stopLoss),sltpValue(Ask+ takeProfit*Point,takeProfit),0);

}

}

}

}

//----

return(0);

}

//+------------------------------------------------------------------+

bool isGoodTime(string Begin, string End) {

if(TimeCurrent()>StrToTime(Begin) && TimeCurrent()<StrToTime(End)) {

return(true);

}

return(false);

}

int countOrders(int oMagic,int oType) {

int count=0;

for(int i=0;i<OrdersTotal();i++) {

if(OrderSelect(i,SELECT_BY_POS)) {

if(OrderMagicNumber()==oMagic) {

if(OrderSymbol()==Symbol()) {

if(OrderType()==oType || oType<0) {

count++;

}

}

}

}

}

return(count);

}

double sltpValue(double w1, int w2)

{

if(w2 == 0)

return (0);

return (NormalizeDouble(w1, Digits));

}

Now EA open only one position per day. Reffering to your question about emails, somwhere in forum exists my post in this them:)

Let me know if find it.

Cheers,

Grzesiek[/lang]

 
Pip:
Hi Avasys,

As far as i can tell there is nothing wrong with the code, based on your description it does exactly what it is programmed to do (buy when Ask is higher than high and sell when bid is lower than low) it basically continue to buy and sell as the high and low are broken, respectively.

Cheers,

Thanks for your comment

Is there any way to tell code to trade only once in day and only first break out.

The author of this code is very busy man he could not contribute much time as it seems

and what I've noticed is that system executes trades despite range between times indicated in code is more than 60 pips the system still trades, it only trade if range between specific times (indicated in code, see begin and end times) is less than 60 pips then trade.

help is appreciated

 
g.pociejewski:
[lang=pl]//+------------------------------------------------------------------+

//| simple EA.mq4 |

//| Copyright © 2011, luktom.biz |

//| www.luktom.biz/en |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2011, luktom.biz."

#property link "http://www.luktom.biz"

extern double stopLoss = 300.0;

extern double takeProfit = 500.0;

extern string Begin="2:00";

extern string End="10:00";

extern double distance = 60;

bool isECN = true;

bool cond = false;

bool cond2 = false;

double low;

double high;

extern double lots = 0.1;

int magic = 1232344524285020;

int slippage = 1;

string comment = "";

int ticket;

int short = 0;

int long = 0;

//+------------------------------------------------------------------+

//| expert initialization function |

//+------------------------------------------------------------------+

int init()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//----

Print(countOrders(magic,OP_BUY));

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

int start()

{

Print(AccountCurrency());

//----

if(isGoodTime(Begin,End))

{

short = 0;

long = 0;

if(!cond)

{

low = Bid;

high = Ask;

}

cond = true;

if(Bid < low) low = Bid;

if(Ask > high) high = Ask;

}

if((high - low)*1000>distance)

{

cond2 = true;

}

if(!isGoodTime(Begin,End))

{

cond = false;

}

if(!isGoodTime(Begin,End) && cond2)

{

if(countOrders(magic,OP_SELL) == 0 )

{

if(Bid<=(low-0.0005) && short == 0)

{

short++;

if(isECN == false)

{

OrderSend(Symbol(),OP_SELL,lots,Bid, slippage,sltpValue(Ask+ stopLoss*Point,stopLoss) ,sltpValue(Ask- takeProfit*Point,takeProfit),comment,magic);

}

if(isECN)

{

ticket=OrderSend(Symbol(),OP_SELL,lots,Bid, slippage,0,0,comment,magic);

OrderSelect(ticket,SELECT_BY_TICKET);

OrderModify(ticket,OrderOpenPrice(),sltpValue(Ask +stopLoss*Point, stopLoss),sltpValue(Bid- takeProfit*Point,takeProfit),0);

}

}

}

if(countOrders(magic,OP_BUY) == 0)

{

if((Ask-high)>=0.005 && long ==0)

{

long++;

if(isECN==false)

{

OrderSend(Symbol(),OP_BUY,lots,Ask, slippage,sltpValue(Ask - stopLoss*Point, stopLoss),sltpValue(Bid+ takeProfit*Point,takeProfit),comment,magic);

}

if(isECN)

{

ticket=OrderSend(Symbol(),OP_BUY,lots,Ask, slippage,0,0,comment,magic);

OrderSelect(ticket,SELECT_BY_TICKET);

OrderModify(ticket,OrderOpenPrice(),sltpValue(Bid - stopLoss*Point, stopLoss),sltpValue(Ask+ takeProfit*Point,takeProfit),0);

}

}

}

}

//----

return(0);

}

//+------------------------------------------------------------------+

bool isGoodTime(string Begin, string End) {

if(TimeCurrent()>StrToTime(Begin) && TimeCurrent()<StrToTime(End)) {

return(true);

}

return(false);

}

int countOrders(int oMagic,int oType) {

int count=0;

for(int i=0;i<OrdersTotal();i++) {

if(OrderSelect(i,SELECT_BY_POS)) {

if(OrderMagicNumber()==oMagic) {

if(OrderSymbol()==Symbol()) {

if(OrderType()==oType || oType<0) {

count++;

}

}

}

}

}

return(count);

}

double sltpValue(double w1, int w2)

{

if(w2 == 0)

return (0);

return (NormalizeDouble(w1, Digits));

}

Now EA open only one position per day. Reffering to your question about emails, somwhere in forum exists my post in this them:)

Let me know if find it.

Cheers,

Grzesiek[/lang]

thanks man,

I copied entire code here and pasted in mq4 file, but when I copied it to experts folder it did not work, it did not created ex4 file and is not on in experts advisors manu. So please can you upload like mq4 file or is there any thing in the code,cause I tried several times

 

Detect Mouse Click x,y postions on chart

Is it possible to detect the postion of a mouse click in MT4? I'm not talking about WindowOnDrop. If I know the x,y screen coordinates, can I convert it to the corresponding Price/Time?

Thanks for your help.

Best regards,

Tiffany

 

Dear Friend

Today on Monday the code (old one which worked on thursday and friday) did not work at all

I manually entered trades,

 

Simple system: Need very little EA recommendation

Here is Logic

Trade when the range between GMT 02:00 and 10:00 is less than 60 pips then Open sell IF price breaks minimum - 5pips line or buy if price breaks maximum + 5 pips line. AND EXECUTE ONLY ONE TRADE PER DAY, IT DOES NOT MATTER TRADE IS CANCELED CLOSED AT STOP OR TAKEN PROFIT JUST ONE ORDER A DAY.

HERE IS CODE BUT IT DOES NOT WORK, IN EA MANU OF MT4 it has inactive icon and there is no ex4 file in experts folder, I could not understand what's wrong

extern double stopLoss = 300.0;

extern double takeProfit = 500.0;

extern string Begin = "2: 00";

extern string End = "10: 00";

extern double distance = 60;

bool isECN = true;

bool cond = false;

bool cond2 = false;

double low;

double high;

extern double lots = 0.1;

int magic = 1232344524285020;

int slippage = 1;

string comment = "";

int ticket;

int short = 0;

long int = 0;

//+------------------------------------------------------------------+

//| expert initialization function |

//+------------------------------------------------------------------+

int init()

{

//----

//----

(0) return;

}

//+------------------------------------------------------------------+

//| expert deinitialization function |

//+------------------------------------------------------------------+

int deinit ()

{

//----

Print (countOrders (magic, OP_BUY));

//----

(0) return;

}

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

int start()

{

Print (AccountCurrency ());

//----

if (isGoodTime (Begin, End))

{

short = 0;

long = 0;

if (! cond)

{

low = Bid;

high = Ask;

}

cond = true;

if (Bid < low) low = Bid;

if (Ask > high) high = Ask;

}

if ((high-low) * 1000 > distance)

{

cond2 = true;

}

if (! isGoodTime (Begin, End))

{

cond = false;

}

if (! isGoodTime (Begin, End) & & cond2)

{

if (countOrders (magic, OP_SELL) == 0)

{

if (Bid ≪ = (CRL-0.0005) & & short == 0)

{

short + +;

if (isECN == false)

{

OrderSend (Symbol (), OP_SELL, lots, Bid, slippage, sltpValue (Ask + stopLoss * Point, stopLoss), sltpValue (Ask-takeProfit * Point, takeProfit), comment, magic);

}

if (isECN)

{

ticket = OrderSend (Symbol (), OP_SELL, lots, Bid, slippage, 0,0, comment, magic);

OrderSelect (ticket, SELECT_BY_TICKET);

OrderModify (ticket, OrderOpenPrice (), sltpValue (Ask + stopLoss * Point, stopLoss), sltpValue (Bid-takeProfit * Point, takeProfit), 0);

}

}

}

if (countOrders (magic, OP_BUY) == 0)

{

if ((Ask-high) > = 0.005 & & long = = 0)

{

long + +;

if (isECN == false)

{

OrderSend (Symbol (), OP_BUY, lots, Ask, slippage, sltpValue (Ask-stopLoss * Point, stopLoss), sltpValue (Bid + takeProfit * Point, takeProfit), comment, magic);

}

if (isECN)

{

ticket = OrderSend (Symbol (), OP_BUY, lots, Ask, slippage, 0,0, comment, magic);

OrderSelect (ticket, SELECT_BY_TICKET);

OrderModify (ticket, OrderOpenPrice (), sltpValue (Bid-stopLoss * Point, stopLoss), sltpValue (Ask + takeProfit * Point, takeProfit), 0);

}

}

}

}

//----

(0) return;

}

//+------------------------------------------------------------------+

bool isGoodTime (string, string, Begin, End) {

if (TimeCurrent () > Localtime (Begin) & & TimeCurrent < Localtime () (End)) {

return (true);

}

return (false);

}

int countOrders (int, int oMagic oType) {

int count = 0;

for (int i = 0; i < OrdersTotal (); i ++) {

if (OrderSelect (i, SELECT_BY_POS)) {

if (OrderMagicNumber () == oMagic) {

if (OrderSymbol () = the = Symbol ()) {

if (OrderType () == oType || oType < 0) {

count ++;

}

}

}

}

}

return (count);

}

double sltpValue (double, int w1 w2)

{

if (w2 = = 0)

return (0);

return (NormalizeDouble (w1, Digits));

}

 

Forex.com EAs

I'm an idiot. I posted this to the wrong forum...and I don't know how to move it to the programming forum. I apologize for the inconvenience; the mistake was unintentional.

I've been trading spot forex for 3 years and have developed 2 EAs. These EAs run fine on Glocap, FXCM and Alpari (I'm a US resident, so my choice of brokers is somewhat limited). Further, I want a MT4 account with the commission built into the spread (personal preference).

I recently tested these EAs on a Forex.com (Gain Capital) demo account. Both EAs worked fine and traded according to the programmed rules. However, when I opened a live account with Forex.com, EA #1 no longer works properly, but EA #2 works fine. EA #1 works fine in the Forex.com strategy tester, but I know that doesn't count for much. This whole thing is very odd to me, because both EAs use the same code to open trades (the error on EA #1 comes when trying to open trades), set lot sizing, monitor trades and close trades. Here's a bit of information about both EAs:

EA #1 EUR/JPY Uses Ichimoku indicator

EA #2 EUR/USD Uses 3 moving averages and MACD

As I said before, EA #2 trades fine; works according to the programmed rules. When EA #1 tries to open some trades, I receive the following error message: 2011.11.21 17:00:02 Ichimoku_1700Eastern EURJPYpro,H1: Ichimoku_Open EA for EURJPYpro: Error opening BUY order : (133) trade is disabled /// for 103.7210

Additionally, when EA #2 tries to place a trade, the Experts log always shows that the std.lib is loading immediately before the trades that throw an error (this does not happen on EA #1):2011.11.21 17:00:02 stdlib EURJPYpro,H1: loaded successfully

Here's the final piece to this puzzle: EA #2 will open trades but not at 1700 Eastern. All of the errors thrown have occurred on trades trying to open at 1700 Eastern (this may be a coincidence).

I've ripped the EA apart; re-typed the code from scratch; copied code from EA #1 into EA #2 and nothing seems to fix the issue. Forex.com doesn't want to help as they consider this "EA support" which they don't offer. In what I can find on the Internet about this error, it means that either a) the broker doesn't allow EA trading (which I know is not true) or b) the trade is sending stops and/or limits which doesn't work with an Instant Execution broker (the trade is NOT sending stops or limits). Forex.com has said that they do NOT suspend trading at any time during the trading day.

My questions for this group are as follows:

1. Has anybody ever run into this issue?

2. If so, what did you do to resolve it?

3. If you've never seen this issue, what do you think could be causing it?

I'm sure this is something simple that I'm just not seeing. Any comments, tales of experience and thoughts from left field would be most appreciated.

Reason: