//+------------------------------------------------------------------+
//|                                      lowhighseoexperradvisor.mq4 |
//|                           Copyright 2016, Robert H Toutaint      |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://rtoutaint@gmail.com"
#property version   "1.00"
#property description "This ea is for testing bar-since events"
#property strict
#property indicator_chart_window

#include <stderror.mqh>
#include <stdlib.mqh>


//--- input parameters
extern double StopLoss=10;
extern double TakeProfit=40;
input double   LotSize=0.12;

extern int Slippage=30;
extern int MagicNumber=963;


double pips;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
// Determine what a pip is.
   pips =Point; //.00001 or .0001. .001 .01.
   if(Digits==3||Digits==5)
   pips*=10;   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

   Checkforsignal();
   
  }
//+------------------------------------------------------------------+
//|                 Trigger                                                 |
//+------------------------------------------------------------------+
 void Checkforsignal()

  {
   static datetime candletime = 0;
   if(candletime != Time[0]) 
   {
  //+------------------------------------------------------------------+
  //|           buy trigger                                                       |
  //+------------------------------------------------------------------+
    double arrowup = iCustom(NULL,0,"highlow seo ver1",2,0);
         if(arrowup != EMPTY_VALUE)  
         EnterTrade(OP_BUY);
     
   
     
//+------------------------------------------------------------------+
//|                     sell trigger                                             |
//+------------------------------------------------------------------+
    double arrowdown = iCustom(NULL,0,"highlow seo ver1",3,0);
         if(arrowdown != EMPTY_VALUE)  
       EnterTrade(OP_SELL);
       
       candletime = Time[0];
      }
  }    
//+------------------------------------------------------------------+
//|              Trade type                                                    |
//+------------------------------------------------------------------+
void EnterTrade(int type){

   int err=0;
   double price=Bid, sl=0, tp=0;
   if(type == OP_BUY)
      price =Ask;
   //----
   int ticket =  OrderSend(Symbol(),type,LotSize,price,Slippage,0,0,"MAEA Trade",MagicNumber,0,Magenta); 
   if(ticket>0){
      if(OrderSelect(ticket,SELECT_BY_TICKET)){
         sl = OrderOpenPrice()+(StopLoss*pips);
         tp = OrderOpenPrice()-(TakeProfit*pips);
         if(OrderType()==OP_BUY){
            sl = OrderOpenPrice()-(StopLoss*pips);
            tp = OrderOpenPrice()+(TakeProfit*pips);
         }
         if(!OrderModify(ticket,price,sl,tp,0,Magenta)) {
            err = GetLastError();
            Print("Encountered an error during modification!"+(string)err+" "+ErrorDescription(err)  );
         }
      }
      else{//in case it fails to select the order for some reason 
         Print("Failed to Select Order ",ticket);
         err = GetLastError();
         Print("Encountered an error while seleting order "+(string)ticket+" error number "+(string)err+" "+ErrorDescription(err)  );
      }
   }
   else{//in case it fails to place the order and send us back a ticket number.
      err = GetLastError();
      Print("Encountered an error during order placement!"+(string)err+" "+ErrorDescription(err)  );
      if(err==ERR_TRADE_NOT_ALLOWED)MessageBox("You can not place a trade because \"Allow Live Trading\" is not checked in your options. Please check the \"Allow Live Trading\" Box!","Check Your Settings!");
   }
}



