MQL4 Learning - page 33

 

hi all

think....

i have a library and into the library i need to determine if run time is

- Script

- Indicator

- or EA

how to code?

 

higher/lower price for a symbol between 2 specific times

yaniv_av:
Hi all,

How can I get the higher/lower price for a symbol between 2 specific times?

Example: I want to get the EURUSD higher price between the 1.1.2008 00:00 until the 1.2.2008 00:00.

How can I do that ?

Thanks !

Here's some code I use in one of my indicators. It does exactly what you are looking for.

All the best,

Hiachiever

void CreateTradeSession(string RecName, datetime dt, string tb, string te, color RecColor)

{

datetime Time1, Time2;

double Price1, Price2;

int b1, b2;

Time1=StrToTime(TimeToStr(dt, TIME_DATE)+" "+tb);

Time2=StrToTime(TimeToStr(dt, TIME_DATE)+" "+te);

if (CurTime()>= Time1) //Preview 1 hour before

{

if(ObjectFind(RecName) != 0)

{

ObjectCreate(RecName, OBJ_RECTANGLE, 0, 0,0, 0,0);

ObjectSet(RecName, OBJPROP_STYLE, STYLE_SOLID);

ObjectSet(RecName, OBJPROP_COLOR, RecColor);

ObjectSet(RecName, OBJPROP_BACK, True);

}

b1=iBarShift(NULL, 0, Time1);

if (Time2>CurTime()) Time2 = CurTime();

b2=iBarShift(NULL, 0, Time2);

Price1=High;

Price2=Low [Lowest (NULL, 0, MODE_LOW , b1-b2, b2)];

ObjectSet(RecName, OBJPROP_TIME1 , Time1);

ObjectSet(RecName, OBJPROP_PRICE1, Price1);

ObjectSet(RecName, OBJPROP_TIME2 , Time2);

ObjectSet(RecName, OBJPROP_PRICE2, Price2);

}

}

 

I didn't found a posted thread that explain about this.

I want to limit my open to 1 open/day only.

Here is the code

if(CheckJustClosedOrder()==1) {return(0);}

and the function is

int CheckJustClosedOrder()

{

int cnt;

datetime orderclosetime, rightnow;

int TheHistoryTotal=OrdersHistoryTotal();

int flag=0;

for(cnt=0;cnt<TheHistoryTotal;cnt++)

{

if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY)==true)

{

if ( (OrderSymbol()==Symbol()) && (OrderMagicNumber()==MagicNumber) && (OrderComment()==GetCommentForOrder()) )

{

orderclosetime=OrderCloseTime();

rightnow=CurTime();

if(rightnow-orderclosetime<36000)

{ // At least 10jam away!

flag=1; // Throw a flag tanda tidak boleh open

break;

}

}

}

}

return(flag);

}

Is command orderhistorytotal() work well when doing backtes?

 

Few of my EAs working with OrdersHistoryTotal() and it's doing well on backtest. Your problem maybe on OrderComment() function. You can use it as identifier only when it's an active order. For closed order, MT4 modify it a little bit, adding [tp] if it was closed by takeprofit or [sl] if it was closed by stoploss.

 

Remove TP and SL

if I have an order placed by an expert advisor, later on I decided I want to remove SL and TP and set them back to 0.000 is that possible ? if so how ?

 

if thats not possible how to modify the current TP ?

Like I need to add 5 more pips to the current of the TP

 
Devil2000:
Few of my EAs working with OrdersHistoryTotal() and it's doing well on backtest. Your problem maybe on OrderComment() function. You can use it as identifier only when it's an active order. For closed order, MT4 modify it a little bit, adding [tp] if it was closed by takeprofit or [sl] if it was closed by stoploss.

So my ordercomment doest work on backtest. Ok i will add double check for istesting or not.

Thanks for the reply. Can you tell me the MT4's newest function or syntax site?

 

don't bother reply I got it

 
pipsmaster:
So my ordercomment doest work on backtest. Ok i will add double check for istesting or not. Thanks for the reply. Can you tell me the MT4's newest function or syntax site?

I think you can find everything about it here.

 
MiniMe:
if I have an order placed by an expert advisor, later on I decided I want to remove SL and TP and set them back to 0.000 is that possible ? if so how ?

Sure..

if(blablabla) OrderModify(OrderTicket(),OrderOpenPrice(),0,0,0,0);

[/CODE]

MiniMe:
if thats not possible how to modify the current TP ? Like I need to add 5 more pips to the current of the TP

[CODE]

if(blablabla) OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderTakeProfit()+5*Point,0,0);

Hope this helps

Reason: