Forex
Google
New signals service!

Go Back   Forex Trading > Programming > Metatrader Programming


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack Thread Tools Display Modes
  #301 (permalink)  
Old 02-05-2008, 10:09 PM
Senior Member
 
Join Date: Feb 2006
Posts: 559
Michel is on a distinguished road
Quote:
Originally Posted by yaniv_av View Post
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:
PHP Code:
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(symPERIOD_M1t1false);
int b2 iBarShift(sym PERIOD_M1t2false);
//Assuming that date1 < date2
double HH iHigh(symPERIOD_M1iHighest(symPERIOD_M1MODE_HIGHb1-b2+1b2));
double LL iLow(symPERIOD_M1iLowest(symPERIOD_M1MODE_LOWb1-b2+1b2)); 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #302 (permalink)  
Old 02-09-2008, 03:03 AM
Dan7974's Avatar
Senior Member
 
Join Date: Jul 2006
Posts: 264
Dan7974 is on a distinguished road
Returning the # of orders on a certain chart

How do you
Return the # of orders on a certain chart?
__________________
God Bless Everyone, and their trading logic.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #303 (permalink)  
Old 02-11-2008, 04:53 AM
Junior Member
 
Join Date: Jun 2007
Posts: 9
rayz is on a distinguished road
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.


PHP Code:
//+------------------------------------------------------------------+
//|                                             stoch.mq4 |
//|                                                      RAYZ|
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Stoch testing"
#property link      "www.forex-tsd.com"

#include <stdlib.mqh>
#include <WinUser32.mqh>

   
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 ){
      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,tpint 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=0i<OrdersTotal(); i++) {
    if (
OrderSelect(iSELECT_BY_POSMODE_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>&& TrailPrice Bid-TrailingStep*Point){
               
TrailPrice=Bid-TrailingStep*Point;
               Print(
"TRAIL PRICE MODIFIED: ",TrailPrice);
            }
            if (
TrailPrice >&& 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>&& TrailPrice Ask+TrailingStep*Point){
               
TrailPrice=Ask+TrailingStep*Point;
               Print(
"TRAIL PRICE MODIFIED: ",TrailPrice);
            }
            if (
TrailPrice >&& 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);
}  
//------------------------------------------------------------+ 
Attached Images
File Type: gif stoch.gif (16.4 KB, 120 views)
Attached Files
File Type: htm Stochtesting1.htm (34.0 KB, 5 views)

Last edited by rayz; 02-11-2008 at 04:57 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #304 (permalink)  
Old 02-14-2008, 03:59 AM
Junior Member
 
Join Date: Aug 2007
Posts: 8
dan5767 is on a distinguished road
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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #305 (permalink)  
Old 02-14-2008, 02:29 PM
Senior Member
 
Join Date: Dec 2005
Location: In front of my trading desk
Posts: 345
Devil2000 is on a distinguished road
Quote:
Originally Posted by dan5767 View Post
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
__________________
Need a professional MQL4 programmer? PM me

Last edited by Devil2000; 02-14-2008 at 04:42 PM. Reason: grammar
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #306 (permalink)  
Old 02-15-2008, 07:39 PM
Member
 
Join Date: Jan 2006
Posts: 30
DooMGuarD is on a distinguished road
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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #307 (permalink)  
Old 02-16-2008, 01:04 AM
Member
 
Join Date: Jan 2006
Posts: 56
hiachiever is on a distinguished road
higher/lower price for a symbol between 2 specific times

Quote:
Originally Posted by yaniv_av View Post
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[Highest(NULL, 0, MODE_HIGH, b1-b2, b2)];
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);
}
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #308 (permalink)  
Old 02-26-2008, 05:19 AM
Junior Member
 
Join Date: Nov 2006
Posts: 20
pipsmaster is on a distinguished road
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

Code:
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?

Last edited by pipsmaster; 02-26-2008 at 05:23 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #309 (permalink)  
Old 02-26-2008, 07:44 AM
Senior Member
 
Join Date: Dec 2005
Location: In front of my trading desk
Posts: 345
Devil2000 is on a distinguished road
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.
__________________
Need a professional MQL4 programmer? PM me
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #310 (permalink)  
Old 02-26-2008, 06:42 PM
MiniMe's Avatar
Senior Member
 
Join Date: Nov 2006
Location: Montréal
Posts: 1,297
MiniMe is on a distinguished road
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 ?
__________________
x.x.x.x.x. $$$ x.x.x.x.x.