How to code? - page 167

 
 

Still trying to add an audible alert to this indicator...... Can someone check the code for me as it is not working?

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

//|

//|

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

#property copyright "niva"

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_color1 White

#property indicator_color2 Red

extern bool Email_Enabled = false;

extern bool Alert_Enabled = true;

//---- input parameters

int CountBars=10000;

//---- buffers

double uptrend[];

double downtrend[];

bool AlertSent,EmailSent;

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

//| Custom indicator initialization function |

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

int init()

{

//---- indicator line

IndicatorBuffers(2);

SetIndexStyle(0,DRAW_ARROW);

SetIndexArrow(0,217);

SetIndexStyle(1,DRAW_ARROW);

SetIndexArrow(1,218);

SetIndexBuffer(0,val1);

SetIndexBuffer(1,val2);

//----

return(0);

}

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

//| AltrTrend_Signal_v2_2 |

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

int start()

{

if (CountBars>=Bars) CountBars=Bars;

int i,shift,counted_bars=IndicatorCounted();

int uptrend, downtrend;

for (shift = CountBars; shift>=0; shift--)

{

if(High[shift-1]>High[shift]&&Low[shift-1]>Low[shift]&&uptrend!=3){

uptrend = uptrend+1;

downtrend=0;

}else if(High[shift-1]<High[shift]&&Low[shift-1]<Low[shift]&&downtrend!=3){

downtrend=downtrend+1;

uptrend=0;

}

else{

uptrend=0;

downtrend=0;

}

if (uptrend==3)

{

val1[shift]=Low[shift];

}

if (downtrend==3)

{

val2[shift]=High[shift];

}

}

return(0);

}

//----

if (Alert_Enabled && (uptrend[0] != 0 || uptrend[0] !=0) && !AlertSent)

{

Alert(Symbol() + "HiLow+3");

AlertSent=true;

}

if (Email_Enabled && (downtrend[0] != 0 || downtrend[0] !=0) && !EmailSent)

{

SendMail(Symbol() + "HiLow+3","HiLow+3 indicator triggered");

EmailSent=true;

}

if(downtrend[0] == 0 && uptrend[0] == 0 )

{

EmailSent=false;

AlertSent=false;

}

return(0);

}

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

Thanks

mrwobbles:
Somewhere in the code the brackets are unbalanced. Sounds like somewhere a } and a ) are missing from the code. You'll need to look through and count how many open and closed brackets there are (+1 for open and -1 for closed) that should tell you how many are missing (say a +2 count mean two right brackets '}' or vice versa). If he indented properly you should be able to figure out where to put the right } in. Happy hunting The

I managed to change some settings and finally I believe to be almost there! Now after the following coding it says:

'shortSL' - variable not defined

'longSL' - variable not defined

Here is what it looks like:

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

//| Salgado.mq4 |

//| salgadoguilherme@hotmail.com|

//| |

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

#property copyright ""

#property link "salgadoguilherme@hotmail.com"

extern bool trade=true;

extern int barstocount=50;

extern double lots=0.01;

extern int StopLoss =40;

extern int TakeProfit =10;

extern int slippage=3;

extern int magicnumber=816;

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

//| expert initialization function |

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

int init()

{

//----

//----

return(0);

}

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

//| expert deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

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

//| expert start function |

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

int start()

{

//----

if(trade==true)

{

//M15

double M15_resistance=iCustom(NULL,PERIOD_M15,"!LinRegrBuf","true",barstocount,2,0);

double M15_resistance_p=iCustom(NULL,PERIOD_M15,"!LinRegrBuf","true",barstocount,2,barstocount-1);

double M15_line=iCustom(NULL,PERIOD_M15,"!LinRegrBuf","true",barstocount,0,0);

double M15_support=iCustom(NULL,PERIOD_M15,"!LinRegrBuf","true",barstocount,1,0);

double slopeM15=((M15_resistance-M15_resistance_p)/barstocount)/Point;

//Alert(DoubleToStr(slopeM15,2);

Comment(

"\n","M15 Slope | ",slopeM15,

//SHORT ENTRY

if(slopeM15<0 && IsTradeAllowed()==true)

{

bool shortopen=false;

int ord_cnt1=OrdersTotal();

for (int start1=0;start1<ord_cnt1;start1++)

{

OrderSelect(start1, SELECT_BY_POS, MODE_TRADES);

if(OrderMagicNumber()==magicnumber && OrderType()==OP_SELL)

{shortopen=true;}

}

if(shortopen==false)

{

double M15High=iHigh(Symbol(),PERIOD_M15,0);

if(M15High>=M15_resistance)

int shortticket=OrderSend(Symbol(),OP_SELL,lots,Bid,slippage,Bid+shortSL,M15_line,DoubleToStr(slopeM15,2);

if(shortticket<0)

{

//LONG ENTRY

if(slopeM15>0 && IsTradeAllowed()==true)

{

bool longopen=false;

int ord_cnt=OrdersTotal();

for (int start=0;start<ord_cnt;start++)

{

OrderSelect(start, SELECT_BY_POS, MODE_TRADES);

if(OrderMagicNumber()==magicnumber && OrderType()==OP_BUY)

{longopen=true;}

}

if(longopen==false)

{

double M15Low=iLow(Symbol(),PERIOD_M15,0);

if(M15Low<=M15_support)

int longticket=OrderSend(Symbol(),OP_BUY,lots,Ask,slippage,Ask-longSL,M15_line,DoubleToStr(slopeM15,2);

if(longticket<0)

{

//----

return(0);

}

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

 

Candle-type Indy

Hi,

I'm badly in need of MQL tutorials on how to code candle-type indicators such as the attached chart. Just the links to somewhere within or outside this forum will be fine. Thanks so much.

Piper.

Files:
ma_candles.gif  15 kb
 

Could someone tell me how to code the following;

Count the number of bars since a short-term MA has crossed a long-term MA.

Thank you!

 

EA code to resume trades after shut down.

Hi,

Is there any sample code for an EA, that can resume managing the trades after its stopped and then comes back again?

Thanks,

JForex

 

How to code?

darvasboxes:
Could someone tell me how to code the following;

Count the number of bars since a short-term MA has crossed a long-term MA.

Thank you!

Yep!

Count the bars since they crossed:

int i;

bool shortGreater = (iMA(NULL,0,8,8,MODE_SMMA,PRICE_MEDIAN,0) > iMA(NULL,0,24,8,MODE_SMMA,PRICE_MEDIAN,0));

bool sgLast;

for(i=0;i<iBars(NULL,0);i++) {

sgLast = shortGreater;

shortGreater = (iMA(NULL,0,8,8,MODE_SMMA,PRICE_MEDIAN,i) > iMA(NULL,0,24,8,MODE_SMMA,PRICE_MEDIAN,i));

if(shortGreater !== sgLast) {

break;

}

}

The variable i will contain then number of bars since they crossed.

Feel free to send me some cash if you found it helpful. I'd appreciate it.

 

Here you go.

Guilhermesalgado:
I managed to change some settings and finally I believe to be almost there! Now after the following coding it says:

'shortSL' - variable not defined

'longSL' - variable not defined

Here you go. I took what you did and modified it so it compiled. Beware, your logic is bad, appears incomplete, and it probably won't do what you want.

But there you go.

- ChazzMoney

P.S. $170 is EXTREMELY cheap for a program. I write custom investment software once or twice a year for five figures. Programmers who take on this kind of work should beware - you need to check EVERYTHING to make sure you don't miss a case. A bug is as good as a random trader.

Feel free to send me some cash if you found it helpful. I appreciate the thought.

Files:
 

code from standard ZigZag

Hi

this code is from standard "ZigZag.mq4"

"if (counted_bars==0 && downloadhistory) // history was downloaded"

counted_bars==0 : checking if the value is equal to zero........ its ok.

downloadhistory : there is no condition check why ??? please clear this

Thanks.

 

Opening 2 ORDERS and Closing 2 ORDERS..CONSISTENTLY.

I've been trying and TRYING for a long time to get my EA to Always open two orders for a buy OR sell. One with TP and the other with NONE. After opening 2 orders then don't open anymore UNTIL time to trade in opposite direction.

For SOME REASON, i look at account history and i see 1 order then 3 orders then 4 oders then 2 orders and it's running like garbage.

Can ANY Coding Masters here take a peek and give me input?

Thank YOU!!!!!!!!!!!!!!!!

OPEN ORDERS

-------

BuyTicket1 = False;

BuyTicket2 = False;

while (!BuyTicket1) {

BuyTicket1 = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLoss, Ask + TakeProfit * Point, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);

Sleep(PausebetweenOrders * 1000);}

//if (BuyTicket1 && SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open 1st Buy");

Sleep(1000);

while (!BuyTicket2) {

BuyTicket2 = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLoss, 0, "2nd Buy(#" + MagicNumber + ")", MagicNumber, 0, BlueViolet);

Sleep(PausebetweenOrders * 1000);}

------------

CLOSE ORDERS

------------

if(OrdersTotal() > 0) {

OrderSelect(0, SELECT_BY_POS, MODE_TRADES);

if(OrderType() == OP_SELL){

for (int j = OrdertotalCloseSell-1; j >= 0; j --) {

PositionClosedSell = False;

AttemptsTriedCloseSell = 0;

OrderSelect(j, SELECT_BY_POS, MODE_TRADES);

while (!PositionClosedSell && AttemptsTriedCloseSell < CloseposnAttempts) {

AttemptsTriedCloseSell = AttemptsTriedCloseSell + 1;

OrderCloseSell = OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, MediumSeaGreen);

Sleep(PausebetweenOrders * 1000);

if( OrderCloseSell == True ) { // Position Closed Successful.