Need help with coding please - page 8

 

Jo

Something like this :

if (MACD[0]>MACD[1]) Alert("Message to use for alert"):
Jovager:
Hello,

How can I code an alert in an indicator ?

For example, how alert when MACD[0]>MACD[1]?

Thanks for help.

Jo
 
mladen:
Jo

Something like this :

if (MACD[0]>MACD[1]) Alert("Message to use for alert"):

Thanks Mladen, but where ?

I had the messages :

Red -If_function not defined

Red-Alert_Semicolon expected

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

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_color1 Silver

#property indicator_color2 Red

#property indicator_width1 2

//---- indicator parameters

extern int FastEMA=12;

extern int SlowEMA=26;

extern int SignalSMA=9;

//---- indicator buffers

double MacdBuffer[];

double SignalBuffer[];

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

//| Custom indicator initialization function |

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

int init()

{

//---- drawing settings

SetIndexStyle(0,DRAW_HISTOGRAM);

SetIndexStyle(1,DRAW_LINE);

SetIndexDrawBegin(1,SignalSMA);

IndicatorDigits(Digits+1);

//---- indicator buffers mapping

SetIndexBuffer(0,MacdBuffer);

SetIndexBuffer(1,SignalBuffer);

//---- name for DataWindow and indicator subwindow label

IndicatorShortName("MACD("+FastEMA+","+SlowEMA+","+SignalSMA+")");

SetIndexLabel(0,"MACD");

SetIndexLabel(1,"Signal");

//---- initialization done

return(0);

}

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

//| Moving Averages Convergence/Divergence |

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

int start()

{

int limit;

int counted_bars=IndicatorCounted();

//---- last counted bar will be recounted

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

//---- macd counted in the 1-st buffer

for(int i=0; i<limit; i++)

MacdBuffer=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);

//---- signal line counted in the 2-nd buffer

for(i=0; i<limit; i++)

SignalBuffer=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);

//---- done

return(0);

}

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

 

Right before the last return in your code (that way you ensure that it is executed only when all the rest of processing is done)

Jovager:
Thanks Mladen, but where ?

I had the messages :

Red -If_function not defined

Red-Alert_Semicolon expected

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

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_color1 Silver

#property indicator_color2 Red

#property indicator_width1 2

//---- indicator parameters

extern int FastEMA=12;

extern int SlowEMA=26;

extern int SignalSMA=9;

//---- indicator buffers

double MacdBuffer[];

double SignalBuffer[];

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

//| Custom indicator initialization function |

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

int init()

{

//---- drawing settings

SetIndexStyle(0,DRAW_HISTOGRAM);

SetIndexStyle(1,DRAW_LINE);

SetIndexDrawBegin(1,SignalSMA);

IndicatorDigits(Digits+1);

//---- indicator buffers mapping

SetIndexBuffer(0,MacdBuffer);

SetIndexBuffer(1,SignalBuffer);

//---- name for DataWindow and indicator subwindow label

IndicatorShortName("MACD("+FastEMA+","+SlowEMA+","+SignalSMA+")");

SetIndexLabel(0,"MACD");

SetIndexLabel(1,"Signal");

//---- initialization done

return(0);

}

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

//| Moving Averages Convergence/Divergence |

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

int start()

{

int limit;

int counted_bars=IndicatorCounted();

//---- last counted bar will be recounted

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

//---- macd counted in the 1-st buffer

for(int i=0; i<limit; i++)

MacdBuffer=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);

//---- signal line counted in the 2-nd buffer

for(i=0; i<limit; i++)

SignalBuffer=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);

//---- done

return(0);

}

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

Pls fix Zero divide error when using timeframe as "0"

pivot_crazy.mq4Could someone please fix the zero divide error when using the timeframe as "0"

Thanks.

Files:
 

Try it out. It is corrected now

privateer:
pivot_crazy.mq4Could someone please fix the zero divide error when using the timeframe as "0" Thanks.
Files:
 

Thank u mladen works like a charm

mladen:
Try it out. It is corrected now

thank u mladen works like a charm

 

i need help with this ea its has martingale function but doesnt work propely for example if a position its closed in a loss martingale function should multiplie the lots of the last position closed in a loss but there its an error in the code whitch make the martingale to work propely here its the eauniversalmacrossea.mq4

Files:
 

That way of opening new order after a loss is not a martingale + martingale works with opened positions

blondutrader:
i need help with this ea its has martingale function but doesnt work propely for example if a position its closed in a loss martingale function should multiplie the lots of the last position closed in a loss but there its an error in the code whitch make the martingale to work propely here its the eauniversalmacrossea.mq4
 

How can I calculate my lotsize, when I want to trader with every trade f.e. 5% of my money?

 

sunshineh,

Try using this function :

double getLots(string symbol, double Risk, double stopLossDistance)

{

RefreshRates();

double lots = 0;

double MinLots = NormalizeDouble(MarketInfo(symbol,MODE_MINLOT) ,2);

double MaxLots = NormalizeDouble(MarketInfo(symbol,MODE_MAXLOT) ,2);

double LotStep = NormalizeDouble(MarketInfo(symbol,MODE_LOTSTEP),2);

int LotDigit = 2;

if(MarketInfo(symbol,MODE_DIGITS)==3 || MarketInfo(symbol,MODE_DIGITS)==5) stopLossDistance *= 10.0;

//

//

//

//

//

if (LotStep==1) LotDigit=0;

if (LotStep==0.1) LotDigit=1;

if (LotStep==0.01) LotDigit=2;

if (Risk>0)

{

if (AccountBalance()>AccountFreeMargin())

lots = NormalizeDouble(AccountFreeMargin()*(Risk/100.0)/(stopLossDistance*MarketInfo(symbol,MODE_TICKVALUE)),LotDigit);

else lots = NormalizeDouble(AccountBalance() *(Risk/100.0)/(stopLossDistance*MarketInfo(symbol,MODE_TICKVALUE)),LotDigit);

}

//

//

//

//

//

lots = NormalizeDouble(NormalizeDouble(lots/LotStep,0)*LotStep,LotDigit);

lots = MathMax(MathMin(lots,MaxLots),MinLots);

return(lots);

}
sunshineh:
How can I calculate my lotsize, when I want to trader with every trade f.e. 5% of my money?