Ask! - page 163

 
jizhong68:
Dear Guru,

I am using a two dimension array, say, ZigZag[2][100]. and I want to sort by the first dimension. I use the following function:

ArraySort(ZigZag,WHOLE_ARRAY,0,MODE_DESCEND);

but it seem neither sort by first dimention, nor by second dimension. is there anybody here can help me?

Thanks a lot

The MQL docs states ArraySort sorts by first dimension, if you are not getting the right results, post your input and output of the array.

Writing a simple quicksort function wouldn't take too much time. Create a new array, store the sorted results, then do a for loop to lookup ZigZag and copy the second dimension over. Inefficient, probably, but it does the job.

 

here is the code

beckham.is.619:
The MQL docs states ArraySort sorts by first dimension, if you are not getting the right results, post your input and output of the array. Writing a simple quicksort function wouldn't take too much time. Create a new array, store the sorted results, then do a for loop to lookup ZigZag and copy the second dimension over. Inefficient, probably, but it does the job.

Thanks for your reply.

I want to calculate and display the support and ressistance lines in a chart. the algorithm of which is the find 100 ZigZag in the history and count the weight of each ZigZag. how to calculate the weight of each ZigZag? For each ZigZag, I try to search all the array to find the quantity of other ZigZags the value of which is 5 Points close to this certain ZigZag, say, if one certain ZigZag is 1.5000, then I want to find all other ZigZags which the distance of these two ZigZag is within 5 Points, if so, I add 1 count to this certain ZigZag, and I do that for all 100 ZigZags.

when I finish this, I try to sort all these ZigZags by the counter dimension. as you can find in the indicator. but I tried a lot by print the value before and after ArraySort(0 function was excuted. find no difference.

I post the indicator for your reference.

Thanks in advance.

here is the code for the Indicater:

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

//| Risisstance and Support.mq4 |

//| Copyright ?200 |

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

#property copyright "Copyright ?2006, Nick Bilak"

// hacked into a channel ind. by t_david sometime in early 2007

#property indicator_chart_window

extern int Gap = 5;

extern int Depth = 24;

extern int Deviation=5;

extern int BackStep=3;

extern int BackStart=288;

int ZigN=100;

double ZigZag[2][100];

int ShowBars = 500;

int dist=24;

int init() {

return(0);

}

int start() {

int k,i,j,limit,hhb,llb;

int counted_bars=IndicatorCounted();

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

if(counted_bars>0) counted_bars--;

ShowBars=Bars-counted_bars;

FindZigZag();

ResistanceSupport();

// for(i=0;i<10;i++)

{

// ObjectDelete("P_Line");

// ObjectCreate("P_Line", OBJ_HLINE,0, CurTime(),Close[0]);

ObjectDelete("RS0");

ObjectCreate("RS0",OBJ_HLINE,0,CurTime(),ZigZag[1][0]);

ObjectDelete("RS1");

ObjectCreate("RS1",OBJ_HLINE,0,CurTime(),ZigZag[1][1]);

ObjectDelete("RS2");

ObjectCreate("RS2",OBJ_HLINE,0,CurTime(),ZigZag[1][2]);

ObjectDelete("RS3");

ObjectCreate("RS3",OBJ_HLINE,0,CurTime(),ZigZag[1][3]);

ObjectDelete("RS4");

ObjectCreate("RS4",OBJ_HLINE,0,CurTime(),ZigZag[1][4]);

ObjectDelete("RS5");

ObjectCreate("RS5",OBJ_HLINE,0,CurTime(),ZigZag[1][5]);

ObjectDelete("RS6");

ObjectCreate("RS6",OBJ_HLINE,0,CurTime(),ZigZag[1][6]);

ObjectDelete("RS7");

ObjectCreate("RS7",OBJ_HLINE,0,CurTime(),ZigZag[1][7]);

ObjectDelete("RS8");

ObjectCreate("RS8",OBJ_HLINE,0,CurTime(),ZigZag[1][8]);

ObjectDelete("RS9");

ObjectCreate("RS9",OBJ_HLINE,0,CurTime(),ZigZag[1][9]);

}

// if (ShowBars >= Bars) ShowBars = Bars;

/*

for (i=0;i<ShowBars;i++) {

b1=0;

b2=0;

b3=0;

b4=0;

b5=0;

b6=0;

b8=0;

hhb = iHighest(Symbol(),0,MODE_HIGH,dist,i-dist/2);

llb = iLowest(Symbol(),0,MODE_LOW,dist,i-dist/2);

if (i==hhb)

b3=High+SignalGap*Point;

if (i==llb)

b4=Low[llb]-SignalGap*Point;

b1=High;//+SignalGap*Point;

b2=Low[llb];//-SignalGap*Point;

}

*/

return(0);

}

//find the ten ZigZag,

void FindZigZag()

{

int i=BackStart;

int ii=0;

int m=0;

int n=0;

while(ii<ZigN)

{

if(iCustom(NULL,0,"zigzag",Depth,Deviation,BackStep,0,i)>0.1) //1=High

{

ZigZag[0]=0;

ZigZag[1]=iCustom(NULL,0,"zigzag",Depth,Deviation,BackStep,0,i);

// Print("ZigZag: ",ZigZag[1]);

ii++;

}

i++;

}

}

// Find Resistance and Support

void ResistanceSupport()

{

int i,n;

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

{

for(n=0;n<ZigN;n++)

{

if(MathAbs(ZigZag[1]-ZigZag[1][n])<Point*Gap)

{

ZigZag[0]++;

}

// Print(i+":ZigNumber: "+ZigZag[0]+" ZigZag: "+ZigZag[1]);

}

// Print("End");

}

ArraySort(ZigZag,WHOLE_ARRAY,0,MODE_DESCEND);

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

{

// Print(i+":ZigNumber: "+ZigZag[0]+" ZigZag: "+ZigZag[1]);

}

// Print("End");

}

 

Can I ask her some question for MQL4?

Hello from Berlin,

I am new in this forum and have read the MQL4 Course from Coders` guru. Very much thanks for your teaching! Now I want to try somthing easy programms and I already floped Why the MA-line will not show in my main-chart? Thanks for your help.

#property indicator_chart_window

#property indicator_color1 Red

extern int Period_MA = 21;

bool Fact_Up = true;

bool Fact_Dn = true;

int start()

{

double MA;

MA=iMA(NULL,0,Period_MA,0,MODE_SMA,PRICE_CLOSE,0);

if (Bid > MA && Fact_Up == true)

{

Fact_Dn = true;

Fact_Up = false;

Alert("Price is above MA(",Period_MA,").");

}

if (Bid < MA && Fact_Dn == true)

{

Fact_Up = true;

Fact_Dn = false;

Alert("Price is below MA(",Period_MA,").");

}

return(0);

}

 

Hi,

I am working on an idea for a custom indicator. I need to know if this is possible in a script:

Can MT4 recognize which candle is under my mouse at any time? So I want to draw a horizontal line at the open or close of a certain candle (which I select by clicking or hovering my mouse above of), is this possible?

I couldn't find any information about this.

It would help greatly, thanks!

 

order/transaction manager for EAs

Hi there,

Anyone familiar with an MQ4 library for order/transaction management for EAs? I'm interested mainly in the following two functionalities:

1. Placement of virtual stop orders: instead of using OrderSend(...) applied with a stop order, you use MyOrderSend(...) with the same parameters and the manager will take care of everything while keeping track of price and place the market order when price touches the stop.

The main purpose of this is to overcome the unnecessary STOPLEVEL burden, but it will also allow for "shadow" orders.

2. The manager will collect state and statistics on pending, executing and terminated orders. Using this info one can implement fancy MM strategies and fancy stop strategies (for example, the number of times that a live position has been in-the-money can be used for profit preservation or stop mechanisms).

I've searched around for quite a while, so I don't expect that such a library in its entirety exists, but if you are familiar with partial solutions and relevant code snippets that'll be great.

Cheers,

Trendick

 

order/transaction manager for EAs

I've just found that a very nice order manager has been developed in mql5 to allow for hedged positions. See paulsfxrandomwalk blogspot (not yet allowed to post links).

Not complete but very nice piece of code.

It shouldn't be easy but still possible to translate it to mql4 as one has to downgrade c++ OOP code to the extremely limited mql4. Seems like a big waste

So my call for your links is still on...

 

MA Lines On Chart

ssh95:
Hello from Berlin,

I am new in this forum and have read the MQL4 Course from Coders` guru. Very much thanks for your teaching! Now I want to try somthing easy programms and I already floped Why the MA-line will not show in my main-chart? Thanks for your help.

#property indicator_chart_window

#property indicator_color1 Red

extern int Period_MA = 21;

bool Fact_Up = true;

bool Fact_Dn = true;

int start()

{

double MA;

MA=iMA(NULL,0,Period_MA,0,MODE_SMA,PRICE_CLOSE,0);

if (Bid > MA && Fact_Up == true)

{

Fact_Dn = true;

Fact_Up = false;

Alert("Price is above MA(",Period_MA,").");

}

if (Bid < MA && Fact_Dn == true)

{

Fact_Up = true;

Fact_Dn = false;

Alert("Price is below MA(",Period_MA,").");

}

return(0);

}

Hi Berliner,

It seems the routines for drawing the MA lines on the chart are missing from your code above.

Do a quick search on this TSD Forum for many good examples of MA indicators that you can look at the code to learn how to draw the MA lines on the chart.

Good luck...and keep learning!

Robert

 

Refresh issue on MTF indicator

Hello,

I need help on this indicator. Its MTF MACD slope, but it has a problem on refresh, i have to switch TF to correct it.

Already try to change

limit=Bars-counted_bars; to limit=Bars-counted_bars/Period();

and also adding Refreshrates();

with no result.

So sorry, i have to upload the code in .mql , try to upload using php tag but its to long.

I also upload the picture on MTF thread

Thanks before guys.

Files:
 
codersguru:
Hi folks,

I've got a lot of private messages asking me for helping with some pieces of code.

Here you can post your questions related to MQL4, and I'll do my best to answer them.

Codesguru,

I have no knowledge about programming at all. And I need you or anyone to help me out by putting alarm and alert (as external indicator) on this execute_line indi.

Thank you in advance.

Cheers, Terry

Files:
 

Waddah Attar scalping

Hello!

I found an interesting indicator that is scalping oriented.

I want to backtest it but it doesnt print any bars aftes a few days.

Can you please see what must be edited in code in order to make it print a few thousand bars? If there is an option to type a number in meta editor please tell me. I couldnt find something.

Thanks for your time

Xander

waddah_attar_scalping.ex4

waddah_attar_scalping.mq4