Price Data Components
Orders Execution
0
Views
0
Downloads
0
Favorites
pnn-system-1
//+------------------------------------------------------------------+
//| Example system using trained probabilistic neural network (PNN) |
//| |
//| PNN System 1.mq4 |
//| Paco Hernández Gómez |
//| http://www.hernandezgomez.com |
//+------------------------------------------------------------------+
#property copyright "Paco Hernández Gómez"
#property link "http://www.hernandezgomez.com"
// Import PNN library
#import "PNN.ex4"
void PNNInit();
void PNNLoad();
void PNNSave();
void PNNAddVector(int class, double vector[]);
int PNNClassifyVector(double vector[]);
#import
/**
* In this system there is always an open position, either buy or sell.
*/
/**
* Take profits at 18 pips.
*/
extern int LIMIT = 18;
/**
* Take loses at 54 pips.
*/
extern int STOP_LOSS = 54;
/**
* Load the trained PNN
*/
int init() {
PNNLoad();
return(0);
}
/**
* Operate the system using the PNN
*/
int start() {
int total;
total = OrdersTotal();
// If there is not an opened position
if (total == 0) {
double data[60];
// Calculate the vector to classify using the trading system criteria
for (int i = 0; i < 60; i++) {
data[i] = (iClose(Symbol(), PERIOD_M15, i) - iClose(Symbol(), PERIOD_M15, i + 1)) / Point;
}
// Use the PNN to classify the vector
int class = PNNClassifyVector(data);
// If PNN classifies the vector as a buying position
if (class == 0) {
// Open a new buying position
OrderSend(Symbol(), OP_BUY, 0.1, Ask, 3, Ask - STOP_LOSS * Point, Ask + LIMIT * Point, NULL, 16384, 0, Green);
}
// If PNN classifies the vector as a selling position
else if (class != 0) {
// Open a new selling position
OrderSend(Symbol(), OP_SELL, 0.1, Bid, 3, Bid + STOP_LOSS * Point, Bid - LIMIT * Point, NULL, 16384, 0, Red);
}
}
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
---