MAcross-EXP





//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
extern double Lots = 1.0;
extern int    OrderPoint = 5;
extern int    SafePoint = 15;
extern int    TakeProfit = 30;
//extern int    StopLoss = 0;
extern int    TrailingStop = 25;
extern string IndicatorName = "MAcross";
datetime OrderTime;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init ()  { return(0); }
int deinit() { Comment(""); return(0); }

int start()
{
  double Dn,Up;
  double PriceBuyOrder,StopLossBuyOrder,TimeOpenBuyOrder,PriceSelOrder,StopLossSelOrder,TimeOpenSelOrder,PriceBuy,PriceSel,PriceOrder;
  double StopLevel=MarketInfo(Symbol(),MODE_STOPLEVEL)*Point;
  int ticket,TicketBuyOrder,TicketSelOrder;
  int i,cnt,SLoss,Order,OrderBuy,OrderSel,Pos,PosBuy,PosSel;

  Order=0; OrderBuy=0; OrderSel=0; Pos=0; PosBuy=0; PosSel=0;
  TicketBuyOrder=0; TicketSelOrder=0; PriceBuyOrder=0; PriceSelOrder=0; PriceBuy=0; PriceSel=0;
  for(cnt=0; cnt<OrdersTotal(); cnt++)
  {
    OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
    if(OrderSymbol()==Symbol())
    {
      if(OrderType()==OP_BUYSTOP)  { OrderBuy++; TicketBuyOrder=OrderTicket(); PriceBuyOrder=OrderOpenPrice(); StopLossBuyOrder=OrderStopLoss(); TimeOpenBuyOrder=OrderOpenTime(); if(TimeOpenBuyOrder>OrderTime) OrderTime=TimeOpenBuyOrder; }
      if(OrderType()==OP_SELLSTOP) { OrderSel++; TicketSelOrder=OrderTicket(); PriceSelOrder=OrderOpenPrice(); StopLossSelOrder=OrderStopLoss(); TimeOpenSelOrder=OrderOpenTime(); if(TimeOpenSelOrder>OrderTime) OrderTime=TimeOpenSelOrder; }
      if(OrderType()==OP_BUY)      { PosBuy++; PriceBuy=OrderOpenPrice(); }
      if(OrderType()==OP_SELL)     { PosSel++; PriceSel=OrderOpenPrice(); }
    }
  }
  Order = OrderBuy+OrderSel;
  Pos = PosBuy+PosSel;

  Dn=iCustom(NULL,0,IndicatorName,0,1);
  Up=iCustom(NULL,0,IndicatorName,1,1);

	if(Order<2 && Pos<2 && Time[0]>OrderTime+Period()*60)
  {
    if(Up!=0 && OrderBuy==0 && PosBuy==0)
    {
      PriceOrder=High[1]+OrderPoint*Point+(Ask-Bid);
      if(Ask>PriceOrder-StopLevel) PriceOrder=Ask+OrderPoint*Point+(Ask-Bid);
      ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,PriceOrder,3,Low[1]-OrderPoint*Point,PriceOrder+TakeProfit*Point,"BuyOrder_ASC",255,0,CLR_NONE);
      if(ticket!=0)
      {
        OrderTime=Time[0];
        PlaySound("expert.wav");
      }
      return(0);
    }

    if(Dn!=0 && OrderSel==0 && PosSel==0)
    {
      PriceOrder=Low[1]-OrderPoint*Point;
      if(Bid<PriceOrder+StopLevel) PriceOrder=Bid-OrderPoint*Point;
      ticket=OrderSend(Symbol(),OP_SELLSTOP,Lots,PriceOrder,3,High[1]+OrderPoint*Point+(Ask-Bid),PriceOrder-TakeProfit*Point,"SellOrder_ASC",255,0,CLR_NONE);
      if(ticket!=0)
      {
        OrderTime=Time[0];
        PlaySound("expert.wav");
      }
      return(0);
    }
  }

  for(cnt=0; cnt<OrdersTotal(); cnt++)
  {
    OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
    if(OrderSymbol()==Symbol())
    {
      if(OrderBuy!=0 && OrderSel!=0)
      {
        if(TimeOpenBuyOrder<TimeOpenSelOrder) { OrderDelete(TicketBuyOrder); return(0); }
        if(TimeOpenBuyOrder>TimeOpenSelOrder) { OrderDelete(TicketSelOrder); return(0); }
      }

      if(OrderType()==OP_BUY)
      {
	      if(SafePoint!=0 && Bid>OrderOpenPrice()+SafePoint*Point && (OrderStopLoss()<OrderOpenPrice() || OrderStopLoss()==0))
       	{ ModifyStopLoss(OrderOpenPrice()+Point); return(0); }

       	if(OrderSel!=0)
       	{
         	if(Bid>StopLossSelOrder)
         	{ OrderDelete(TicketSelOrder); PlaySound("expert.wav"); return(0); }

       	  if(SafePoint==0 && OrderStopLoss()!=PriceSelOrder)
         	{ ModifyStopLoss(PriceSelOrder); return(0); }
        }
	      else if(OrderStopLoss()>OrderOpenPrice() && OrderStopLoss()<Bid-TrailingStop*Point)
       	{ ModifyStopLoss(Bid-TrailingStop*Point); PlaySound("expert.wav"); return(0); }
      }

      if(OrderType()==OP_SELL)
      {
	      if(SafePoint!=0 && Ask<OrderOpenPrice()-SafePoint*Point && (OrderStopLoss()>OrderOpenPrice() || OrderStopLoss()==0))
       	{ ModifyStopLoss(OrderOpenPrice()-Point); return(0); }

       	if(OrderBuy!=0)
       	{
         	if(Ask<StopLossBuyOrder)
         	{ OrderDelete(TicketBuyOrder); PlaySound("expert.wav"); return(0); }

       	  if(SafePoint==0 && OrderStopLoss()!=PriceBuyOrder)
         	{ ModifyStopLoss(PriceBuyOrder); PlaySound("expert.wav"); return(0); }
        }
        else if(OrderStopLoss()<OrderOpenPrice() && OrderStopLoss()>Ask+TrailingStop*Point) 
       	{ ModifyStopLoss(Ask+TrailingStop*Point); PlaySound("expert.wav"); return(0); }
   		}
 	 	}
	}
	
  return(0);
}
//************************************************************************************************
void ModifyStopLoss(double StopLoss)
{
  OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(StopLoss,Digits),OrderTakeProfit(),0,CLR_NONE);
  PlaySound("expert.wav");
  return(0);
}
//************************************************************************************************





Sample





Analysis



Market Information Used:

Series array that contains open time of each bar
Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar


Indicator Curves created:


Indicators Used:




Custom Indicators Used:
IndicatorName

Order Management characteristics:
Checks for the total of open orders

It automatically opens orders when conditions are reached
It can change open orders parameters, due to possible stepping strategy

Other Features:

It plays sound alerts

BackTest : EURUSD on H1

From 2009-08-01 to 2009-10-01 Profit Factor:0.00 Total Net Profit:0.00

BackTest : EURUSD on H1

From 2009-12-01 to 2010-01-17 Profit Factor:0.00 Total Net Profit:0.00

BackTest : EURUSD on H1

From 2010-04-01 to 2010-04-30 Profit Factor:0.00 Total Net Profit:0.00

BackTest : EURUSD on H1

From 2010-05-01 to 2010-05-31 Profit Factor:0.00 Total Net Profit:0.00

BackTest : EURUSD on H1

From 2010-06-01 to 2010-06-30 Profit Factor:0.00 Total Net Profit:0.00

BackTest : GBPUSD on H1

From 2010-01-01 to 2010-02-27 Profit Factor:0.00 Total Net Profit:0.00

BackTest : USDCAD on H1

From 2009-12-01 to 2010-01-01 Profit Factor:0.00 Total Net Profit:0.00

BackTest : USDJPY on H1

From 2009-11-01 to 2009-11-30 Profit Factor:0.00 Total Net Profit:0.00

Request Backtest for MAcross-EXP


From : (yyyy/mm/dd) To: (yyyy/mm/dd)

Pair: Period: