smoothingaverage

Author: Rietsuiker
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself
Indicators Used
Moving average indicator
0 Views
0 Downloads
0 Favorites
smoothingaverage
//+------------------------------------------------------------------+
//|                                             SmoothingAverage.mq4 |
//|                                                       Rietsuiker |
//|                                                     http://ak.fm |
//+------------------------------------------------------------------+
#property copyright "Rietsuiker"
#property link      "http://ak.fm"
#property version   "0.01"

//--- input parameters
input int      Period_MA=200;
input double      Risk=10;
input int      Smoothing=1400;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int CurrentOrder;

double MA;
double MA2;
double highpoint;

double Lots=(AccountEquity()*Point*Risk);
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   Print("You're gonna get bankrupt m8");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   Print(AccountEquity());
   Print(Lots);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

   MA=iMA(NULL,0,Period_MA,0,MODE_SMA,PRICE_CLOSE,0);

   if(OrdersTotal()<1)
     {

      if(Bid<MA+Smoothing*Point)
        {;
         OrderSend(Symbol(),OP_SELL,Lots,Bid,10,0,0);
         CurrentOrder++;
           } else if(Ask>MA-Smoothing*Point){
         OrderSend(Symbol(),OP_BUY,Lots,Ask,10,0,0);
         CurrentOrder++;
        }

      OrderSelect(CurrentOrder,SELECT_BY_TICKET);
     }

   if(OrderType()==OP_SELL && Bid>MA+Smoothing*Point)
     {
      OrderClose(CurrentOrder,Lots,Ask,3,Red);
        } else if(OrderType()==OP_BUY && Ask<MA-Smoothing*Point){
      OrderClose(CurrentOrder,Lots,Bid,3,Red);
     }

  }
//+------------------------------------------------------------------+

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 ---