Ask! - page 82

 

Codersguru please help

Codersguru

i'm truying to write a sound alert for the bullspower indicator when crossing the zero line. i've no experience with MQL but put some code together from several other indicators. when compiling the code there is no error. though the indicator alert doesnt work could you please help for either correcting it or maybe put a new code for this sound alert when Bullbears crosses the zero line ?

thx a lot in advance

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

//| |

//| |

//| |

//| |

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

#property copyright "forex-tsd"

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

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_color1 Lime

#property indicator_color2 Crimson

#property indicator_level1 0

double ExtMapBuffer1[];

double ExtMapBuffer2[];

double valbull[];

double valbear[];

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

//| Custom indicator initialization function |

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

int init()

{

IndicatorBuffers(3);

SetIndexBuffer(0,ExtMapBuffer1);

SetIndexDrawBegin(0,2);

SetIndexLabel(0,"ExtMapBuffer1");

SetIndexBuffer(1,ExtMapBuffer2);

SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, 4);

SetIndexDrawBegin(1,2);

SetIndexLabel(1,"ExtMapBuffer2");

//---- indicators

//----

return(0);

}

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

//| Custor indicator deinitialization function |

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

int deinit()

{

//---- TODO: add your code here

//----

return(0);

}

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

//| Custom indicator iteration function |

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

int start()

{

int shift,counted_bars=IndicatorCounted();

double valbear[], valbull[];

//---- check for possible errors

if(counted_bars<0) return(-1);

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

if(counted_bars>0) counted_bars--;

shift=Bars-1;

while(shift>=0)

{

valbull[shift]=iBullsPower(NULL, 0, 13,PRICE_CLOSE,0);

valbear[shift]=iBearsPower(NULL, 0, 13,PRICE_CLOSE,0);

if (valbull[shift]>0)

{

ExtMapBuffer1[shift]=valbull[shift];

ExtMapBuffer2[shift]=0;

}

else

{

ExtMapBuffer2[shift]=valbull[shift];

ExtMapBuffer1[shift]=0;

}

shift--;//

}

//---- alert module

#define SIGNAL_BAR 1

//---- Static variables where the last bar time

//---- and the last alert direction are stored

static int PrevSignal = 0, PrevTime = 0;

//---- If the bar selected to be analyzed is not a zero bar,

// there is no sense to check the alert

//---- several times. If no new bar starts to be formed, quit.

if(SIGNAL_BAR > 0 && Time[0] <= PrevTime )

return(0);

//---- Mark that this bar was checked

PrevTime = Time[0];

if(PrevSignal <= 0)

{

if(valbull[SIGNAL_BAR] > 0 )

{

PrevSignal = 1;

Alert("BullChannell_positiv (", Symbol(), ", ", Period(), ") - BUY!!!");

}

}

if(PrevSignal >= 0)

{

if(valbull[SIGNAL_BAR] < 0 )

{

PrevSignal = -1;

Alert("BearChannell_negativ (", Symbol(), ", ", Period(), ") - SELL!!!");

}

}

//---- end alert module

//----

return(0);

}

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

 

How to use function to differentiate between opened orders and pending orders?

How to use function to differentiate between opened orders and pending orders?

Thanks.

 
vntb:
How to use function to differentiate between opened orders and pending orders? Thanks.

Check the OrderType() :

OrderType() == OP_BUY //BuyOrder (opened)

OrderType() == OP_SELL //Sell Order (opened)

OrderType() == OP_BUYLIMIT //Buy limit Order (pending)

OrderType() == OP_SELLLIMIT //Sell limit Order (pending)

OrderType() == OP_BUYSTOP //Buy stop Order (pending)

OrderType() == OP_SELLSTOP //Sell stop Order (pending)

 

iMAOnArray in EA

Hi folks,

I am trying to do an EMA based on crossings of moving averages on indicators (e.g., CCI, Force, RSI). However, I cannot fathom how to declare an array and run the iMAOnArray function to make variables.

For example, in the code below I want to put RSI data for the chart in a buffer and then utilize the data to produce a moving average with which to trigger trades. What am I doing wrong?

Thanks for any comments or suggestions.

autumn

double RSI[];

ArrayResize(RSI,Bars);

ArraySetAsSeries(RSI,true);

for(int i=Bars; i>=0; i--)

{

RSI = (iRSI(NULL,0,RSIPeriod,RSIPrice,i));

}

double Green0 = iMAOnArray(RSI,0,GreenPeriod,0,GreenPrice,0);

 

Hello

anyone has the step-momentum with alert?

It will be a great indicator i think

thanks

regards!

 

Close trade by level

Hi, I like to know how to close trade when price reached certain level. Say, 55 point above MA line. I tried to include the MA in the TakeProfit part of OrderSend, but tester reject my EA with: "invalid something" error message. Thank you.

 
Sendra:
Hi, I like to know how to close trade when price reached certain level. Say, 55 point above MA line. I tried to include the MA in the TakeProfit part of OrderSend, but tester reject my EA with: "invalid something" error message. Thank you.

First of all get the moving average:

double MA = iMA(...);

then calculate the TakeProfit like this:

double TP = MA + (55*Point); // or TP = MA-(55*Point); in the Sell case.

 

It works!!

Hey, thanks, CodersGuru. It does work. But it also makes me think: If I can move take profit to a certain level which isn't static, I can do the same with my stoploss (without using trailingstop).

And I tried.

It did work, with bad result. So, I guess I have to do with trailingstop. Is that correct? (Mind you, I haven't learn how to code trailingstop yet.)

thank you.

 

Internal trailing stop

Sendra:
Hey, thanks, CodersGuru. It does work. But it also makes me think: If I can move take profit to a certain level which isn't static, I can do the same with my stoploss (without using trailingstop).

And I tried.

It did work, with bad result. So, I guess I have to do with trailingstop. Is that correct? (Mind you, I haven't learn how to code trailingstop yet.)

thank you.

I did something like this for an internal trailing stop: (this is example for a long order) It seems to work. Hope this helps.

extern int Trailing_Stop=20;

static double Trailing_Long;

bool Read_Long_Open;

if (Insert your long entry decision)

{

Ordersend() function here

Read_Long_Open=true;

}

if (Read_Long_Open==true)

{

if(OrderSelect(T_1L, SELECT_BY_TICKET)==true)

{

Trailing_Long=OrderOpenPrice();

Print(" Trailing_Long =",Trailing_Long);

Read_Long_Open=false;

}

}

if (Read_Long_Open==false)

{

if (Trailing_Long < Bid)

{

Trailing_Long=Bid;

Print("Adjusted Trailing_Long =",Trailing_Long);

}

}

if (Bid <= Trailing_Long-Trailing_Stop*Point)

{

OrderClose() function

Print("Long Order Closed");

}

 

Thanks

Hi, Wolfe,

I tried your code, but got more negatif result instead. Please don't ask why, cos I don't know the answer either. Mind you, I'm still in hit-and-run phase in coding. But thanks anyway, your code had give me enough inspiration to write my own with enough result for me.

So, thanks.

Reason: