Orders Execution
0
Views
0
Downloads
0
Favorites
MA-EA-TSTOPS
//+------------------------------------------------------------------+
//| MA-EA-TSTOPS.mq4 |
//| Copyright(c) 2010 Masaru Sasaki |
//| http://youtarou.blogzine.jp |
//+------------------------------------------------------------------+
// < MetaTrader4 FX(O×ÖØàæø)©®gCOVXeEA >
// u\[XR[höJRv
// *êÊIÈÂlg[_[ÌêlƵÄAvOÉsµêÈûÖÌ
// QlƵÄöJ·éɵܵ½B
// ©ªÍK¢ÉàvO~Oðï¡ÆµÄ½Tf[vO}[
// Å é©çAVXevO~O(EA)ªÅ«Üµ½B
// vO~OÍK¤æèAµêë¾Æv¢Ü·B
//
// uÖ~v
// *±ÌvO\[XR[hð»ÌÜܬpµ½\tgÌÌð
// êØÖ~vµÜ·B
//
// uÆÓv
// *±ÌvOÉîÃs×Ìʶµ½áQA¹¸ÈÇÉ¢Ä
// ìÒÍêØÌÓCð¢Ü¹ñB
//
// uà¾v
// *ÙÊg[hÉÄGg[µ½ãÌgCOXgbvð©®»·é
// EAÅ·B(©®ÍµÜ¹ñB)
// }üµ½`[gÌÊÝÅA1I[_[ÌÝεܷB
// ¡I[_[ÉÍεĢܹñB
// gpû@ƵÄÍAÙÊg[hÉÄGg[µ½ãÉEAÒ®ðÂ
// Ʒ龯ŷB
// AgCOXgbvû@ðêè(pipsPÊ)©êèų¢
// (wèÍÍÌlÀl)©ðIðūܷB
// êèÍpipsPÊÅÝèūܷB
//
// (ÓFI[_[Ì}WbNÔð©Ä¢Ü¹ñÌÅA¼ÌEAů¶ÊÝ
// ÆÍ¤¶Å«Ü¹ñB
//
// QlÐFFX^g[_[üå (PanRolling)
// FX^g[_[ÀHvO~O (PanRolling)
//
#property copyright "Copyright(c) 2010 Masaru Sasaki"
#property link "http://youtarou.blogzine.jp"
// êèų¢gCOXgbvÌo[ð©é
extern int HL_period = 20;
// êègCOXgbvðIðµ½ÌTCY(pips)
extern int sp_size = 5;
// gCOXgbvû@ÌIð(WÍêèų¢û®)
extern int TrailingStop_select = 1;
// fobO on/off tO
bool debug = false;
// êèų¢gCOXgbvÖ(wèµ½o[ÌlAÀl)
bool TrailingStopHL(int HL_period, double ask, double bid, int ticket, int type)
{
// gCOXgbvvZ
double spread = ask-bid;
double HH = High[iHighest(NULL, 0, MODE_HIGH, HL_period, 1)] + spread;
double LL = Low[iLowest(NULL, 0, MODE_LOW, HL_period, 1)];
bool ret = false;
OrderSelect(ticket, SELECT_BY_TICKET);
if( type == OP_BUY )
{
if( LL > OrderStopLoss() )
ret = OrderModify( ticket, OrderOpenPrice(), LL, OrderTakeProfit(), 0, Blue);
}
if( type == OP_SELL )
{
if( HH < OrderStopLoss() || OrderStopLoss() == 0 )
ret = OrderModify( ticket, OrderOpenPrice(), HH, OrderTakeProfit(), 0, Blue);
}
return(ret);
}
// êèÌgCOXgbvÖ(pipsPÊ)
bool TrailingStopSetsize(int setsize, double point, double ask, double bid, int ticket, int type)
{
// gCOXgbvvZ
bool ret = false;
double profit = 0.0;
double set_size = setsize * point;
double spread = ask - bid;
int i = 1000;
OrderSelect(ticket, SELECT_BY_TICKET);
while( i > 0 )
{
if( type == OP_BUY )
{
profit = ask - OrderOpenPrice() - (set_size * i + spread);
if( profit > 0 )
{
ret = OrderModify(ticket, OrderOpenPrice(), OrderStopLoss() + set_size, OrderTakeProfit(), 0, Blue);
return(ret);
}
}
if( type == OP_SELL )
{
profit = OrderOpenPrice() - bid - (set_size * i + spread);
if( profit > 0 )
{
ret = OrderModify(ticket, OrderOpenPrice(), OrderStopLoss() - set_size, OrderTakeProfit(), 0, Blue);
return(ret);
}
}
i--;
}
return(false);
}
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
// o[ÌnlÅg[hÂ\©`FbN
if( Volume[0] > 1 || IsTradeAllowed() == false )
return(0);
// I[_[L³Ì`FbN
int ticket = 0; bool ret = false;
for(int i = 0; i < OrdersTotal(); i++ )
{
if(OrderSelect(i, SELECT_BY_POS) == false) break;
if(OrderSymbol() != Symbol()) continue;
int type = OrderType();
if(type == OP_BUY || type == OP_SELL)
{
ticket = OrderTicket();
break;
}
}
if(ticket == 0) return(0);
if( TrailingStop_select == 1 )
{
// êèų¢gCOXgbvÖÄÑoµ
ret = TrailingStopHL(HL_period, Ask, Bid, ticket, type);
}
else
{
// êèÌgCOXgbvÖÄÑoµ
ret = TrailingStopSetsize(sp_size, Point, Ask, Bid, ticket, type);
}
// fobO\¦
if( debug == true )
{
Print("Open :", Open[1], "Close :", Close[1]);
Print("Trailing stop :", ret);
}
return(0);
}
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---