Reverse Ea
Reverse Ea
Reverse Ea
//| ReverseEA.mq4 |
//| Copyright 2014, tidicofx |
//| tidicofx@yahoo.com |
//| developed for loocoom |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, tidicofx"
#property link "tidicofx@yahoo.com"
#property version "1.52"
#property strict
//+------------------------------------------------------------------+
#include <stdlib.mqh>
#include <stderror.mqh>
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Input Parameters Definition |
//+------------------------------------------------------------------+
input string hint1 = "===== trade entry settings =====";
input int MaxOrdersPerCandle = 0;
input double InitialLot = 0.01;
input bool IncrementBuy = true;
input double IncrementBuyBy = 0.01;
input int IncrementBuyMaxLevels = 10;
input bool IncrementSell = true;
input double IncrementSellBy = 0.01;
input int IncrementSellMaxLevels = 10;
input double RealSL = 20;
input double TakeProfit = 50;
input double ProfitLevel1 = 10.0;
input double StopLevel1 = 2.0;
input double ProfitLevel2 = 20.0;
input double StopLevel2 = 5.0;
input double ProfitLevel3 = 30.0;
input double StopLevel3 = 10.0;
input double ProfitLevel4 = 40.0;
input double StopLevel4 = 20.0;
input double MinCandleSize = 5;
{
//-----------------------------------------------------------------if (reason == REASON_REMOVE) GlobalVariablesDeleteAll(gbl);
if (!IsTesting())
for (int i = ObjectsTotal(0, -1, -1)-1; i >= 0; i--)
if (StringFind(ObjectName(0, i), lbl) != -1)
ObjectDelete(0, ObjectName(0, i));
Comment("");
//-----------------------------------------------------------------}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
void OnTick()
{
//-----------------------------------------------------------------if (!IsConnected() || AccountNumber() == 0 || Bars <= 30 || ArraySize(Time) == 0) return;
//-----------------------------------------------------------------if (MaxCandleSize == 0 || NormalizeDouble(High[1]-Low[1],
_Digits)<=NormalizeDouble(PipsToPoints(MaxCandleSize), _Digits))
if (MinCandleSize == 0 || NormalizeDouble(High[1]-Low[1],
_Digits)>=NormalizeDouble(PipsToPoints(MinCandleSize), _Digits))
{
if (NormalizeDouble(High[1], _Digits)>NormalizeDouble(High[2], _Digits) &&
NormalizeDouble(Low[1], _Digits)>=NormalizeDouble(Low[2], _Digits))
if (NormalizeDouble(Close[1], _Digits)<=NormalizeDouble((High[1]+Low[1])/2, _Digits))
if (DoesSignalCatched(OP_SELL, Time[0]) == -1 && (GetOrderCount(OP_SELL)<MaxSellOrders ||
MaxSellOrders==0))
SetOrder(OP_SELL, Time[1]);
if (NormalizeDouble(Low[1], _Digits)<NormalizeDouble(Low[2], _Digits) &&
NormalizeDouble(High[1], _Digits)<=NormalizeDouble(High[2], _Digits))
if (NormalizeDouble(Close[1], _Digits)>=NormalizeDouble((High[1]+Low[1])/2, _Digits))
if (DoesSignalCatched(OP_BUY, Time[0]) == -1 && (GetOrderCount(OP_BUY)<MaxBuyOrders ||
MaxBuyOrders==0))
SetOrder(OP_BUY, Time[1]);
if (NormalizeDouble(High[0], _Digits)>NormalizeDouble(High[1], _Digits) &&
NormalizeDouble(Low[0], _Digits)<NormalizeDouble(Low[1], _Digits))
GlobalVariableSet(gbl+IntegerToString(ticket)+".ClosedByHiddenSL", true);
Print("order closed on virtual sl");
continue;
}
if (ProfitLevel4 != 0 && NormalizeDouble(Bid-OrderOpenPrice(),
_Digits)>=NormalizeDouble(PipsToPoints(ProfitLevel4), _Digits))
{
if (NormalizeDouble(sl, _Digits)<NormalizeDouble(OrderOpenPrice()+PipsToPoints(StopLevel4),
_Digits))
{
sl = NormalizeDouble(OrderOpenPrice()+PipsToPoints(StopLevel4), _Digits);
Print("trail sl of order #"+IntegerToString(OrderTicket())+" to "+DoubleToStr(sl, _Digits)+" on
ProfitLevel4");
_res = OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0);
}
}
else if (ProfitLevel3 != 0 && NormalizeDouble(Bid-OrderOpenPrice(),
_Digits)>=NormalizeDouble(PipsToPoints(ProfitLevel3), _Digits))
{
if (NormalizeDouble(sl, _Digits)<NormalizeDouble(OrderOpenPrice()+PipsToPoints(StopLevel3),
_Digits))
{
sl = NormalizeDouble(OrderOpenPrice()+PipsToPoints(StopLevel3), _Digits);
Print("trail sl of order #"+IntegerToString(OrderTicket())+" to "+DoubleToStr(sl, _Digits)+" on
ProfitLevel3");
_res = OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0);
}
}
else if (ProfitLevel2 != 0 && NormalizeDouble(Bid-OrderOpenPrice(),
_Digits)>=NormalizeDouble(PipsToPoints(ProfitLevel2), _Digits))
{
if (NormalizeDouble(sl, _Digits)<NormalizeDouble(OrderOpenPrice()+PipsToPoints(StopLevel2),
_Digits))
{
sl = NormalizeDouble(OrderOpenPrice()+PipsToPoints(StopLevel2), _Digits);
Print("trail sl of order #"+IntegerToString(OrderTicket())+" to "+DoubleToStr(sl, _Digits)+" on
ProfitLevel2");
}
//-----------------------------------------------------------------for (int i = ObjectsTotal()-1; i >= 0; i--)
if (StringFind(ObjectName(0, i), lbl) != -1)
if (ObjectType(ObjectName(0, i)) == OBJ_HLINE || ObjectType(ObjectName(0, i)) == OBJ_TEXT)
{
int index = StringFind(ObjectName(0, i), ".", StringLen(lbl));
int ticket = StrToInteger(StringSubstr(ObjectName(0, i), StringLen(lbl), index-StringLen(lbl)));
if (OrderSelect(ticket, SELECT_BY_TICKET))
if (OrderCloseTime() != 0)
{
GlobalVariableDel(gbl+IntegerToString(OrderTicket())+".SL");
GlobalVariableDel(gbl+IntegerToString(OrderTicket())+".TP");
ObjectDelete(ObjectName(0, i));
}
}
//-----------------------------------------------------------------}
//+------------------------------------------------------------------+
int DoesSignalCatched(int type, datetime from)
{
for (int i = OrdersTotal() - 1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == type
&& OrderOpenTime()>=from)
return (OrderTicket());
for (int i = OrdersHistoryTotal() - 1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == type
&& OrderOpenTime()>=from)
return (OrderTicket());
return (-1);
}
//+------------------------------------------------------------------+
int GetOrderCount(int type)
{
int count = 0;