You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
This EA in the tester only entered 1 trade in over 2 years worth of data.
Any ideas why? It's based on the alligator indicator and when the green line moves below the red line or vice versa, it should enter a trade. All trade closes are handled by the stop loss, which is modified at regular intervals.
[quote]
//+------------------------------------------------------------------+
//| èñïðàâëåííàÿ åâðîäîëëàð.mq4 |
//| Copyright © 2008, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009,"
extern double Lot = 0.11;
extern double SL = 500; //50pips
int ticket;
double LipsValue; //green
double TeethValue; //red
double JawsValue; //blue
//+------------------------------------------------------------------+
//| Calculate open positions |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
{
int buys=0,sells=0;
//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY) buys++;
if(OrderType()==OP_SELL) sells++;
}
}
//---- return orders volume
if(buys>0) return(buys);
else return(-sells);
}
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void CheckForOpen()
{
//check the alligator here
//if green below red sell, set SL = red
//int ticket;
//double TeethValue;
//double LipsValue;
TeethValue=iAlligator(NULL, 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORTEETH, 1);
LipsValue=iAlligator(NULL, 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORLIPS, 1);
JawsValue=iAlligator(NULL, 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORJAW, 1);
//if distance between lips and teeth is not greater than x then don't bother
//if (MathAbs(JawsValue-TeethValue) >= 0.003) {
if(LipsValue<TeethValue)
{
//int OrderSend( string symbol, int cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment=NULL, int magic=0, datetime expiration=0, color arrow_color=CLR_NONE)
ticket=OrderSend(Symbol(),OP_SELL,Lot,Bid,3,Bid+SL*Point,0.00000,"My order",0,0,Red);
if(ticket<0)
{
Print("OrderSend failed with error #",GetLastError());
return(0);
}
}
//if green above red buy, set SL = red
if(LipsValue>TeethValue)
{
//int OrderSend( string symbol, int cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment=NULL, int magic=0, datetime expiration=0, color arrow_color=CLR_NONE)
ticket=OrderSend(Symbol(),OP_BUY,Lot,Ask,3,Ask-SL*Point,0.00000,"My order",0,0,Green);
if(ticket<0)
{
Print("OrderSend failed with error #",GetLastError());
return(0);
}
}
}
//}
//+------------------------------------------------------------------+
//| Modify stop loss on existing orders |
//+------------------------------------------------------------------+
void ModifyExisting()
{
//set SL == red line
OrderSelect(ticket,SELECT_BY_TICKET);
int order_type=OrderType();
if (order_type == OP_BUY) {
OrderModify(OrderTicket(),OrderOpenPrice(),JawsValue,OrderTakeProfit(),0,Green);
return(0);}
if (order_type == OP_SELL) {
OrderModify(OrderTicket(),OrderOpenPrice(),JawsValue,OrderTakeProfit(),0,Red);
return(0);}
}
//+------------------------------------------------------------------+
//| Start function |
//+------------------------------------------------------------------+
void start()
{
//---- calculate open orders by current symbol
//we only need to check for an open here as the stop loss on existing orders will manage the close
if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
else ModifyExisting();
//---
}
//+-----------------------------------------------+
[/quote]