Author: Copyright 2010, Alf.
Price Data Components
Orders Execution
It automatically opens orders when conditions are reached
0 Views
0 Downloads
0 Favorites
pipser
//+------------------------------------------------------------------+
//|                                                       Pipser.mq5 |
//|                                             Copyright 2010, Alf. |
//|        http://forum.liteforex.org/showthread.php?p=6432#post6432 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2010, Alf."
#property link      "http://forum.liteforex.org/showthread.php?p=6432#post6432"
#property version   "1.00"
//--- input parameters
input double   Lot=0.1;
input int      SL=15;
input int      Slipage=0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   ObjectCreate(0,"BUY",OBJ_BUTTON,0,0,0);
   ObjectSetInteger(0,"BUY",OBJPROP_XDISTANCE,ChartGetInteger(0,CHART_WIDTH_IN_PIXELS)-100);
   ObjectSetInteger(0,"BUY",OBJPROP_YDISTANCE,50);
   ObjectSetString(0,"BUY",OBJPROP_TEXT,"Buy");
   ObjectCreate(0,"SELL",OBJ_BUTTON,0,0,0);
   ObjectSetInteger(0,"SELL",OBJPROP_XDISTANCE,ChartGetInteger(0,CHART_WIDTH_IN_PIXELS)-100);
   ObjectSetInteger(0,"SELL",OBJPROP_YDISTANCE,80);
   ObjectSetString(0,"SELL",OBJPROP_TEXT,"Sell");
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
    ObjectDelete(0,"BUY");
    ObjectDelete(0,"SELL");
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
//+------------------------------------------------------------------+
void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam)
{
  
  MqlTick last_tick;
   SymbolInfoTick(_Symbol,last_tick);
   MqlTradeResult result;
   MqlTradeRequest request;
   
   request.symbol=_Symbol;
   request.magic=777;
   request.deviation=Slipage;
   request.action=TRADE_ACTION_DEAL;
   request.type_filling=ORDER_FILLING_AON;
  if(ObjectGetInteger(0,"BUY",OBJPROP_STATE)!=0)
  {
      ObjectSetInteger(0,"BUY",OBJPROP_STATE,0);
      request.volume=Lot;
      request.price=last_tick.ask;
      request.type=ORDER_TYPE_BUY;
      if(SL!=0) request.sl=last_tick.bid-SL*Point();
       else request.sl=0;
      request.tp=0;
      OrderSend(request,result);
      return;
  }
  if(ObjectGetInteger(0,"SELL",OBJPROP_STATE)!=0)
  {
      ObjectSetInteger(0,"SELL",OBJPROP_STATE,0);
      request.volume=Lot;
      request.price=last_tick.bid;
      request.type=ORDER_TYPE_SELL;
      if(SL!=0) request.sl=last_tick.ask+SL*Point();
      else request.sl=0;
      request.tp=0;
      OrderSend(request,result);
      return;
  }
}

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