Forex
Google
New signals service!

Go Back   Forex Trading > Metatrader Training > Metatrader 4 mql 4 - Development course > Questions


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 (2) Thread Tools Display Modes
  #761 (permalink)  
Old 08-26-2007, 03:04 AM
1Dave7's Avatar
Member
 
Join Date: Aug 2007
Posts: 82
1Dave7 is on a distinguished road
Smile

Quote:
Originally Posted by justize View Post
Hi,
I have a problem to integrate my own indicators into an EA.
Here are both indicators i would like use in my EA:
Discret Butterworth-Lowpass-Filter (1st order)

I know that i have to use iCustom
but I donīt know, what I have to write into the ()...

For example, the indicator butterworth-ad has 4 variables (A,B,F,G) and 3 outputs. How can I open that indicator, tell them the vars and how can I get the right output after all???


Kind regards
1) Adjust the settings in the indicator for what you want the indicator to do.

2) Now import the settings into your ea:

Try this in your ea: Butter0=iCustom(NULL,0,"Put full name of indicator file Butter here in quotations", minus .mq4),A,B,F,G,0,0); //This should cover buffer 0.

3) Butter1 =iCustom(NULL,0,"Put full name of indicator file Butter here in quotations", minus .mq4),A,B,F,G,1,0); //This should cover buffer 1.

4) Butter2 =iCustom(NULL,0,"Put full name of indicator file Butter here in quotations", minus .mq4),A,B,F,G,2,0); //This should cover buffer 2.

5) Type this then: Print(" ",TradeLast," Butter0= ",Butter0," | ", "Butter1= ",Butter1," | ", "Butter2= ",Butter2);

6) Declare the values at the beginning of the program: double Butter0=0,Butter1=0,Butter2=0; //Or use integer instead of double depending on the scale of the indicator, such as 0-100, versus 0.00 to 100.00.

7) Compile the program and see if it compiles. If it does, place the expert over the currency plot and then look in the experts folder below the graphs under the currency you are viewing and see if the buffers being printed out show the same values that the indicator shows on the graph. If it does you can determine which buffers you will need to use in your ea.

8) Let's say Butter0 (Buffer0) matches the indicator values. Next is to use them in a logic buy or sell statement.

9) Reference Butter0 (Current Bar): Butter0=iCustom(NULL,0,"Put full name of indicator file Butter here in quotations", minus .mq4),A,B,F,G,0,0);

And also the bar one back: Butter0_1Back=iCustom(NULL,0,"Put full name of indicator file Butter here in quotations", minus .mq4),A,B,F,G,0,1);

Note: Use this if you want to check to see if the indicator is rising like a Moving average: if(Butter0>Butter0_1Back) BuyValue=1; //MA is rising.

Note: If Buffer 0 = Up buffer, and Buffer 1 = Down buffer you can write a statement for a buy: If (Butter0>Butter1) BuyValue=1;//Buffer 0 is positive like the indicator value, Buffer 1 is probably 0.00 value until Butter0 goes negative past 0.

I hope I did not confuse you. Work with it to see what you see.

Dave
<><<<

Note: I just looked at the indicator, it is a moving average, so code it in the ea as a moving average using the example I showed for a moving average.

Last edited by 1Dave7; 08-26-2007 at 03:29 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #762 (permalink)  
Old 08-26-2007, 03:24 AM
1Dave7's Avatar
Member
 
Join Date: Aug 2007
Posts: 82
1Dave7 is on a distinguished road
Cool Moving average of another indicator

Figured it out.

Last edited by 1Dave7; 08-26-2007 at 03:40 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #763 (permalink)  
Old 08-26-2007, 04:03 AM
1Dave7's Avatar
Member
 
Join Date: Aug 2007
Posts: 82
1Dave7 is on a distinguished road
Question MA of a iCustom indicator

How do I code the statement in an ea to reference a Moving Average of 7, Smooth, of a iCustom indicator?? Which equates to using a Moving Average using first indicators data. You can do this in displaying a iCustom indicator and having a MA of the indicator (Using first indicators data), but how do you code it in an ea???

Please help me on this statement!

I thank you in advance for your help!

Dave

Can anybody help with this???? Please!!!!


I think I got it!:

LR0=iCustom(NULL,0,"Laguerre RSI LONG & SHORT ENTRY",0,0); //LOWER GAMMA


Still need help on this - Can you help me!

Last edited by 1Dave7; 08-28-2007 at 06:18 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #764 (permalink)  
Old 08-27-2007, 11:34 AM
Junior Member
 
Join Date: May 2007
Posts: 16
sbguy is on a distinguished road
checking for open positions within a range

I'm trying to check for open positions within x pips, if no position is open it will open one. It doesn't work and just opens positions continuously, can anyone help?

if(buyingPosition)
{
weBeBuying = true;
totalorders = OrdersTotal();
for(i=0;i<totalorders;i++)
{
OrderSelect(i,SELECT_BY_POS);
if((OrderSymbol()==Symbol()) && (OrderMagicNumber()==magicNumber))
{
type = OrderType();
if((type == OP_BUY) || (type == OP_BUYLIMIT))
{
if(((Bid+spread) - OrderOpenPrice()) > -0.0013)
weBeBuying = false;
}
}
}
}


if(weBeBuying==true)
OrderSend(Symbol(),OP_BUY,lots,Bid+spread,slippage ,0,0,NULL,magicNumber,0,Green);

Last edited by sbguy; 08-27-2007 at 11:48 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #765 (permalink)  
Old 08-28-2007, 08:56 PM
Member
 
Join Date: Apr 2006
Posts: 65
maje is on a distinguished road
Sere you can post your questions related to MQL4, and I'll do my best to answer them

for error code.

I have just returned account to me that on all my expert, I have an error code "OrderModify error 1", even with an expert like that of Coders Guru, below,
why?

Thanks !

//+------------------------------------------------------------------+
//| PriceCross.mq4 |
//| Coders Guru |
//| http://www.forex-tsd.com |
//+------------------------------------------------------------------+

#property copyright "Coders Guru"
#property link "http://www.forex-tsd.com"

//---- Includes
#include <stdlib.mqh>

//---- Trades limits
extern double TakeProfit = 200;
extern double TrailingStop = 50;
extern double StopLoss = 50;
extern double Lots = 0.1;
extern int Slippage = 5;

//--- External options
extern int CurrentBar = 1;
extern int HedgeLevel = 6;
extern double Expiration = 7200;
extern int Size = 4;
extern int Step = 1;
extern bool UseClose = true;


//--- Indicators settings
extern int MaMode = 3;
extern int MaPeriod = 24;

//--- Global variables
int MagicNumber = 101090;
string ExpertComment = "PriceCross";

bool LimitPairs = true;
bool LimitFrame = true;
int TimeFrame = 60;
string LP[] = {"EURUSD","USDCHF","GBPUSD","USDJPY"}; // add/remove the paris you want to limit.
bool Optimize = true;
int NumberOfTries = 5;
//+------------------------------------------------------------------
int init()
{
return(0);
}

int deinit()
{
return(0);
}
//+------------------------------------------------------------------

bool isNewSymbol(string current_symbol)
{
//loop through all the opened order and compare the symbols
int total = OrdersTotal();
for(int cnt = 0 ; cnt < total ; cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
string selected_symbol = OrderSymbol();
if (current_symbol == selected_symbol && OrderMagicNumber()==MagicNumber)
return (False);
}
return (True);
}

//+------------------------------------------------------------------+
int start()
{
int cnt, ticket, total,n;
double trend ;

if(Bars<100) {Print("bars less than 100"); return(0);}


if(LimitFrame)
{
if(Period()!=TimeFrame) {Print("This EA is not working with this TimeFrame!"); return(0);}
}
if(LimitPairs)
{
if(AllowedPair(Symbol()) == false) {Print("This EA is not working with this Currency!"); return(0);}
}

trend = iMA(NULL,0,MaPeriod,0,MaMode,PRICE_CLOSE,CurrentBa r);

//--- Trading conditions
bool BuyCondition = false , SellCondition = false , CloseBuyCondition = false , CloseSellCondition = false ;

if (Open[1]<trend && Close[1]>trend)
BuyCondition = true;

if (Open[1]>trend && Close[1]<trend)
SellCondition = true;

if (Open[1]>trend && Close[1]<trend)
CloseBuyCondition = true;

if (Open[1]<trend && Close[1]>trend)
CloseSellCondition = true;


total = OrdersTotal();

if(total < 1 || isNewSymbol(Symbol()))
{
if(BuyCondition) //<-- BUY condition
{
ticket = OpenOrder(OP_BUY); //<-- Open BUY order
CheckError(ticket,"BUY");

for(n=0 ; n< Size ; n++)
{
ticket = OpenPendingOrder(OP_BUYSTOP,Lots,HedgeLevel+(n*Ste p+1),Slippage,StopLoss,TakeProfit,ExpertComment,Ma gicNumber,CurTime() + Expiration);
}
return(0);
}
if(SellCondition) //<-- SELL condition
{
ticket = OpenOrder(OP_SELL); //<-- Open SELL order
CheckError(ticket,"SELL");

for(n=0 ; n < Size ; n++)
{
ticket = OpenPendingOrder(OP_SELLSTOP,Lots,HedgeLevel+(n*St ep+1),Slippage,StopLoss,TakeProfit,ExpertComment,M agicNumber,CurTime() + Expiration);
}
return(0);
}
return(0);
}

for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY) //<-- Long position is opened
{
if(UseClose)
{
if(CloseBuyCondition) //<-- Close the order and exit!
{
CloseOrder(OrderType()); return(0);
}
}

TrailOrder(OrderType()); return(0); //<-- Trailling the order
}
if(OrderType()==OP_SELL) //<-- Go to short position
{
if(UseClose)
{
if(CloseSellCondition) //<-- Close the order and exit!
{
CloseOrder(OP_SELL); return(0);
}
}

TrailOrder(OrderType()); return(0); //<-- Trailling the order
}
}
}

return(0);
}
//+------------------------------------------------------------------+

....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #766 (permalink)  
Old 08-29-2007, 04:25 AM
Junior Member
 
Join Date: Mar 2007
Posts: 10
Hartadi is on a distinguished road
Hi,

Is there anyway we can know that an order is already closed?
The illustration is like this :

I open 2 pending orders.

open #182 buy limit 0.17 EURUSD at 1.3005 sl: 1.2970 tp: 1.3013
open #183 buy limit 0.17 EURUSD at 1.3000 sl: 1.2968 tp: 1.3011

then

order #182, buy 0.17 EURUSD is opened at 1.3005
take profit #182 at 1.3013 (1.3013 / 1.3015)

i want to delete order #183 after order #182 is closed. The trigger is if order #182 closed then order #183 will be deleted.

Cheers
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #767 (permalink)  
Old 08-29-2007, 07:12 AM
Junior Member
 
Join Date: Aug 2007
Posts: 17
fxgroup is on a distinguished road
To CodersGuru : need help about 10 points 3 EA....

Hi CodersGuru,
I am new to forex trade and new to this forum too. First time, I am learning is EuroX2_sl, extended from 10 points 3 EA script. After did a few forward test, this EA did Open Position well but it did not Close Position well as I need to when market reverse. Maybe, something is wrong with the code ( cos' I am not a programmer ) and I think I need your help to solve it. Could please check which part may be wrong ?

Condition is :
1. OPEN BUY when indicator condition exist. ie: stochastic
2. CLOSE BUY when OPEN SELL indicator exist. ie:stochastic
3. OPEN SELL as the indicator condition ( no. 2 above ) exist. ie : stochastic
4. CLOSE SELL as the indicator condition ( no. 1 above ) exist. ie : stochastic

I think OPEN position is okay but the problem is with the CLOSE POSITION as it did not CLOSE ( BUY or SELL ) even when the indicator exist.

The code as I did is :

-------- part of script from EuroX2_sl extended from 10 points 3 as I think for close position -------

// it is important to enter the market correctly,
// but it is more important to exit it correctly...
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && // check for opened position
OrderType()<=OP_BUY &&
OrderType()>=OP_SELL &&
OrderType()>=OP_BUY &&

OrderSymbol()==Symbol()) // check for symbol
{
//+--------------------------------------------------------------


if(OrderType()==OP_BUY) // long position is opened
{
//+-------------------------------------------------------------------
//+ CONDITION FOR CLOSE POSITION
//+-------------------------------------------------------------------

//+--------------- CLOSE BUY POSITION ----------------------------
if ( Stoch_Main_M15_Cu < Stoch_Sig_M15_Cu )

//+------------------------------------------------------------------
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet) ; // close position
return(0); // exit
}
//+-----------------------------------------------------------------------
// check for trailing stop
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
//+---------------CLOSE SELL POSITION --------------------------------
else // go to short position
{ //+ DO NOT REMOVE

if(OrderType()==OP_SELL) // short position is opened
{
}
// should it be closed?
//+----------------------------------------------------------------------------
if ( Stoch_Main_M15_Cu > Stoch_Sig_M15_Cu )

//+-----------------------------------------------------------------------------
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet) ; // close position
return(0); // exit
}
//+----------------------------------------


// check for trailing stop
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Poi nt*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}

--------------------------------------------------------------

Thank you,
fxgroup

Last edited by fxgroup; 08-29-2007 at 10:01 AM. Reason: change a few words.... name of indicator
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #768 (permalink)  
Old 08-29-2007, 05:41 PM
european's Avatar
Senior Member
 
Join Date: Apr 2006
Posts: 284
european is on a distinguished road
Reading data from another currency pair window

My EA is on "GBPJPY" window, but I need to find ObjectDescription() form another window, say "USDJPY". (Unfortunately, it's a Pivot indicator which doeasn't return values from iCustom())

Anybody knows the way to refer to another (not current) pair window to be able to use functions like ObjectDescription() on it?
Or MQ4 doesn't allow it?

Thank you

euro

Last edited by european; 08-29-2007 at 05:50 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #769 (permalink)  
Old 08-29-2007, 06:29 PM
1Dave7's Avatar
Member
 
Join Date: Aug 2007
Posts: 82
1Dave7 is on a distinguished road
Smile How do I isolate profits of one currency from others??

PHP Code:
color color_of_pipsprofit;
color_of_pipsprofit White;

int m,totalbuy

totalbuy=OrdersTotal(); 
          
for(
m=0;m<totalbuy;m++) 

OrderSelect(mSELECT_BY_POSMODE_TRADES); 

if(
OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber() == Reference

{
pips_profit=OrderProfit();
}

 
    if(
pips_profit >= 0
    
    { 
    
    
color_of_pipsprofit Lime;  
  }
  else {
color_of_pipsprofit Red
  }


 
int n,totalsell

totalsell=OrdersTotal(); 
          
for(
n=0;n<totalsell;n++) 

OrderSelect(nSELECT_BY_POSMODE_TRADES); 

if(
OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber() == Reference
{
pips=OrderProfit();


}
    
    
    if(
pips_profit >= 0

    
color_of_pipsprofit Lime;   
  }
  else {
color_of_pipsprofit Red
  }



  
  
ObjectCreate("pips_profit"OBJ_LABEL000);
  
ObjectSetText("pips_profit",DoubleToStr(pips_profit,2),14"Verdana"color_of_pipsprofit);
  
ObjectSet("pips_profit"OBJPROP_CORNER3);
  
ObjectSet("pips_profit"OBJPROP_XDISTANCE35);
  
ObjectSet("pips_profit"OBJPROP_YDISTANCE20); 

 } 
I created this coding, but I cannot isolate the profits of one currency from other currencies being traded. What am I lacking in my code??

Please review. Thanks for your help!

Dave
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #770 (permalink)  
Old 08-29-2007, 07:11 PM
codersguru's Avatar
Senior Member
 
Join Date: Oct 2005
Posts: 986
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Lightbulb Profit

Try this code:


PHP Code:
 int start()

int total OrdersTotal(); 
for (
int cnt total cnt >=cnt--)
   {
      
OrderSelect(cntSELECT_BY_POSMODE_TRADES);
      
      if(
OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber)
      {
         Print(
Profit(OrderType(),OrderSymbol(),OrderOpenPrice());
      }
    }
  return(
0);          
}

double Profit(int typestring currencydouble open)
{
   if(
type==OP_BUY) return((MarketInfo(currency,MODE_BID) - open) / MarketInfo(currency,MODE_POINT) ); //case buy
   
if(type ==OP_SELL) return((open MarketInfo(currency,MODE_ASK)) / MarketInfo(currency,MODE_POINT)); //case buy
   
return(-1);

Quote:
Originally Posted by 1Dave7 View Post
PHP Code:
color color_of_pipsprofit;
color_of_pipsprofit White;

int m,totalbuy

totalbuy=OrdersTotal(); 
          
for(
m=0;m<totalbuy;m++) 

OrderSelect(mSELECT_BY_POSMODE_TRADES); 

if(
OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber() == Reference

{
pips_profit=OrderProfit();
}

 
    if(
pips_profit >= 0
    
    { 
    
    
color_of_pipsprofit Lime;  
  }
  else {
color_of_pipsprofit Red
  }


 
int n,totalsell

totalsell=OrdersTotal(); 
          
for(
n=0;n<totalsell;n++) 

OrderSelect(nSELECT_BY_POSMODE_TRADES); 

if(
OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber() == Reference
{
pips=OrderProfit();


}
    
    
    if(
pips_profit >= 0

    
color_of_pipsprofit Lime;   
  }
  else {
color_of_pipsprofit Red
  }



  
  
ObjectCreate("pips_profit"OBJ_LABEL000);
  
ObjectSetText("pips_profit",DoubleToStr(pips_profit,2),14"Verdana"color_of_pipsprofit);
  
ObjectSet("pips_profit"OBJPROP_CORNER3);
  
ObjectSet("pips_profit"OBJPROP_XDISTANCE35);
  
ObjectSet("pips_profit"OBJPROP_YDISTANCE20); 

 } 
I created this coding, but I cannot isolate the profits of one currency from other currencies being traded. What am I lacking in my code??

Please review. Thanks for your help!

Dave
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
histogram, forex, ZUP_v1.mq4

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

LinkBacks (?)
LinkBack to this Thread: http://www.forex-tsd.com/questions/270-ask.html
Posted By For Type Date
OzFx System:) - Page 639 This thread Refback 06-21-2008 10:53 PM
Forex SRDC Sidus Sibkis EA MT4 Forum OTCSmart This thread Refback 12-08-2007 12:46 PM


All times are GMT. The time now is 06:20 AM.