Orders Execution
0
Views
0
Downloads
0
Favorites
ts-gbp-jpy_1t
/*
* GBP/JPY strategy http://www.forexinvestimentos.com/forum/smf/index.php/topic,1029.0.html
*/
#property copyright "Felipe Schmitt"
// Universal settings
// Money management
extern double FixedLots = 0.3; // if > 0.0 fixed lots used
extern double Risk = 0.01; // per cent of free margin of a single offer
extern int StopLoss = 50;
extern int TakeProfit1 = 100;
//extern int TakeProfit2 = 70;
//extern int TakeProfit3 = 60;
extern int DayStartHour = 4;
extern int StopShift = 0;
extern int OrderExpirationHours = 20;
bool extremsSet = false;
double dayHigh = 0.0;
double dayLow = 0.0;
void CloseOpenPositions()
{
//for(int i = 0; i < OrdersTotal(); i++)
for(int i = OrdersTotal(); i>=0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if(OrderType() == OP_BUY || OrderType() == OP_SELL)
{
double price = Ask;
if(OrderType() == OP_BUY)
price = Bid;
OrderClose(OrderTicket(), OrderLots(), price, 3);
}
}
}
}
void SetPositions()
{
// calculate lot size
double lots;
if(FixedLots > 0.0)
lots = FixedLots;
else
lots = NormalizeDouble(AccountFreeMargin() * Risk / (StopLoss * MarketInfo(Symbol(), MODE_TICKVALUE)), 1);
CloseOpenPositions();
double price = Ask;
int operation = OP_BUYSTOP;
// if(Ask < dayHigh)
{
operation = OP_BUYSTOP;
price = dayHigh + StopShift * Point;
}
OrderSend(Symbol(), OP_BUYSTOP, lots, price, 3, price - StopLoss * Point, price + TakeProfit1 * Point, NULL, 0, TimeCurrent() + D'1970.01.01 1' * OrderExpirationHours, Blue);
//OrderSend(Symbol(), OP_BUYSTOP, lots, price, 3, price - StopLoss * Point, price + TakeProfit2 * Point, NULL, 0, TimeCurrent() + D'1970.01.01 1' * OrderExpirationHours, Blue);
// OrderSend(Symbol(), OP_BUYSTOP, lots, price, 3, price - StopLoss * Point, price + TakeProfit3 * Point, NULL, 0, TimeCurrent() + D'1970.01.01 1' * OrderExpirationHours, Blue);
price = Bid;
operation = OP_SELLSTOP;
// if(Bid > dayLow)
{
operation = OP_SELLSTOP;
price = dayLow - StopShift * Point;
}
OrderSend(Symbol(), OP_SELLSTOP, lots, price, 3, price + StopLoss * Point, price - TakeProfit1 * Point, NULL, 0, TimeCurrent() + D'1970.01.01 1' * OrderExpirationHours, Red);
//OrderSend(Symbol(), OP_SELLSTOP, lots, price, 3, price + StopLoss * Point, price - TakeProfit2 * Point, NULL, 0, TimeCurrent() + D'1970.01.01 1' * OrderExpirationHours, Red);
// OrderSend(Symbol(), OP_SELLSTOP, lots, price, 3, price + StopLoss * Point, price - TakeProfit3 * Point, NULL, 0, TimeCurrent() + D'1970.01.01 1' * OrderExpirationHours, Red);
}
void start()
{
if(TimeHour(TimeCurrent()) == DayStartHour && !extremsSet)
{
dayHigh = High[iHighest(NULL, PERIOD_H1, MODE_HIGH, 8, 0)] ;
dayLow = Low[iLowest(NULL, PERIOD_H1, MODE_LOW, 8, 0)];
extremsSet = true;
SetPositions();
}
else if(TimeHour(TimeCurrent()) != DayStartHour && extremsSet)
extremsSet = false;
}
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
---