How to code? - page 334

 

HI guys,

I can't draw Envelopes on Array

I can draw Bollinger band without any problems.

I want to draw the envelopes on CCI indicator.

I've drawn with Bollingerbands with the attach code and it works,

the only problem is drawing with Envelopes on the cci indicator.

Please help.

Files:
cci_env.mq4  3 kb
 
luffy:
HI guys,

I can't draw Envelopes on Array

I can draw Bollinger band without any problems.

I want to draw the envelopes on CCI indicator.

I've drawn with Bollingerbands with the attach code and it works,

the only problem is drawing with Envelopes on the cci indicator.

Please help.

luffy

It can not be done without coding envelopes for each and every indicator value you wish yo apply envelopes to

 
mladen:
luffy It can not be done without coding envelopes for each and every indicator value you wish yo apply envelopes to

Hi Mladen

I appreciate your great help to as unable to program.

I have a problem with the attached Macd3 which does only refresh if I get it edited and the close it again.

It would be big help if it would refresh with every bar closed. I hope you can find a solution.

BTW this is a very nice indicator in regard to get the turning point early!

Files:
macd_3m.ex4  17 kb
macd_3m.mq4  5 kb
 
wolfsch:
Hi Mladen

I appreciate your great help to as unable to program.

I have a problem with the attached Macd3 which does only refresh if I get it edited and the close it again.

It would be big help if it would refresh with every bar closed. I hope you can find a solution.

BTW this is a very nice indicator in regard to get the turning point early!

wolfsch

It works OK on my terminal (tested it on a 1 minute chart and it did all OK - I am using build 788)

 
wolfsch:
Hi Mladen

I appreciate your great help to as unable to program.

I have a problem with the attached Macd3 which does only refresh if I get it edited and the close it again.

It would be big help if it would refresh with every bar closed. I hope you can find a solution.

BTW this is a very nice indicator in regard to get the turning point early!

Woks for me too

 
luffy:
HI guys,

I can't draw Envelopes on Array

I can draw Bollinger band without any problems.

I want to draw the envelopes on CCI indicator.

I've drawn with Bollingerbands with the attach code and it works,

the only problem is drawing with Envelopes on the cci indicator.

Please help.

luffy

Try it out now : cci_env_1.mq4

Files:
cci_env_1.mq4  3 kb
cci_env.gif  71 kb
 

Hi, i am trying to set my ea to auto close all my open trades at a specific timing. and was wondering if someone could help shed me some light on this matter? thanks.

Regards

Ryan

 
tkuan77:
Hi, i am trying to set my ea to auto close all my open trades at a specific timing. and was wondering if someone could help shed me some light on this matter? thanks.

Regards

Ryan

Ryan

Check this one : https://www.mql5.com/en/forum/177401/page2

Don't worry for the two compiler warning when compiling the code - they are benign

 

Hi mladen, I tried to input the part about closing trade based on timing and compile, it does give me warning as you mention, however, when i run the code, it does not close off the trade at the timing i specified.

Not too sure what could be the error here. Hope you could enlighten me on where I might be wrong here.

Regards

Ryan

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

//| Forex TSD - forex forum |

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

#property copyright "R Creation"

#property link "https://www.forex-tsd.com"

//---- input parameters

extern double TakeProfit = 200.0;

extern double Lots = 0.1;

extern double StopLoss = 200.0;

extern int PreferredHour_1st = 5;

extern int PreferredMinute_1st = 30;

int magicNo_1st = 530;

extern bool UseCurrSymbol = False; // not too sure what is this for.....

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

//| expert initialization function |

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

int init()

{

//----

//----

return(0);

}

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

//| expert deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

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

//| expert start function |

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

datetime newbar;

double pBid, pAsk;

int start()

{

if(newbar==Time[0])return(0);

else newbar=Time[0];

int ticket, total;

if(Bars<100)

{

Print("bars less than 100");

return(0);

}

if(TakeProfit<10)

{

Print("TakeProfit less than 10");

return(0); // check TakeProfit

}

double Fast_MA, Slow_MA;

Fast_MA = iMA(NULL,0,7,0,MODE_EMA,PRICE_CLOSE,0);

Slow_MA = iMA(NULL,0,30,0,MODE_EMA,PRICE_CLOSE,0);

total = OrdersTotal(); // check for total number of trades currently open

if(total < 1)

{

if (Hour()==PreferredHour_1st && Minute()==PreferredMinute_1st && Seconds()==0 && Fast_MA > Slow_MA)

{

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,1,Ask-StopLoss*Point,Ask+TakeProfit*Point,

"My EA",magicNo_1st,0,Green);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());

}

else Print("Error opening BUY order : ",GetLastError());

return(0);

}

if (Hour()==PreferredHour_1st && Minute()==PreferredMinute_1st && Seconds()==0 && Fast_MA < Slow_MA)

{

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,1,Bid+StopLoss*Point,Bid-TakeProfit*Point,

"My EA",magicNo_1st,0,Red);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());

}

else Print("Error opening SELL order : ",GetLastError());

return(0);

}

return(0);

}

if(total > 1) //to close off orders based on timing... not yet resolved.

{

if (Hour()==7 && Minute()==0 && Seconds()==0)

{

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

{

if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

{

if (!UseCurrSymbol || OrderSymbol()==Symbol())

{

if (OrderType()==OP_BUY)

{

pBid=MarketInfo(OrderSymbol(),MODE_BID);

OrderClose(OrderTicket(),OrderLots(),pBid,1,Blue);

}

if (OrderType()==OP_SELL)

{

pAsk=MarketInfo(OrderSymbol(),MODE_ASK);

OrderClose(OrderTicket(),OrderLots(),pAsk,1,Red);

}

}

}

}

}

}

return(0);

}

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

 
tkuan77:
Hi mladen, I tried to input the part about closing trade based on timing and compile, it does give me warning as you mention, however, when i run the code, it does not close off the trade at the timing i specified.

Not too sure what could be the error here. Hope you could enlighten me on where I might be wrong here.

Regards

Ryan

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

//| Forex TSD - forex forum |

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

#property copyright "R Creation"

#property link "https://www.forex-tsd.com"

//---- input parameters

extern double TakeProfit = 200.0;

extern double Lots = 0.1;

extern double StopLoss = 200.0;

extern int PreferredHour_1st = 5;

extern int PreferredMinute_1st = 30;

int magicNo_1st = 530;

extern bool UseCurrSymbol = False; // not too sure what is this for.....

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

//| expert initialization function |

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

int init()

{

//----

//----

return(0);

}

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

//| expert deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

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

//| expert start function |

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

datetime newbar;

double pBid, pAsk;

int start()

{

if(newbar==Time[0])return(0);

else newbar=Time[0];

int ticket, total;

if(Bars<100)

{

Print("bars less than 100");

return(0);

}

if(TakeProfit<10)

{

Print("TakeProfit less than 10");

return(0); // check TakeProfit

}

double Fast_MA, Slow_MA;

Fast_MA = iMA(NULL,0,7,0,MODE_EMA,PRICE_CLOSE,0);

Slow_MA = iMA(NULL,0,30,0,MODE_EMA,PRICE_CLOSE,0);

total = OrdersTotal(); // check for total number of trades currently open

if(total < 1)

{

if (Hour()==PreferredHour_1st && Minute()==PreferredMinute_1st && Seconds()==0 && Fast_MA > Slow_MA)

{

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,1,Ask-StopLoss*Point,Ask+TakeProfit*Point,

"My EA",magicNo_1st,0,Green);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());

}

else Print("Error opening BUY order : ",GetLastError());

return(0);

}

if (Hour()==PreferredHour_1st && Minute()==PreferredMinute_1st && Seconds()==0 && Fast_MA < Slow_MA)

{

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,1,Bid+StopLoss*Point,Bid-TakeProfit*Point,

"My EA",magicNo_1st,0,Red);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());

}

else Print("Error opening SELL order : ",GetLastError());

return(0);

}

return(0);

}

if(total > 1) //to close off orders based on timing... not yet resolved.

{

if (Hour()==7 && Minute()==0 && Seconds()==0)

{

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

{

if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

{

if (!UseCurrSymbol || OrderSymbol()==Symbol())

{

if (OrderType()==OP_BUY)

{

pBid=MarketInfo(OrderSymbol(),MODE_BID);

OrderClose(OrderTicket(),OrderLots(),pBid,1,Blue);

}

if (OrderType()==OP_SELL)

{

pAsk=MarketInfo(OrderSymbol(),MODE_ASK);

OrderClose(OrderTicket(),OrderLots(),pAsk,1,Red);

}

}

}

}

}

}

return(0);

}

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

This part

if(newbar==Time[0])return(0);

else newbar=Time[0];

int ticket, total;

if(Bars<100)

{

Print("bars less than 100");

return(0);

}

if(TakeProfit<10)

{

Print("TakeProfit less than 10");

return(0); // check TakeProfit

}

Is preventing the ea to close orders at certain time if it is not a first tick of a new bar and if the profit is not > 10 pips

Reason: