MQL4 - automated forex trading   /  

Forum

Need help

Back to topics list  | 1 2 3 To post a new topic, please log in or register

avatar
16
lancelot 2010.07.22 13:30 

I am new for this program I am practicing to code EA now I want to close the order

but in the report it said the " invalided ticket for order close function"

Please help me...

{
if(a1<a2)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3);
return(0);
}
}

thank...

Using MetaTrader 4 for a Time Based Pattern Analysis

Using MetaTrader 4 for a Time Based Pattern Analysis

Time based pattern analysis can be used in the currency market to determine a better time to enter a trade or time in which trading should be avoided at all. Here we use MetaTrader 4 to analyze history market data and produce optimization results that can be useful for application in mechanical trading systems.


avatar
1975
zzuegg 2010.07.22 13:33 

have you preaviously selected the right order?

http://docs.mql4.com/trading/OrderSelect


avatar
1971
ubzen 2010.07.22 13:39 


avatar
16
lancelot 2010.07.22 13:55 

thanks I will come back with new question?...

thank for your answer?


avatar
16
lancelot 2010.07.22 13:58 

I tried to close order when the candle stick bar close!!!

Do you have any recommendation?


avatar
1975
zzuegg 2010.07.22 14:02 

common method is to close when new bar opens, which generally is the same price as close of last one.

check out the timeseries function.

maybe a comparsion between currentBar OpenTime and a previously stored reference time would work fine ;)


avatar
16
lancelot 2010.07.22 14:04 

The Idea is to open price when candle stick open and close price when candle stick close I am not sure for this, I am too new for the codes

any can give me suggestion so trade every bar..

//+------------------------------------------------------------------+
//| random.mq4 |
//| Copyright ฉ 2010, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright ฉ 2010, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"

//---- input parameters
extern double Lot =0.1;

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+

int start()
{
//----
int ticket;
int total;
double candle,candle1;

candle=iOpen("EURUSD",PERIOD_H1,1);
candle1=iClose("EURUSD",PERIOD_H1,1);

total=OrdersTotal();
// order buy//
if(total<1)
{
if(candle1>candle)
{
ticket=OrderSend(Symbol(),OP_BUY,Lot,Ask,3,0,0,"MAC",0,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
}
else
{
if(candle1<candle)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3);
return(0);
}
}
//----
return(0);
}
//+------------------------------------------------------------------+

this is my code but it is not right I think


avatar
1975
zzuegg 2010.07.22 14:10 

if you have a working code for open trade when candle opens you can use the same code to close the order,

currentOpen Tick = previousClose Tick

here is pseudocode:

static time lastBar
static time currBar
currBar = OpenTimeOfCurrentBar
IF   lastBar != currBar
THEN lastBar = currBar
     //Here goes code for  isA-NewBar
ELSE //here goes code for NotA-NewBar


avatar
16
lancelot 2010.07.22 14:25 

So my codes in there it is wrong way, right?

I think It is when I use iOpen and iClose Proble is : it can't not close when the bar is close: because it is wrong logic as you said.

but the code you give me. It is too advance for me, I need time to study....

Thank mate

I will come back soon


avatar
1975
zzuegg 2010.07.22 14:32 

hi, i am having a good day so here is the full mql code:

static datetime lastBar=0;  //static surpresses that the variable gets overwrited every tick
       datetime currBar=0;  //here static is not neccesary because initialisation is done every tick
currBar=Time[0];
if(currBar!=lastBar){  //if time of current Open bar not is (!=) time of the lastOpen, then we have a new Bar
  lastBar=currBar;     //setting oldBarOpenTime to the currentOpenTime
  //The code here will be executed
  //at the tick when a new Bar has
  //formed and the previous closed
}else{
  //here comes the code which will be
  //executed in all the ticks between
}

but please do not only copy and paste this code, but try to understand what every line of code does..-.


avatar
539
Viffer 2010.07.22 14:34 
lancelot:

candle=iOpen("EURUSD",PERIOD_H1,1);
candle1=iClose("EURUSD",PERIOD_H1,1);


Why don't you just look at the open of the latest bar with the open of the prev bar

   candle=iOpen("EURUSD",PERIOD_H1,1);
   candle1=iOpen("EURUSD",PERIOD_H1,0); 

open is always just the first tick so you won't have to muck about with NewBar. Is any gapping variance going to make any difference on this code?

V

Oh and as ubzen said, please use the source button. It's difficult to read unformated code and you are less likely to get a response.

V

Back to topics list   | 1 2 3  

To add comments, please log in or register