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
  #1051 (permalink)  
Old 04-17-2008, 02:55 PM
Junior Member
 
Join Date: Oct 2006
Posts: 16
Bone is on a distinguished road
I have an indicator similar to this one. Does anybody know how to pass it's values to EA? I've tried to use buffer, this way

double Trend[];
...
SetIndexBuffer(0,Trend);
...
Trend[0]=UpRating;
return(0);
}

I don't know if it works but I know that all indicator's inscription has gone. Any ideas about it?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1052 (permalink)  
Old 04-18-2008, 09:21 AM
Junior Member
 
Join Date: Jan 2008
Posts: 12
forexarchitect is on a distinguished road
need modification help

Hello fellow trader

I need help with this code.

current function is to close first open orders by time and any following orders, mean it could be more than 2 orders closed in the same time.

Question: how do I change it to make it close the FIRST 2 open orders by time ONLY.
here the code.
thanks for help

//+------------------------------------------------------------------+
//| Close Condition Type 2 |
//+------------------------------------------------------------------+

void CheckCloseConditionType2()
{
int Orders[];
int i, j;

ArrayResize(Orders, 0);

int cnt = OrdersTotal();
for (i=0; i < cnt; i++)
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
if (OrderSymbol() != Symbol()) continue;
if (OrderMagicNumber() != Magic) continue;

int type = OrderType();
if (type == OP_BUY || type == OP_SELL)
{
int size = ArraySize(Orders);
ArrayResize(Orders, size+1);
Orders[size] = OrderTicket();
}
}

//-----

size = ArraySize(Orders);
for (i=0; i < size; i++)
{
if (!OrderSelect(Orders[i], SELECT_BY_TICKET)) continue;
if (OrderCloseTime() > 0) continue;
datetime tm1 = OrderOpenTime();

for (j=i+1; j < size; j++)
{
if (!OrderSelect(Orders[j], SELECT_BY_TICKET)) continue;
if (OrderCloseTime() > 0) continue;
datetime tm2 = OrderOpenTime();

if (tm1 > tm2)
{
int ticket = Orders[i];
Orders[i] = Orders[j];
Orders[j] = ticket;
}
}
}

//-----

for (i = size-1; i >= 1; i--)
{
double Profit = ArrayGetOrdersProfit(Orders);

if ((Profit >= TotalTakeProfit && TotalTakeProfit > 0) || (Profit >= Profit2Exit && Profit2Exit > 0))
{
Print("[Enter] Close by condition Type2");

string msg1 = "";
string msg2 = "";

double P;
double T.P = 0;

for (j=0; j < size; j++)
{
if (Orders[j] == -1) continue;
if (!OrderSelect(Orders[j], SELECT_BY_TICKET)) continue;
if (OrderCloseTime() > 0) continue;

if (StringLen(msg1) > 0) msg1 = msg1 + " + ";
msg1 = msg1 + "order " +Orders[j];

GetOrderProfit(Orders[j], P);
if (StringLen(msg2) > 0) msg2 = msg2 + " + ";
msg2 = msg2 +DoubleToStr(P, 2);
T.P += P;
}

Print("Close: " + msg1);
Print("Profit: " + msg2 + " = " + DoubleToStr(T.P, 2));

ArrayCloseOrders(Orders);

Print("[Exit] Close by condition Type2");
return;
}

Orders[i] = -1;
}
}
__________________
creativity + common sense + a bit of humor = lots of pipp
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1053 (permalink)  
Old 04-22-2008, 03:46 PM
yyc196's Avatar
Senior Member
 
Join Date: Dec 2006
Location: Earth
Posts: 197
yyc196 is on a distinguished road
How to count the numbers of pips

Hi,

I realized that after the market has gone for a great moves (up or down trend). The remaining market is somehow risky to trade with. I am trying to program an EA to avoid entering any trades say after a great move of about 90pips.

I need to know how to calculate the number of pips from first bar at 8am (london market open) to the current bar. If the market has already been moved for more than 90pips I will not take any trade.

Can someone code a few line to give me some clues? Many thanks and appreciated.

Shek
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1054 (permalink)  
Old 04-22-2008, 05:04 PM
Senior Member
 
Join Date: Feb 2006
Posts: 513
Michel is on a distinguished road
Quote:
Originally Posted by yyc196 View Post
Hi,

I realized that after the market has gone for a great moves (up or down trend). The remaining market is somehow risky to trade with. I am trying to program an EA to avoid entering any trades say after a great move of about 90pips.

I need to know how to calculate the number of pips from first bar at 8am (london market open) to the current bar. If the market has already been moved for more than 90pips I will not take any trade.

Can someone code a few line to give me some clues? Many thanks and appreciated.

Shek
If needed, check first that you are later than 8 am:
PHP Code:
if(Hour() < 8) return; 
Then, find the max and min of the current day. (if its ok for you, its easier than from 8 am):
PHP Code:
double Max iHigh(Symbol(), PERIOD_D10);
double Min iLow(Symbol(), PERIOD_D10);
int Range = (Max Min) / Point;
if(
Range 90) return;
... 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1055 (permalink)  
Old 04-23-2008, 04:02 PM
umarannur's Avatar
Member
 
Join Date: Nov 2007
Location: Malaysia
Posts: 49
umarannur is on a distinguished road
I try to add a new feature to this indicator High_Low (Zigzag) V2 so that for every time its formed a new high-low the ZZ will alert me. Don't know where it go wrong. The indi instead doesn't show up on my screen. Anyone?? Help me please.. I'm new to coding, please refine what I have done so that the indi will do just like what I want in the above. Here's the code.

High_Low v2 (ZigZag) with Alert.mq4
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1056 (permalink)  
Old 04-24-2008, 02:08 PM
Member
 
Join Date: Feb 2007
Location: Seremban, Negeri Sembilan, Malaysia
Posts: 30
ahmad.ariffin is on a distinguished road
Hi,

How to draw a rectangle background? I mean through conding. I know it uses ObjectCreate() but I don't know how to write it the way I'm suppose to.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1057 (permalink)  
Old 04-24-2008, 06:24 PM
Senior Member
 
Join Date: Oct 2007
Posts: 198
Dave137 is on a distinguished road
Question Time Period of Graph

What is the code to find out what time period the graph is running at? So I can change variable settings for each time period.

if(?????) . . .

Dave
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1058 (permalink)  
Old 04-24-2008, 07:26 PM
Senior Member
 
Join Date: Feb 2006
Posts: 513
Michel is on a distinguished road
Quote:
Originally Posted by Dave137 View Post
What is the code to find out what time period the graph is running at? So I can change variable settings for each time period.

if(?????) . . .

Dave
PHP Code:
if(Period() == PERIOD_M15) ... 
or:
PHP Code:
switch(Period())
{
   case 
PERIOD_M1:
      ...
   break;
   case 
PERIOD_M5:
      ...
   break;
   ...

Sometime it maybe easier to work with indices:
PHP Code:
int tfIndex ArrayBsearch({PERIOD_M1PERIOD_M5PERIOD_M15, ...}, Period()); 
Example : how to display the period by the string you want:
PHP Code:
int Periods[] = {PERIOD_M1PERIOD_M5PERIOD_M15, ...};
string sPeriods[]  = {" M1"" M5"" M15"" M30"" Hourly"" 4 hours"" Daily"" Weekly"...};
int tfIndex ArrayBsearch(PeriodsPeriod());
comment(Symbol() + sPeriods[tfIndex]); 

Last edited by Michel; 04-24-2008 at 07:50 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1059 (permalink)  
Old 04-24-2008, 08:03 PM
Senior Member
 
Join Date: Oct 2007
Posts: 198
Dave137 is on a distinguished road
Smile

Thank You Michel!

I hope that this EA I am creating will be the one! Your help is highly appreciated!

Dave
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1060 (permalink)  
Old 04-27-2008, 08:12 AM
Junior Member
 
Join Date: Dec 2007
Posts: 5
bearfoot090 is on a distinguished road
hi there!

can some here help me add this function. Make it to close trade when the bar is completed or in another word to make it close the trade when the next bar appear.( doesnt matter the trade is profit or loss )


extern int SystemMagicNumber=197;
extern double TakeProfit = 100;
extern double StopLoss = 500;
extern double Lots=0.1;
extern double TrailingStop = 0;
extern int MaxBuyTrades=5;
extern int MaxSellTrades=5;

int start()
{

if( HavePosThisBar(SystemMagicNumber)==false
&&iMA(NULL,0,5,0,MODE_SMA, PRICE_CLOSE,1)<iMA(NULL,0,15,0,MODE_EMA, PRICE_CLOSE,1)
&& iMA(NULL,0,5,0,MODE_SMA, PRICE_CLOSE,2)>iMA(NULL,0,15,0,MODE_EMA, PRICE_CLOSE,2)
&& SellPositionsCount()<MaxSellTrades


)
{
OrderSend(Symbol(),OP_SELL,Lots,Bid,0,Bid+StopLoss *Point,Bid-TakeProfit*Point,"",SystemMagicNumber,0,Red);


return(0);
}



if( HavePosThisBar(SystemMagicNumber)==false
&& iMA(NULL,0,5,0,MODE_SMA, PRICE_CLOSE,1)>iMA(NULL,0,15,0,MODE_EMA, PRICE_CLOSE,1)
&& iMA(NULL,0,5,0,MODE_SMA, PRICE_CLOSE,2)<iMA(NULL,0,15,0,MODE_EMA, PRICE_CLOSE,2)
&& BuyPositionsCount()<MaxBuyTrades

)
{
OrderSend(Symbol(),OP_BUY,Lots,Ask,0,Ask-StopLoss*Point,Ask+TakeProfit*Point,"",SystemMagic Number,0,Blue);

return(0);
}






for(int cnt=OrdersTotal()-1;cnt>=0;cnt--)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol())
{
if (OrderType()==OP_SELL)
{
if (TrailingStop>0)
{
if (OrderOpenPrice()-Ask>TrailingStop*Point)
{
if (OrderStopLoss() == 0 || OrderStopLoss()>(Ask+Point*TrailingStop))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Poi nt*TrailingStop,OrderTakeProfit(),0,Purple);
return(0);
}
}
}
}

if (OrderType()==OP_BUY)
{
if (TrailingStop>0)
{
if (Bid-OrderOpenPrice()>TrailingStop*Point)
{
if (OrderStopLoss()<(Bid-Point*TrailingStop))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Yellow);
return(0);
}
}
}
}
}
}








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


bool HavePosThisBar(int magic)
{
int cnt;
bool Result=false;
for(cnt=0; cnt<=OrdersHistoryTotal()-1; cnt++)
if(OrderSelect(cnt, SELECT_BY_POS, MODE_HISTORY))
if((OrderSymbol() == Symbol()) &&(OrderMagicNumber() == magic) && Time[0]<=OrderOpenTime())
{
Result=true;
break;
}
for(cnt=0; cnt<=OrdersTotal()-1; cnt++)
if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
if((OrderSymbol() == Symbol()) &&(OrderMagicNumber() == magic) && Time[0]<=OrderOpenTime())
{
Result=true;
break;
}
return(Result);
}


int BuyPositionsCount()
{
int Result=0;
for(int cnt=0; cnt<=OrdersTotal()-1; cnt++)
if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
if((OrderSymbol() == Symbol()) &&(OrderMagicNumber() == SystemMagicNumber) &&
(OrderType()==OP_BUY)

)
{
Result++;

}
return(Result);
}

int SellPositionsCount()
{
int Result=0;
for(int cnt=0; cnt<=OrdersTotal()-1; cnt++)
if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
if((OrderSymbol() == Symbol()) &&(OrderMagicNumber() == SystemMagicNumber) &&
(OrderType()==OP_SELL)

)
{
Result++;
}
return(Result);
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
histogram

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 On
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 09:53 PM
Forex SRDC Sidus Sibkis EA MT4 Forum OTCSmart This thread Refback 12-08-2007 11:46 AM


All times are GMT. The time now is 10:44 PM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.