ASC_EXP_v1[1].0-H1

Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt can change open orders parameters, due to possible stepping strategy
Miscellaneous
It plays sound alerts
0 Views
0 Downloads
0 Favorites
ASC_EXP_v1[1].0-H1
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
extern double Lots = 30.0;
extern int    OrderPoint = 5;
extern int    SafePoint = 15;
extern int    TakeProfit = 25;
//extern int    StopLoss = 0;
extern int    TrailingStop = 25;
extern string IndicatorName = "ASCTrend1sig";
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init ()  { return(0); }
int deinit() { Comment(""); return(0); }

int start()
{
  double Dn,Up;
  double PriceBuyOrder,PriceSelOrder,PriceBuy,PriceSel;
  int 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(); }
      if(OrderType()==OP_SELLSTOP) { OrderSel++; TicketSelOrder=OrderTicket(); PriceSelOrder=OrderOpenPrice(); }
      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*/)
  {
    if(Up!=0 && OrderBuy==0 /*&& PosBuy==0*/)
    {
      OrderSend(Symbol(),OP_BUYSTOP,Lots,High[1]+OrderPoint*Point+(Ask-Bid),3,Low[1]-OrderPoint*Point,0,"BuyOrder",255,0,CLR_NONE);
      PlaySound("expert.wav");
      return(0);
    }

    if(Dn!=0 && OrderSel==0 /*&& PosSel==0*/)
    {
      OrderSend(Symbol(),OP_SELLSTOP,Lots,Low[1]-OrderPoint*Point,3,High[1]+OrderPoint*Point+(Ask-Bid),0,"SelOrder",255,0,CLR_NONE);
      PlaySound("expert.wav");
      return(0);
    }
  }

  for(cnt=0; cnt<OrdersTotal(); cnt++)
  {
    OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
    if(OrderSymbol()==Symbol())
    {
      if(OrderType()==OP_BUY)
      {
	      if(SafePoint!=0 && Bid>OrderOpenPrice()+SafePoint*Point && (OrderStopLoss()<OrderOpenPrice() || OrderStopLoss()==0))
       	{ OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point,OrderTakeProfit(),0,CLR_NONE); PlaySound("expert.wav"); return(0); }

       	if(OrderSel!=0 && OrderStopLoss()!=PriceSelOrder && OrderStopLoss()<OrderOpenPrice())
       	{ OrderModify(OrderTicket(),OrderOpenPrice(),PriceSelOrder,OrderTakeProfit(),0,CLR_NONE); PlaySound("expert.wav"); return(0); }

       	if(OrderSel!=0 && OrderStopLoss()>OrderOpenPrice()+2*Point)
       	{ OrderDelete(TicketSelOrder); PlaySound("expert.wav"); return(0); }

	      if(OrderStopLoss()>OrderOpenPrice() && OrderStopLoss()<Bid-TrailingStop*Point)
       	{ OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-TrailingStop*Point,Digits),OrderTakeProfit(),0,CLR_NONE); PlaySound("expert.wav"); return(0); }
      }

      if(OrderType()==OP_SELL)
      {
	      if(SafePoint!=0 && Ask<OrderOpenPrice()-SafePoint*Point && (OrderStopLoss()>OrderOpenPrice() || OrderStopLoss()==0))
       	{ OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-Point,OrderTakeProfit(),0,CLR_NONE); PlaySound("expert.wav"); return(0); }

       	if(OrderBuy!=0 && OrderStopLoss()!=PriceBuyOrder && OrderStopLoss()>OrderOpenPrice())
       	{ OrderModify(OrderTicket(),OrderOpenPrice(),PriceBuyOrder,OrderTakeProfit(),0,CLR_NONE); PlaySound("expert.wav"); return(0); }

       	if(OrderBuy!=0 && OrderStopLoss()<OrderOpenPrice()-2*Point)
       	{ OrderDelete(TicketBuyOrder); PlaySound("expert.wav"); return(0); }

        if(OrderStopLoss()<OrderOpenPrice() && OrderStopLoss()>Ask+TrailingStop*Point) 
       	{ OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+TrailingStop*Point,Digits),OrderTakeProfit(),0,CLR_NONE); PlaySound("expert.wav"); return(0); }
   		}
 	 	}
	}
	
  return(0);
}

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---