MQL4 Learning - page 32

 
omelette:
if ((Ask - Bid) / Point >= ThresholdValue)

{

//Your code here...

}

thanks a lot omelette, its works

 

ExpertsDllConfirm in start.ini seems not to work

Hi,

The ExpertsDllConfirm in start.ini seems not to work:

ExpertsDllConfirm=false doesn't make this flag reset at start up. See attached options dialog window. Can anyone else confirm this is a bug for MT4? Is there a workaround for this?

Thanks,

Jeff

Files:
bugmt4.jpg  34 kb
 
fxtrader625:
Hi,

The ExpertsDllConfirm in start.ini seems not to work:

ExpertsDllConfirm=false doesn't make this flag reset at start up. See attached options dialog window. Can anyone else confirm this is a bug for MT4? Is there a workaround for this?

Thanks,

Jeff

Hi

maybe not a bug, check if don't have some files set RO. By only click out the option should be enough

Also, there is no start.ini file.

 
Linuxser:
Hi

maybe not a bug, check if don't have some files set RO. By only click out the option should be enough

Also, there is no start.ini file.

Of course, the MT4 can be started with start.ini like this command:

terminal config\start.ini

This file contains a list of settings to login an account, to select chart, to switch options, etc... See MT4 manual for more info about this (Tools - Configuration at startup). It's only that ExpertsDllConfirm=false seems not to work...

 
fxtrader625:
Of course, the MT4 can be started with start.ini like this command:

terminal config\start.ini

This file contains a list of settings to login an account, to select chart, to switch options, etc... See MT4 manual for more info about this (Tools - Configuration at startup). It's only that ExpertsDllConfirm=false seems not to work...

Sorry, you're right.

Also EnableDDE and EnableNews does not work.

 
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 !

Something like this:

string date1 = "2008.01.01 00:00";

string date2 = "2008.01.02 00:00";

string sym = "YourSymbol";

datetime t1 = StrToTime(date1);

datetime t2 = StrToTime(date2);

int b1 = iBarShift(sym, PERIOD_M1, t1, false);

int b2 = iBarShift(sym PERIOD_M1, t2, false);

//Assuming that date1 < date2

double HH = iHigh(sym, PERIOD_M1, iHighest(sym, PERIOD_M1, MODE_HIGH, b1-b2+1, b2));

double LL = iLow(sym, PERIOD_M1, iLowest(sym, PERIOD_M1, MODE_LOW, b1-b2+1, b2));

 

Returning the # of orders on a certain chart

How do you

Return the # of orders on a certain chart?

 

MQL4 LEARNING: i dont no why my ea error.

Hello can someone help me plz?

i m newbie in metaquoates language. i start learning by edit the simple ea first.

refer to my stoch ea, there are some error..

why my ea not take trade when the stoch line cross for that area ( mark by text'?')??

not all but some look ok( mark by text 'ok').

sorry for my english.

very thankfull for any help.

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

//| stoch.mq4 |

//| RAYZ|

//| |

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

#property copyright "Stoch testing"

#property link "www.forex-tsd.com"

#include

#include

extern int Confirm=0;

extern int K=8,D=3,SL=3;

extern double LowerLevel = 20;

extern double UpperLevel = 80;

extern double lots=0.1;

extern int TakeProfit=10;

extern int StopLoss=15;

bool UseTrail = false;

double TrailingAct = 6;

double TrailingStep = 6;

extern bool UseTimeFilter=false;

extern int BeginHour=1;

extern int EndHour=5;

int bar;

int TestStart;

int k;

int mm,dd,yy,hh,min,ss,tf;

string comment;

string syym;

string qwerty;

int OrderID;

double TrailPrice;

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

//| expert initialization function |

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

int init()

{

//----

//----

return(0);

}

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

//| expert deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

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

//| expert start function |

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

int TimeFilter(){

if(Hour()>EndHour || Hour()<BeginHour){

return(1);

}

return(0);

}

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

// Calculates Current Orders on TF,Pair,EA

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

int CalculateCurrentOrders(){

int orders=0;

for(int i=0;i<OrdersTotal();i++){

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){

if(OrderSymbol()==Symbol() && OrderMagicNumber()==OrderID ){

orders++;

}

}

}

return(orders);

}

int TradeSignal(int functyp){

bool Rev=false;

int x = Confirm;

double sto1=iStochastic(NULL,0,K,D,SL,MODE_SMA,0,MODE_MAIN,x);

// double sto2=iStochastic(NULL,0,15,2,1,MODE_SMA,0,MODE_SIGNAL,1);

// double stdev=iStdDev(NULL,0,10,MODE_SMA,0,0,0);

//double sto3=iStochastic(NULL,1440,15,2,1,MODE_SMA,0,MODE_MAIN,0);

// double sto4=iStochastic(NULL,1440,15,2,1,MODE_SMA,0,MODE_SIGNAL,0);

if(functyp==1){

if(sto1 >99 ){

if(Rev){

return(1);

}else{

return(2);

}

}

if(sto1 < 1 ){

if(Rev){

return(2);

} else{

return(1);

}

}

}

if(functyp==2){

if(sto1 >99){

if(Rev){

return(1);

}else{

return(2);

}

}

if(sto1 < 1){

if(Rev){

return(2);

} else{

return(1);

}

}

}

return(0);

}

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

//| Open Conditions |

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

void CheckForOpen(){

double sl,tp; int res,error;

if(TradeSignal(1)==2){

if (StopLoss==0) {sl=0;} else sl=Bid+Point*StopLoss;

if (TakeProfit==0) {tp=0;} else tp=Bid-Point*TakeProfit;

bar=Bars;

res = OrderSend(Symbol(),OP_SELL,lots,Bid,3,sl,tp,"D2",OrderID,0,Blue); // def

if(res<0){

error=GetLastError();

Print("Error = ",ErrorDescription(error));

}

}

if(TradeSignal(1)==1){

if (StopLoss==0) {sl=0;} else sl=Ask-Point*StopLoss;

if (TakeProfit==0) {tp=0;} else tp=Ask+Point*TakeProfit;

bar=Bars;

res = OrderSend(Symbol(),OP_BUY,lots,Ask,3,sl,tp,"D2",OrderID,0,Red); // def

if(res<0){

error=GetLastError();

Print("Error = ",ErrorDescription(error));

}

}

}

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

//| Close conditions |

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

void CheckForClose(){

for(int i=0;i<OrdersTotal();i++){

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if (OrderType()==OP_BUY && OrderMagicNumber()==OrderID && Symbol()==OrderSymbol()){

if (TradeSignal(2)==2) { // MA SELL signals

int res = OrderClose(OrderTicket(),OrderLots(),Bid,3,White); // close

TrailPrice=0;

if(res<0){

int error=GetLastError();

Print("Error = ",ErrorDescription(error));

}

}

}

if (OrderType()==OP_SELL && OrderMagicNumber()==OrderID && Symbol()==OrderSymbol() ){

if (TradeSignal(2)==1) { // MA BUY signals

res = OrderClose(OrderTicket(),OrderLots(),Ask,3,White); // close

TrailPrice=0;

if(res<0){

error=GetLastError();

Print("Error = ",ErrorDescription(error));

}

}

}

}

}

void TrailingPositions() {

for (int i=0; i<OrdersTotal(); i++) {

if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {

if (OrderMagicNumber()==OrderID ) {

if (OrderType()==OP_BUY) {

if (Bid-OrderOpenPrice()>TrailingAct*Point && TrailPrice ==0) {

TrailPrice=Bid-TrailingStep*Point;

Print("TRAIL PRICE MODIFIED: ",TrailPrice);

}

if (TrailPrice>0 && TrailPrice < Bid-TrailingStep*Point){

TrailPrice=Bid-TrailingStep*Point;

Print("TRAIL PRICE MODIFIED: ",TrailPrice);

}

if (TrailPrice >0 && TrailPrice >= Bid-TrailingStep*Point){

CloseOrder(1);

}

}

if (OrderType()==OP_SELL) {

if (OrderOpenPrice()-Ask > TrailingAct*Point && TrailPrice ==0) {

TrailPrice=Ask+TrailingStep*Point;

Print("TRAIL PRICE MODIFIED: ",TrailPrice);

}

if (TrailPrice>0 && TrailPrice > Ask+TrailingStep*Point){

TrailPrice=Ask+TrailingStep*Point;

Print("TRAIL PRICE MODIFIED: ",TrailPrice);

}

if (TrailPrice >0 && TrailPrice <= Ask+TrailingStep*Point){

CloseOrder(2);

}

}

}

}

}}

void CloseOrder(int ord){

for(int i=0;i<OrdersTotal();i++){

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if (OrderType()==OP_BUY && OrderMagicNumber()==OrderID){

if (ord==1){

int res = OrderClose(OrderTicket(),OrderLots(),Bid,3,White); // close

TrailPrice=0;

if(res<0){

int error=GetLastError();

Print("Error = ",ErrorDescription(error));

}

}}

if (OrderType()==OP_SELL && OrderMagicNumber()==OrderID ){

if (ord==2) { // MA BUY signals

res = OrderClose(OrderTicket(),OrderLots(),Ask,3,White); // close

TrailPrice=0;

if(res<0){

error=GetLastError();

Print("Error = ",ErrorDescription(error));

}

}

}

}

}

int start(){

if(Bars<100 || IsTradeAllowed()==false) return;

if(CalculateCurrentOrders()==0) {

TrailPrice=0;

if(UseTimeFilter && TimeFilter()==1)return;

CheckForOpen();

}else{

CheckForClose();

}

if(UseTrail){TrailingPositions();}

// if(UseEmailAlerts){MailAlert();}

return(0);

}

//------------------------------------------------------------+
Files:
stoch.gif  17 kb
 

Timelimit on orders

Hello,

I am in the process of programming an EA and trying to place a time limit on orders. For example, if a trade is opened on the first of the month I would like to force it to close if the parameters on my EA are not reached by the fifth day or so. I have tried to search the forum, but with so many results with the terms "time limit" I have failed to find an answer.

Thanks for your help!

 
dan5767:
Hello,

I am in the process of programming an EA and trying to place a time limit on orders. For example, if a trade is opened on the first of the month I would like to force it to close if the parameters on my EA are not reached by the fifth day or so. I have tried to search the forum, but with so many results with the terms "time limit" I have failed to find an answer.

Thanks for your help!

Calculate how many seconds are 5 days, add it to "OrderOpenTime()" compare it to "TimeCurrent()".

Hope this helps

Reason: