MQL4 Learning - page 104

 

Error help

Using the default zigzag indicator, I am trying to make trendlines using the last 10 high and low, so i can get better SR levels

But I am not able to set the limit to the number of lines being formed

Help me please

 

// begin custom code

if (LowMapBuffer[shift]!=0)

{

tm = iTime(Symbol(),0,shift);

tmL = TimeDay(tm) + "-" + TimeMonth(tm) + "-" + TimeYear(tm) + " - " + TimeHour(tm) + "-" + TimeMinute(tm);

prL = iLow(Symbol(),0,shift);

LDraw(tm, prL, tmL, Red, shift);

}

if (HighMapBuffer[shift]!=0)

{

tm = iTime(Symbol(),0,shift);

tmL = TimeDay(tm) + "-" + TimeMonth(tm) + "-" + TimeYear(tm) + " - " + TimeHour(tm) + "-" + TimeMinute(tm);

prL = iHigh(Symbol(),0,shift);

LDraw(tm, prL, tmL, Green, shift);

}

// end custom code

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

void LDraw(datetime tmi, double pr, string tmli, color cl, double S)

{

ObjectCreate("AZ"+DoubleToStr(S,0), OBJ_HLINE, 0, tmi, pr);

ObjectSet("AZ"+DoubleToStr(S,0),OBJPROP_COLOR,cl);

ObjectSetText("AZ"+DoubleToStr(S,0),tmli,12,"Arial",Red);

}

 

Please let me know how to make following EA

Following action is the one I want to know in EA.

If there is executed order within last 10 bar, no new order is opened.

 

you will need to create a counter that is incremented every time a new bar is created. you may also want to account for if the time frame changes as well.

 
junglelion:
// begin custom code

if (LowMapBuffer[shift]!=0)

{

tm = iTime(Symbol(),0,shift);

tmL = TimeDay(tm) + "-" + TimeMonth(tm) + "-" + TimeYear(tm) + " - " + TimeHour(tm) + "-" + TimeMinute(tm);

prL = iLow(Symbol(),0,shift);

LDraw(tm, prL, tmL, Red, shift);

}

if (HighMapBuffer[shift]!=0)

{

tm = iTime(Symbol(),0,shift);

tmL = TimeDay(tm) + "-" + TimeMonth(tm) + "-" + TimeYear(tm) + " - " + TimeHour(tm) + "-" + TimeMinute(tm);

prL = iHigh(Symbol(),0,shift);

LDraw(tm, prL, tmL, Green, shift);

}

// end custom code

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

void LDraw(datetime tmi, double pr, string tmli, color cl, double S)

{

ObjectCreate("AZ"+DoubleToStr(S,0), OBJ_HLINE, 0, tmi, pr);

ObjectSet("AZ"+DoubleToStr(S,0),OBJPROP_COLOR,cl);

ObjectSetText("AZ"+DoubleToStr(S,0),tmli,12,"Arial",Red);

}

many edits later! look... I've cobbled together something that may work but at least should give you some ideas and possible ways to implement. looking at others code and attempting to not interfere much is h.a.r.d and causes suggestions to look a bit crazy!

Really hope what done helps in some way

not familiar with zz code. but why not after the main zz for loop has ended do: have your 'own' for loop. eg,

#define MAXLINES 10

int iHighLinesDrawn=0,iLowLinesDrawn=0;

for(shift=0;shift<maxbars;shift++)

{

if (HighMapBuffer[shift]!=0 && iHighLinesDrawn<MAXLINES)

{

iHighLinesDrawn++;

//actuals calcs...

LDraw(tm, prL, tmL, Green, shift);

}

if (LowMapBuffer[shift]!=0 && iLowLinesDrawn<MAXLINES)

{

iLowLinesDrawn++;

//actuals calcs...

(1) tmL = TimeDay(tm) + "-" + TimeMonth(tm) + "-" + TimeYear(tm) + " - " + TimeHour(tm) + "-" + TimeMinute(tm);

>>>consider changing (1) to:

tmL = "L" + iLowLinesDrawn; (and same for "H"...)

>>>why? in this way each of hi,lo set of 10 lines have a 'set object name format' which can be tested for existence by ObjectFind() and if already created, just 'move' it to your actual input value: prL

>>>NOTE: thinking about it, once a line has been drawn, it only needs moving, Ahhaaa, I see it now, you want to set text with time etc. BUT... do you really need to? Excuse, but I mentioned above, the trying to not interfere with code and this causes one to not look at total 'what currently doing'. I'm digging self big hole here. Best is to take what can from this post and P.L.A.Y around. This is by far the best method when not sure what things do because you try some code and look at results and think what? and go back and try another angle. Can be fun and one learns a lot that way!

.....basically, IF want unique names for each object THEN you must keep list of created object names. eg, once list has MAXLINES of names in it, take out the oldest, delete that named object, create new object and put on list (as the newest). Next time around, get the oldest name and delete, ...

OR just scan all object eg, High names, and get the 'oldest' datetime in the name, delete it, and now create new High name with latest datetime.

Where you get the names from is up to you - eg: a "string sHighNames[MAXLINES];" could be used to stuff names into and when full, you now must firstly search for the oldest name, delete it, replace it with new name in same [just deleted name] element, create new object.

man... so many different ways to approach stuff

>>>ummm, am saying that if use unique zz point time data in it's name, you cannot stop creating new lines each time because your draw () not know the 11th,12th,... line name. ie, the lines keep getting created, yes?

>>>by having fixed line format, once the eg, H1,H2,...,H10 objects have been created, all the draw () need do is update the objects attributes which will effectively 'move' it to a new position...

NOTE:OBJPROP_TIME1 for HLINE not actually needed - ie, could be zero.

iow, not really needed as a function actual... just a comment

LDraw(tm, prL, tmL, Red, shift);

}

if(iLowLinesDrawn>=MAXLINES && iHighLinesDrawn>=MAXLINES)

break; //max lines hi and lo are now drawn

}//for(shift=0;shift<maxbars;shift++)

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

void LDraw(datetime tmi, double pr, string tmli, color cl, double S)

{

//only need create the line objects IF not already created - this will also save a few cycles once 10 of each hi,lo have been created...

if(ObjectFind(tmli == -1)

ObjectCreate("AZ"+DoubleToStr(S,0), OBJ_HLINE, 0, tmi, pr);

else

ObjectSet(tmli,OBJPROP_PRICE1,pr); //since already created, just 'move' it to new price

(1) ObjectSet("AZ"+DoubleToStr(S,0),OBJPROP_COLOR,cl);

(2) ObjectSetText("AZ"+DoubleToStr(S,0),tmli,12,"Arial ",Red);

in (1),(2) change "AZ"+DoubleToStr(S,0) to tmli ie, the lines name created by caller: eg, H1,...H

}

idea is to let generic zz code do all it's stuff and only then, when it's about to return to terminal, you put above. The indicator buffers are all loaded and your code just does whatever processing it wants using these buffers and each time you only go back the number of bars needed UNTIL both hi and lo have MAXLINES drawn.

is idea , maybe get you on right track?

regards

 

Order Close by Magic Number

I am attempting to close one of three open orders by using the magic number that I assigned when the order was opened.

if (OrderMagicNumber() == 11111 && OrderOpenPrice() + (250 * Point) <= Bid ) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID),3, Red );

the above lines makes a reference to the trade with the magic numbe "11111", but using the order close function, closes all open trades based on the criteria of the magic number trade. How can I only close the order with the magic number that I have assigned?

 

how to detect the order is belong to which currency?

Hi i am new to mql,

I am trying to create an EA to trade automatic. The EA must only can have only one trade on each currency. which means that if i attach the EA to the chart, the EA must detect is there an Real Order running OR any pending order available for the currency that attached.

If there is any Real Order or Pending order, it must be discard and wait for no real order or pending order in the terminal..

The problem is..... even when i have a real trade order OR pending ticket in terminal, the code execute what i wanted, but it cannot detect whether it is same to the currency which attach with this EA or not.

below is my code,anyone who can help me, pls advise....

/////// My code ////////

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

//| test_order.mq4 |

//| xxx |

//| / MetaQuotes Software Corp. |

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

#property copyright "xxx"

#property link "xxx"

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

//| expert initialization function |

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

int init()

{

//----

Alert("EA attached"); //Test

//----

return(0);

}

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

//| expert deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

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

//| expert start function |

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

int start()

{

//----

string Symb=Symbol();

int total=OrdersTotal();

if (total>0){

Alert("Got trade/pending ticket in interminal..."); //Test

if (OrderSymbol()!= Symb){

Alert("Got trade/pending ticket in terminal, but not same currency"); //Test

}else{

Alert("Got trade/pending ticket in terminal which is same to the currency attach with this EA"); //Test

}

}else{

Alert("Got trade/pending ticket in interminal..."); //Test

}

//----

return(0);

}

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

 

Looking for Code

Hello Everyone,

Can someone share some code on how to draw an OHLC bar on a sub window?

Thanks

EK

 

Open a pending order straddle at a given time

Dear problem solvers

I am totally new to MQL4 - learning it from 2 books.

My partner and I have an EA we wish to develop. We have tried 4 so called expert programmers all to no avail.

I am able to wrire an EA to place a pending order at Close[1] so the next step is to have the program open a OP_BUYSTOP and an OP_SELLSTOP

at a prescribed GMT or Server time equivalent

I must be missing the Time Function capabilities somewhere

HH = Hour()

MM = Minute()

int Currenttime = HH*100 + MM

if CurrentTime = StraddleOpenTime

etc

I have included where my EA is at ATM - don't laugh please

Files:
 

Trade entry based on Price

I am trying to figure out how to determine the entry of a trade based on the current price. I want to enter a trade when the last 2 digits read a certain price. Any help would be greatly appreciated.