How to code? - page 278

 

I backtested it for 20 days and seems I would lost money

I will backtest for a year, let's see

but first of all I need if i can modify times by just changing value in extern string begin and extern string end?

 

Also what I noticed is that EA makes trades multiple times a day. So we must tell EA to make just one trade for first break out of this Min-Max -/+ 5 pips range. Also we must incorporate trailing stop instead of just stop loss.

Also question about numbers. Is not 300 equual to 300 pips? we need stop to be 30 pips and take profit 50 pips. Also what does magis = 123 means?

same question for this if(Bid<=(low-0.005)) 0.005 here is not 50 pips?

is not extern double stopLoss = 300.0;

extern double takeProfit = 500.0;

extern string Begin="02:00";

extern string End="10:00";

extern double distance = 80;

bool isECN = true;

bool cond = false;

bool cond2 = false;

double low;

double high;

extern double lots = 0.1;

int magic = 123;

int slippage = 1;

string comment = "";

int ticket;

 
Avasys:
Also what I noticed is that EA makes trades multiple times a day. So we must tell EA to make just one trade for first break out of this Min-Max -/+ 5 pips range. Also we must incorporate trailing stop instead of just stop loss.

Also question about numbers. Is not 300 equual to 300 pips? we need stop to be 30 pips and take profit 50 pips. Also what does magis = 123 means?

same question for this if(Bid<=(low-0.005)) 0.005 here is not 50 pips?

is not extern double stopLoss = 300.0;

extern double takeProfit = 500.0;

extern string Begin="02:00";

extern string End="10:00";

extern double distance = 80;

bool isECN = true;

bool cond = false;

bool cond2 = false;

double low;

double high;

extern double lots = 0.1;

int magic = 123;

int slippage = 1;

string comment = "";

int ticket;

[lang=pl]You are right there should be 0.0005 instead of 0.005. 300 and 500 is because i use five digits broker it's mean 300 poits so 30 pips.

Please tell me want kind of trailing stop you need ? about magic numer. As you can see i change you magic if you dont like 123 [/lang]

Files:
simple_ea.mq4  4 kb
 
g.pociejewski:
[lang=pl]You are right there should be 0.0005 instead of 0.005. 300 and 500 is because i use five digits broker it's mean 300 poits so 30 pips. Please tell me want kind of trailing stop you need ? about magic numer. As you can see i change you magic if you dont like 123 [/lang]

Thanks

so does this EA now makes trades only once in a day, so break out of the levels may occur few times through day but it may only trade once.

Also regarding EURJPY as it is high value currency, I still use same numbering or I move 00?

and also can I myself change or modify numbers stop loss, take profit, times

regarding trailing stop. I would like when profit rises 35 pips trailing stop must follow to lock the profit.

so what if I change here:

extern double stopLoss = 300.0; (I use 4 digits broker so, should I modify this?)

extern double takeProfit = 500.0;

extern string Begin="0:00"; (whet happens if I want to make time range 22:00 of previous day and 06:00 current day?)

extern string End="08:15";

extern double distance = 60;

bool isECN = true;

bool cond = false;

bool cond2 = false;

double low;

double high;

extern double lots = 0.1;

int magic = 123;

int slippage = 1;

string comment = "";

int ticket;

also what if I change this

if(Bid<=(low-0.005))

It may not affect functionality of code right?

The only problem it has when I try to backtest I got that as if EA executed few trades in one day, so can you manage in code to execute only one trade for one pair per day

 

Hello Again

OK I found out that distance must be not 80 for the pairs like GBPUSD which has lower value than JPY pairs so in case of JPY pairs distance must be 10X than for low value pairs.

and again, I could not understand one thing when I backtest it in result it states as if EA traded multiple times in one day on the same pair.

So is it possible that if EA entered in position this position must be only one that day?

thanks

Also what is meaning of the following:

int slippage= 1;

string comment = "";

int ticket;

and also could I add script into the EA and when trade executed it is sms-ed or e-mailed to me?

thanks

 

StopTrading for today, if one order is in history listed

Hi,

maybe someone can guide me to do:

- Order is executed, closed in profit or loss and listed in history

- now i want to disable trading/stop open new orders on this pair (symbol) for the whole day

- next day, a new order can be executed

its like a "Max Trades Per Bar" function, but based on history.

serveral different tested code snippets fail, because i lack on extended coding skills

example:

1 2008.01.07 02:36 sell 1 0.10 1.4730 0.0000 0.0000 0.00 10000.00

2 2008.01.07 03:14 close 1 0.10 1.4714 0.0000 0.0000 16.00 10016.00

3 2008.01.07 03:14 sell 2 0.10 1.4712 0.0000 0.0000 0.00 10016.00

4 2008.01.07 07:54 close 2 0.10 1.4672 0.0000 0.0000 40.00 10056.00

5 2008.01.07 07:54 sell 3 0.10 1.4671 0.0000 0.0000 0.00 10056.00

6 2008.01.09 15:56 close 3 0.10 1.4663 0.0000 0.0000 7.04 10063.04

7 2008.01.10 14:24 buy 4 0.10 1.4708 0.0000 0.0000 0.00 10063.04

8 2008.01.10 14:47 close 4 0.10 1.4748 0.0000 0.0000 40.50 10103.54

any help is very appreciated

regards

Michael

 
ixbone:
Hi,

maybe someone can guide me to do:

- Order is executed, closed in profit or loss and listed in history

- now i want to disable trading/stop open new orders on this pair (symbol) for the whole day

- next day, a new order can be executed

its like a "Max Trades Per Bar" function, but based on history.

serveral different tested code snippets fail, because i lack on extended coding skills

example:

1 2008.01.07 02:36 sell 1 0.10 1.4730 0.0000 0.0000 0.00 10000.00

2 2008.01.07 03:14 close 1 0.10 1.4714 0.0000 0.0000 16.00 10016.00

3 2008.01.07 03:14 sell 2 0.10 1.4712 0.0000 0.0000 0.00 10016.00

4 2008.01.07 07:54 close 2 0.10 1.4672 0.0000 0.0000 40.00 10056.00

5 2008.01.07 07:54 sell 3 0.10 1.4671 0.0000 0.0000 0.00 10056.00

6 2008.01.09 15:56 close 3 0.10 1.4663 0.0000 0.0000 7.04 10063.04

7 2008.01.10 14:24 buy 4 0.10 1.4708 0.0000 0.0000 0.00 10063.04

8 2008.01.10 14:47 close 4 0.10 1.4748 0.0000 0.0000 40.50 10103.54

any help is very appreciated

regards

Michael

[lang=pl]Hi Michael,

One question, do you need to stop open new positions if any positions in current day is closed, or you not allow for example open short if any short

is closed on stop ? There ios any example how to make it in the case of OP_BUY(for others is similar)

int time;

bool cond = true;

double stopLoss = 50;

double takeProfit = 70;

double lots = 0.1;

int orders = 0;

int magic = 123;

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

//| expert initialization function |

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

int init()

{

//----

//----

return(0);

}

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

//| expert deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

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

//| expert start function |

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

int start()

{

Print(countOrders(magic, OP_BUY));

if(orders !=countOrders(magic,OP_BUY)) cond = false;

if(time != DayOfWeek()) cond = true;

if(cond) {

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

}

orders = countOrders(magic,OP_BUY);

time = DayOfWeek();

//----

return(0);

}

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));

}

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

I hope that it's clear. In the case of any questions contact me please.

Cheers,

Grzesiek[/lang]

 

Hi Grzesiek,

yes only stop opening new positions in the current day, it doesnt matter if buy, sell, pending or canceled:

- if a order is closed in profit, loss, canceled or pending deleted and noted in the history - no new trades of any kind are allowed for this symbol() at the current day

- if we have a new day, all kind of new orders can be executed.

what i have done, isnt working:

extern bool Only1OrderPerDay=true;

if(Only1OrderPerDay==true){

CountHistoryOrders();

}

void CountHistoryOrders(){

for(int d=0;d<OrdersHistoryTotal();d++){

OrderSelect(d,SELECT_BY_POS,MODE_HISTORY);{

if(OrderSymbol()==Symbol() && (OrderMagicNumber()==Magic || Magic==0))d++;

Print("HistoryOrders "+DoubleToStr(d,0));

{

if(d>0 ....time?...){

return;

}}}}}

thanks for help

Michael

g.pociejewski:
[lang=pl]Hi Michael,

One question, do you need to stop open new positions if any positions in current day is closed, or you not allow for example open short if any short

is closed on stop ? There ios any example how to make it in the case of OP_BUY(for others is similar)

int time;

bool cond = true;

double stopLoss = 50;

double takeProfit = 70;

double lots = 0.1;

int orders = 0;

int magic = 123;

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

//| expert initialization function |

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

int init()

{

//----

//----

return(0);

}

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

//| expert deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

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

//| expert start function |

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

int start()

{

Print(countOrders(magic, OP_BUY));

if(orders !=countOrders(magic,OP_BUY)) cond = false;

if(time != DayOfWeek()) cond = true;

if(cond) {

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

}

orders = countOrders(magic,OP_BUY);

time = DayOfWeek();

//----

return(0);

}

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));

}

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

I hope that it's clear. In the case of any questions contact me please.

Cheers,

Grzesiek[/lang]
 

Drag and Drop Stop Loss

Hello

I have Drag and Drop Stop loss script, and a love to use it. But with my broker dose not work for 2 orders in a same scart only set 1 order. I want to set stop loss for 2 orders in same place.

What is the problem ? It is work fine for other broker.

Please help

int start()

{

//----

int digits = MarketInfo(Symbol(),MODE_DIGITS);

double value = NormalizeDouble(WindowPriceOnDropped(),digits);

for(int i=OrdersTotal()-1;i>=0;i--)

{

if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

continue;

if(OrderSymbol()!=Symbol())

continue;

RefreshRates();

if(OrderType()==OP_BUY)

if(value<Bid)

OrderModify(OrderTicket(),OrderOpenPrice(),value, OrderTakeProfit(),OrderExpiration(),White);

if(OrderType()==OP_SELL)

if(value>Ask)

OrderModify(OrderTicket(),OrderOpenPrice(),value, OrderTakeProfit(),OrderExpiration(),White);

if((OrderType()==OP_BUYSTOP) || (OrderType()==OP_BUYLIMIT))

if(value<OrderOpenPrice())

OrderModify(OrderTicket(),OrderOpenPrice(),value, OrderTakeProfit(),OrderExpiration(),White);

if((OrderType()==OP_SELLSTOP) || (OrderType()==OP_SELLLIMIT))

if(value>OrderOpenPrice())

OrderModify(OrderTicket(),OrderOpenPrice(),value, OrderTakeProfit(),OrderExpiration(),White);

}

return(0);

}

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

 

How can I find the X Y co ordinate position of two dissimilar indicators in an EA to buy and sell where the cross

say a Macd and another indicator in the same sub-window?

Reason: