4Stochs v0.1

Orders Execution
It automatically opens orders when conditions are reached
Indicators Used
Stochastic oscillator
0 Views
0 Downloads
0 Favorites
4Stochs v0.1
//+------------------------------------------------------------------+
//|                                      4Stochs EA for MetaTrader 4 |
//|                                                      version 0.1 |
//|                                   Copyright © 2008 Forex-Factory |
//|                   Strategy first published by David (ljyljl5555) |
//|                                     EA Conversion by Azmel Ainul |
//+------------------------------------------------------------------+

extern int    Magic        = 775769;
extern double LotSize      = 0.01;
extern int    TP           = 10;
extern int    SL           = 10;
extern string LongComment  = "4Stochs Long";
extern string ShortComment = "4Stochs Short";

double S1M;
double S1S;
double S2M;
double S2S;
double S3M;
double S3S;
double S4M;
double S4S;

string Signal;
string Status;

double ticket;
double slippage=5;

int init()
{
   S1M=iStochastic(NULL,PERIOD_M5,5,3,3,MODE_SMA,0,MODE_MAIN,0);
   S1S=iStochastic(NULL,PERIOD_M5,5,3,3,MODE_SMA,0,MODE_SIGNAL,0);
   S2M=iStochastic(NULL,PERIOD_M30,5,3,3,MODE_SMA,0,MODE_MAIN,0);
   S2S=iStochastic(NULL,PERIOD_M30,5,3,3,MODE_SMA,0,MODE_SIGNAL,0);
   S3M=iStochastic(NULL,PERIOD_H1,5,3,3,MODE_SMA,0,MODE_MAIN,0);
   S3S=iStochastic(NULL,PERIOD_H1,5,3,3,MODE_SMA,0,MODE_SIGNAL,0);
   S4M=iStochastic(NULL,PERIOD_H1,14,3,3,MODE_SMA,0,MODE_MAIN,0);
   S4S=iStochastic(NULL,PERIOD_H1,14,3,3,MODE_SMA,0,MODE_SIGNAL,0);
   
   Signal="NONE";
   Status="READY";
   if(S1M>S1S && S2M>S2S && S3M>S3S && S4M>S4S)
   {
      Signal="LONG";
      Status="SHORT ACTIVE";
   }
   if(S1M<S1S && S2M<S2S && S3M<S3S && S4M<S4S)
   {
      Signal="SHORT";
      Status="LONG ACTIVE";
   }
   return(0);
}

int start()
{
   S1M=iStochastic(NULL,PERIOD_M5,5,3,3,MODE_SMA,0,MODE_MAIN,0);
   S1S=iStochastic(NULL,PERIOD_M5,5,3,3,MODE_SMA,0,MODE_SIGNAL,0);
   S2M=iStochastic(NULL,PERIOD_M30,5,3,3,MODE_SMA,0,MODE_MAIN,0);
   S2S=iStochastic(NULL,PERIOD_M30,5,3,3,MODE_SMA,0,MODE_SIGNAL,0);
   S3M=iStochastic(NULL,PERIOD_H1,5,3,3,MODE_SMA,0,MODE_MAIN,0);
   S3S=iStochastic(NULL,PERIOD_H1,5,3,3,MODE_SMA,0,MODE_SIGNAL,0);
   S4M=iStochastic(NULL,PERIOD_H1,14,3,3,MODE_SMA,0,MODE_MAIN,0);
   S4S=iStochastic(NULL,PERIOD_H1,14,3,3,MODE_SMA,0,MODE_SIGNAL,0);
   
   Signal="NONE";
   if(S1M>S1S && S2M>S2S && S3M>S3S && S4M>S4S)
   {
      Signal="LONG";
   }
   if(S1M<S1S && S2M<S2S && S3M<S3S && S4M<S4S)
   {
      Signal="SHORT";
   }
   
   if(Status=="READY" && Signal=="LONG")
   {
      ticket=OrderSend(Symbol(),OP_BUY,LotSize,Ask,slippage,Ask-SL*Point,Ask+TP*Point,LongComment,Magic,0,Blue);
      if(ticket>-1)
      {
         Status="LONG ACTIVE";
      }
   }
   
   if(Status=="READY" && Signal=="SHORT")
   {
      ticket=OrderSend(Symbol(),OP_SELL,LotSize,Bid,slippage,Bid+SL*Point,Bid-TP*Point,ShortComment,Magic,0,Red);
      if(ticket>-1)
      {
         Status="SHORT ACTIVE";
      }
   }
   
   if(Status=="LONG ACTIVE" && (Signal=="NONE" || Signal=="SHORT"))
   {
      Status="READY";
   }
   
   if(Status=="SHORT ACTIVE" && (Signal=="NONE" || Signal=="LONG"))
   {
      Status="READY";
   }
   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 ---