Forex



Go Back   Forex Trading > Downloads > Expert Advisors - Metatrader 4






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
 
Thread Tools Display Modes
  #1 (permalink)  
Old 05-21-2006, 04:06 PM
Junior Member
 
Join Date: Apr 2006
Posts: 3
exec is on a distinguished road
Need some help

Hi,
I have some problem with an expert advisor, it make Long order without any trouble , however it does not work with the Short order.
I dont understand why cause i have not a sufficient knowledge, somebody could just take a look? , thanks


//+------------------------------------------------------------------+
//| Stoch.mq4 |
//| For Eur/Usd 1H
//| Copyright © 2005, Jacob Yego |
//| http://PointForex.com |
//+------------------------------------------------------------------+

extern double TakeProfit = 250;
extern double Lots = 1.0;
extern double TrailingStop = 60;


//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{

double EMA1;
double EMA2;
double EMA3;
double EMA4;
double ATR;
double RSI;
double CCI;
double Stoch;
double Stochsig;
int cnt,ticket,tt=0, total;
// check TakeProfit on a chart of less than 200 bars
if(Bars<200)
{
Print("bars less than 200");
return(0);
}
if(TakeProfit<10)
{
Print("TakeProfit less than 10");
return(0); // check TakeProfit
}

// data in internal variables for access speed

EMA1=iMA(NULL,0,8,0,MODE_EMA,PRICE_CLOSE,0);
EMA2=iMA(NULL,0,100,0,MODE_EMA,PRICE_CLOSE,0);
EMA3=iMA(NULL,0,8,0,MODE_EMA,PRICE_CLOSE,1);
EMA4=iMA(NULL,0,100,0,MODE_EMA,PRICE_CLOSE,1);

ATR=iATR(NULL,0,20,0);
RSI=iRSI(NULL,0,14,PRICE_CLOSE,0);
CCI= iCCI(NULL,0,14,PRICE_CLOSE,0);
Stoch=iStochastic(NULL,0,14,3,3,MODE_SMA,0,MODE_MA IN,0);
Stochsig=iStochastic(NULL,0,14,3,3,MODE_SMA,0,MODE _SIGNAL,0);

// to ensure that only one trade per pair is entered to avoid multiplicity
total=OrdersTotal();
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol()==Symbol()) tt++;
}

{
if((total < 2) && tt==0) // you can change total to whatever
//number of pairs you want to trade
{
// no opened orders identified
if(AccountFreeMargin()<(1000*Lots))
{
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
// long position (BUY) possibility

if( EMA1 > EMA2 && EMA3 < EMA4 && RSI > 50.0 && CCI>0 && Stoch>Stochsig)
{Alert( "Buy Now");
}
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-2*ATR,Ask+TakeProfit*Point,"Stochy",77777,0,Green) ;
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);
}
// Short position (SELL) possibility
if(EMA2 > EMA1 && EMA4 < EMA3 && RSI<50 && CCI<0 && Stoch<Stochsig)
{Alert( "Sell Now");
}
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+2
*ATR,Bid-TakeProfit*Point,"Stochy",77777,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES )) Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
return(0);
}

//Exit Strategy
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symbol()) // check for symbol
{
if(OrderType()==OP_BUY) // long position is opened
{
// should it be closed?

if (RSI<30 && EMA2 > EMA1 && EMA4 < EMA3 && CCI<0 && Stoch<Stochsig )
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet) ; // close position
return(0); // exit
}
// Trailing stop Check
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
}
else // Move to short position
{
// should it be closed?

if (RSI>70 && EMA1 > EMA2 && EMA3 < EMA4 && CCI>0 && Stoch>Stochsig)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet) ; // close position
return(0); // exit
}
// trailing stop check
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);
}
}
}
}
}
}
return(0);
}
// the end.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #2 (permalink)  
Old 05-21-2006, 04:31 PM
igorad's Avatar
Senior Member
 
Join Date: Oct 2005
Location: Ukraine
Posts: 956
igorad is on a distinguished road
Hi,
I've fixed your EA - too many braces after BUY/Sell conditions.

Igor
Attached Files
File Type: mq4 Stoch_v1.mq4 (3.9 KB, 33 views)
__________________
Let's improve trade skills together
http://finance.groups.yahoo.com/group/TrendLaboratory
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #3 (permalink)  
Old 05-21-2006, 11:31 PM
Junior Member
 
Join Date: Apr 2006
Posts: 3
exec is on a distinguished road
Thanks a lot Igorad the problem is fixed.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks


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


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



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