Price Data Components
Orders Execution
Indicators Used
0
Views
0
Downloads
0
Favorites
fingerlingshoal_ac_ac_a
//+------------------------------------------------------------------+
//| fingerlingshoal.mq4 |
//| Copyright © 2005, Alejandro Galindo |
//| http://elCactus.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Alejandro Galindo"
#property link "http://elCactus.com"
//----
extern double TakeProfit = 10;
extern double Lots = 0.01;
extern double InitialStop = 250;
extern double TrailingStop = 10;
extern int MagicNumber=8888;
//----
extern bool Use.Time.Filter = false;
extern string Server.Time.To.Start = "00:00";
extern string Server.Time.To.Stop = "24:00";
datetime start_time,end_time;
bool tradinghour=true;
//====
#define SIGNAL_NONE 0
#define SIGNAL_BUY 1
#define SIGNAL_SELL 2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4
//----
extern double FastEMA=5;
extern double SlowEMA=21;
//----
extern bool travel=true;
//
extern int MaxTrades = 48;
extern int Pips = 18;
extern int SecureProfit = 7;
extern int AccountProtection = 1;
extern int OrderstoProtect = 6;
extern int ReverseCondition = 261;
extern double EURUSDPipValue = 10;
extern double GBPUSDPipValue = 10;
extern double USDCHFPipValue = 10;
extern double USDJPYPipValue = 9.715;
extern int StartYear = 2005;
extern int StartMonth = 1;
extern int EndYear = 2010;
extern int EndMonth = 12;
extern int EndHour = 22;
extern int EndMinute = 30;
extern int mm = 0;
extern int risk = 50;
extern int AccountisNormal = 0;
//----
bool IsTrading=true;
//---
int OpenOrders = 0, cnt = 0;
int slippage = 2;
double sl = 0, tp = 0;
double BuyPrice = 0, SellPrice = 0;
double lotsi = 0, mylotsi = 0;
int mode = 0;
int myOrderType_m5 = 0;
int myOrderType_m15 = 0;
int myOrderType_m60 = 0;
int myOrderType = 0;
bool ContinueOpening = True;
double LastPrice = 0;
int PreviousOpenOrders = 0;
double Profit = 0;
int LastTicket = 0, LastType = 0;
double LastClosePrice = 0, LastLots = 0;
double Pivot = 0;
double PipValue = 0;
string text = "", text2 = "";
static int LASTRUN;
int BarCount;
int Current;
bool TickCheck = False;
extern bool EachTickMode = false;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
BarCount = Bars;
if (EachTickMode) Current = 0; else Current = 1;
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int Order = SIGNAL_NONE;
int Total, Ticket;
double StopLossLevel, TakeProfitLevel;
if ((LASTRUN == Time[0]))
{
return(0); // It's a no go, no new bar
}
else
{
LASTRUN = Time[0]; // Finally a new bar!! Now execute the rest of the code
}
//====
//====
if (EachTickMode && Bars != BarCount) TickCheck = False;
Total = OrdersTotal();
Order = SIGNAL_NONE;
//----
if(AccountisNormal == 1)
if(mm != 0)
lotsi = MathCeil(AccountBalance()*risk / 10000);
else
lotsi = Lots;
else
// then is mini
if(mm != 0)
lotsi = MathCeil(AccountBalance()*risk / 10000) / 10;
else
lotsi = Lots;
//----
if(lotsi > 100)
lotsi = 100;
OpenOrders = 0;
//----
for(cnt = 0; cnt < OrdersTotal(); cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if ( OrderSymbol() != Symbol()) continue;
if ( OrderMagicNumber() != MagicNumber) continue;
OpenOrders++;
}
//----
if(OpenOrders < 1)
{
if(TimeYear(CurTime()) < StartYear)
return(0);
//----
if(TimeMonth(CurTime()) < StartMonth)
return(0);
//----
if(TimeYear(CurTime()) > EndYear)
return(0);
//----
if(TimeMonth(CurTime()) > EndMonth )
return(0);
// The time to control trading and Manual stop progra running!
if(!travel)return(0);
if (DayOfWeek() == 0 ) return(0); // Sunday check
if (DayOfWeek() == 1 && Hour() < 2) return(0); // Monday check
if (DayOfWeek() == 5 && Hour() >= 16) return(0); // Friday check
if (DayOfWeek() == 5 && Day()<=7) return(0); // First Friday Of the Month echeck
}
//----
if(Symbol() == "EURUSD")
PipValue = EURUSDPipValue;
//----
if(Symbol() == "GBPUSD")
PipValue = GBPUSDPipValue;
//----
if(Symbol() == "USDJPY")
PipValue = USDJPYPipValue;
//----
if(Symbol() == "USDCHF")
PipValue = USDCHFPipValue;
//----
if(PipValue == 0)
PipValue = 10 ;
//----
if(PreviousOpenOrders > OpenOrders)
{
for(cnt=OrdersTotal();cnt>=0;cnt--)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
mode = OrderType();
//----
if ( OrderSymbol() != Symbol()) continue;
if ( OrderMagicNumber() != MagicNumber) continue;
{
if(mode == OP_BUY)
OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), slippage, Blue);
//----
if(mode == OP_SELL)
OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), slippage, Red);
return(0);
}
}
//---- Time period calculation
//start_time = StrToTime(TimeToStr(TimeCurrent(), TIME_DATE) + " " + Server.Time.To.Start); //---- Date and time to start
//end_time = StrToTime(TimeToStr(TimeCurrent(), TIME_DATE) + " " + Server.Time.To.Stop); //---- Date and time to stop
//---- Is it time to trade
//if(Use.Time.Filter && (TimeCurrent() < start_time || TimeCurrent() >= end_time)) tradinghour=false;
//else tradinghour=true;
}
PreviousOpenOrders = OpenOrders;
//----
if(OpenOrders >= MaxTrades)
ContinueOpening = False;
else
ContinueOpening = True;
//----
if(LastPrice == 0)
{
for(cnt = 0; cnt < OrdersTotal(); cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
mode = OrderType();
//----
if ( OrderSymbol() != Symbol()) continue;
if ( OrderMagicNumber() != MagicNumber) continue;
{
LastPrice = OrderOpenPrice();
//----
if(mode == OP_BUY)
myOrderType = 2;
//----
if(mode == OP_SELL)
myOrderType = 1;
}
}
}
//----
if(OpenOrders < 1)
{
myOrderType = 3;
//----5 minute iMA
//+------------------------------------------------------------------+
//| Variable Begin |
//+------------------------------------------------------------------+
double ac0_m1 = iAC(NULL, PERIOD_M1, Current + 0);
double ac1_m1 = iAC(NULL, PERIOD_M1, Current + 1);
double ac2_m1 = iAC(NULL, PERIOD_M1, Current + 2);
double ao0_m1 = iAO(NULL, PERIOD_M1, Current + 0);
double ao1_m1 = iAO(NULL, PERIOD_M1, Current + 1);
double ac0_m5 = iAC(NULL, PERIOD_M5, Current + 0);
double ac1_m5 = iAC(NULL, PERIOD_M5, Current + 1);
double ac2_m5 = iAC(NULL, PERIOD_M5, Current + 2);
double ao0_m5 = iAO(NULL, PERIOD_M5, Current + 0);
double ao1_m5 = iAO(NULL, PERIOD_M5, Current + 1);
double ac0_m15 = iAC(NULL, PERIOD_M15, Current + 0);
double ac1_m15 = iAC(NULL, PERIOD_M15, Current + 1);
double ac2_m15 = iAC(NULL, PERIOD_M15, Current + 2);
double ao0_m15 = iAO(NULL, PERIOD_M15, Current + 0);
double ao1_m15 = iAO(NULL, PERIOD_M15, Current + 1);
double Buy1_1_m1 = ac0_m1, Buy1_1_m5 = ac0_m5, Buy1_1_m15 = ac0_m15;
double Buy1_2_m1 = ac1_m1, Buy1_2_m5 = ac1_m5, Buy1_2_m15 = ac1_m15;
double Buy2_1_m1 = ac1_m1, Buy2_1_m5 = ac1_m5, Buy2_1_m15 = ac1_m15;
double Buy2_2_m1 = ac2_m1, Buy2_2_m5 = ac2_m5, Buy2_2_m15 = ac2_m15;
double Buy3_1_m1 = ao0_m1, Buy3_1_m5 = ao0_m5, Buy3_1_m15 = ao0_m15;
double Buy3_2_m1 = ao1_m1, Buy3_2_m5 = ao1_m5, Buy3_2_m15 = ao1_m15;
double Sell1_1_m1 = ac0_m1, Sell1_1_m5 = ac0_m5, Sell1_1_m15 = ac0_m15;
double Sell1_2_m1 = ac1_m1, Sell1_2_m5 = ac1_m5, Sell1_2_m15 = ac1_m15;
double Sell2_1_m1 = ac1_m1, Sell2_1_m5 = ac1_m5, Sell2_1_m15 = ac1_m15;
double Sell2_2_m1 = ac2_m1, Sell2_2_m5 = ac2_m5, Sell2_2_m15 = ac2_m15;
double Sell3_1_m1 = ao0_m1, Sell3_1_m5 = ao0_m5, Sell3_1_m15 = ao0_m15;
double Sell3_2_m1 = ao1_m1, Sell3_2_m5 = ao1_m5, Sell3_2_m15 = ao1_m15;
double CloseBuy1_1_m1 = ac0_m1, CloseBuy1_1_m5 = ac0_m5, CloseBuy1_1_m15 = ac0_m15;
double CloseBuy1_2_m1 = ac1_m1, CloseBuy1_2_m5 = ac1_m5, CloseBuy1_2_m15 = ac1_m15;
double CloseBuy2_1_m1 = ac1_m1, CloseBuy2_1_m5 = ac1_m5, CloseBuy2_1_m15 = ac1_m15;
double CloseBuy2_2_m1 = ac2_m1, CloseBuy2_2_m5 = ac2_m5, CloseBuy2_2_m15 = ac2_m15;
double CloseSell1_1_m1 = ac0_m1, CloseSell1_1_m5 = ac0_m5, CloseSell1_1_m15 = ac0_m15;
double CloseSell1_2_m1 = ac1_m1, CloseSell1_2_m5 = ac1_m5, CloseSell1_2_m15 = ac1_m15;
double CloseSell2_1_m1 = ac1_m1, CloseSell2_1_m5 = ac1_m5, CloseSell2_1_m15 = ac1_m15;
double CloseSell2_2_m1 = ac2_m1, CloseSell2_2_m5 = ac2_m5, CloseSell2_2_m15 = ac2_m15;
//+------------------------------------------------------------------+
//| Variable End |
//+------------------------------------------------------------------+
if ((CloseBuy1_1_m1 < CloseBuy1_2_m1) && (CloseBuy2_1_m1 > CloseBuy2_2_m1)) myOrderType_m5 = 4;
if ((CloseSell1_1_m1 > CloseSell1_2_m1) && (CloseSell2_1_m1 < CloseSell2_2_m1)) myOrderType_m5 = 5;
if (Buy1_1_m1 > Buy1_2_m1 && Buy2_1_m1 < Buy2_2_m1 && Buy3_1_m1 > Buy3_2_m1) myOrderType_m5 = 2;
if (Sell1_1_m1 < Sell1_2_m1 && Sell2_1_m1 > Sell2_2_m1 && Sell3_1_m1 < Sell3_2_m1) myOrderType_m5 = 1;
if ((CloseBuy1_1_m5 < CloseBuy1_2_m5) && (CloseBuy2_1_m5 > CloseBuy2_2_m5)) myOrderType_m15 = 4;
if ((CloseSell1_1_m5 > CloseSell1_2_m5) && (CloseSell2_1_m5 < CloseSell2_2_m5)) myOrderType_m15 = 5;
if (Buy1_1_m5 > Buy1_2_m5 && Buy2_1_m5 < Buy2_2_m5 && Buy3_1_m5 > Buy3_2_m5) myOrderType_m15 = 2;
if (Sell1_1_m5 < Sell1_2_m5 && Sell2_1_m5 > Sell2_2_m5 && Sell3_1_m5 < Sell3_2_m5) myOrderType_m15 = 1;
if ((CloseBuy1_1_m15 < CloseBuy1_2_m15) && (CloseBuy2_1_m15 > CloseBuy2_2_m15)) myOrderType_m60 = 4;
if ((CloseSell1_1_m15 > CloseSell1_2_m15) && (CloseSell2_1_m15 < CloseSell2_2_m15)) myOrderType_m60 = 5;
if (Buy1_1_m15 > Buy1_2_m15 && Buy2_1_m15 < Buy2_2_m15 && Buy3_1_m15 > Buy3_2_m1) myOrderType_m60 = 2;
if (Sell1_1_m15 < Sell1_2_m15 && Sell2_1_m15 > Sell2_2_m15 && Sell3_1_m15 < Sell3_2_m1) myOrderType_m60 = 1;
if(myOrderType_m5==2 && myOrderType_m15==2 && myOrderType_m60==2)myOrderType=2;
if(myOrderType_m5==1 && myOrderType_m15==1 && myOrderType_m60==1)myOrderType=1;
if(myOrderType_m5==1 && myOrderType_m15==2 && myOrderType_m60==2)myOrderType=3;
if(myOrderType_m5==1 && myOrderType_m15==1 && myOrderType_m60==2)myOrderType=3;
if(myOrderType_m5==2 && myOrderType_m15==1 && myOrderType_m60==1)myOrderType=3;
if(myOrderType_m5==2 && myOrderType_m15==2 && myOrderType_m60==1)myOrderType=3;
if(myOrderType_m5==4 && myOrderType_m15==4 && myOrderType_m60==4)myOrderType=4;
if(myOrderType_m5==5 && myOrderType_m15==5 && myOrderType_m60==5)myOrderType=5;
//----
if(ReverseCondition == 1)
if(myOrderType == 1)
myOrderType = 2;
else
if(myOrderType == 2)
myOrderType = 1;
}
// if we have opened positions we take care of them
for(cnt = OrdersTotal(); cnt >= 0; cnt--)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
//----
if ( OrderSymbol() != Symbol()) continue;
if ( OrderMagicNumber() != MagicNumber) continue;
{
if(OrderType() == OP_SELL)
if(TrailingStop > 0)
if(OrderOpenPrice() - Ask >= (TrailingStop + Pips)*Point)
if(OrderStopLoss() > (Ask + Point*TrailingStop))
{
OrderModify(OrderTicket(), OrderOpenPrice(),
Ask + Point*TrailingStop,
OrderClosePrice() - TakeProfit*Point - TrailingStop*Point,
800, Purple);
return(0);
}
//----
if(OrderType() == OP_BUY)
if(TrailingStop > 0)
if(Bid - OrderOpenPrice() >= (TrailingStop + Pips)*Point)
if(OrderStopLoss() < (Bid - Point*TrailingStop))
{
OrderModify(OrderTicket(), OrderOpenPrice(),
Bid - Point*TrailingStop,
OrderClosePrice() + TakeProfit*Point + TrailingStop*Point,
800, Yellow);
return(0);
}
}
}
Profit = 0;
LastTicket = 0;
LastType = 0;
LastClosePrice = 0;
LastLots = 0;
//----
for(cnt = 0; cnt < OrdersTotal(); cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
//----
if ( OrderSymbol() != Symbol()) continue;
if ( OrderMagicNumber() != MagicNumber) continue;
{
LastTicket = OrderTicket();
//----
if(OrderType() == OP_BUY)
LastType = OP_BUY;
//----
if(OrderType() == OP_SELL)
LastType = OP_SELL;
LastClosePrice = OrderClosePrice();
LastLots = OrderLots();
//----
if(LastType == OP_BUY)
{
if(OrderClosePrice() < OrderOpenPrice())
Profit = Profit - (OrderOpenPrice() - OrderClosePrice())*OrderLots() / Point;
//----
if(OrderClosePrice() > OrderOpenPrice())
Profit = Profit + (OrderClosePrice() - OrderOpenPrice())*OrderLots() / Point;
}
//----
if(LastType == OP_SELL)
{
if(OrderClosePrice() > OrderOpenPrice())
Profit=Profit - (OrderClosePrice()-OrderOpenPrice())*OrderLots() / Point;
//----
if(OrderClosePrice() < OrderOpenPrice())
Profit=Profit+(OrderOpenPrice()-OrderClosePrice())*OrderLots()/Point;
}
}
}
Profit = Profit*PipValue;
text2 = "Profit: $" + DoubleToStr(Profit, 2) + " +/-";
//----
if(OpenOrders >= (MaxTrades - OrderstoProtect) && AccountProtection == 1)
{
if(Profit >= SecureProfit)
{
OrderClose(LastTicket, LastLots, LastClosePrice, slippage, Yellow);
ContinueOpening = False;
return(0);
}
}
//----
if(!IsTesting())
{
if(myOrderType == 3)
text = "No conditions to open trades";
else
text=" ";
Comment("LastPrice=", LastPrice, " Previous open orders=", PreviousOpenOrders,
"\nContinue opening=", ContinueOpening, " OrderType=", myOrderType, "\n",
text2, "\nLots=", lotsi, "\n", text);
}
//----
if(myOrderType == 4 || myOrderType == 5)
{
for(cnt=OrdersTotal();cnt>=0;cnt--)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
mode = OrderType();
//----
if ( OrderSymbol() != Symbol()) continue;
if ( OrderMagicNumber() != MagicNumber) continue;
{
if(mode == OP_BUY)
OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), slippage, Blue);
//----
if(mode == OP_SELL)
OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), slippage, Red);
return(0);
}
}
}
if(myOrderType == 1 && ContinueOpening)
{
if((Bid - LastPrice) >= Pips*Point || OpenOrders < 1)
{
SellPrice = Bid;
LastPrice = 0;
//----
if(TakeProfit == 0)
tp = 0;
else
tp = SellPrice - TakeProfit*Point;
//----
if(InitialStop == 0)
sl=0;
else
sl=SellPrice+InitialStop*Point;
//----
if(OpenOrders != 0)
{
mylotsi=lotsi;
//----
for(cnt = 1; cnt <= OpenOrders; cnt++)
if(MaxTrades > 48)
mylotsi = NormalizeDouble(mylotsi*2, 2);
else
mylotsi = NormalizeDouble(mylotsi*3, 2);
}
else
mylotsi = lotsi;
//----
if(mylotsi > 100)
mylotsi = 100;
OrderSend(Symbol(), OP_SELL, mylotsi, SellPrice, slippage, sl, tp, NULL, MagicNumber, 0, Red);
return(0);
}
}
//----
if(myOrderType == 2 && ContinueOpening)
{
if((LastPrice - Ask) >= Pips*Point || OpenOrders < 1)
{
BuyPrice = Ask;
LastPrice = 0;
//----
if(TakeProfit == 0)
tp = 0;
else
tp = BuyPrice + TakeProfit*Point;
//----
if(InitialStop == 0)
sl = 0;
else
sl = BuyPrice - InitialStop*Point;
//----
if(OpenOrders != 0)
{
mylotsi = lotsi;
//----
for(cnt = 1; cnt <= OpenOrders; cnt++)
{
if(MaxTrades > 48)
mylotsi = NormalizeDouble(mylotsi*2, 2);
else
mylotsi = NormalizeDouble(mylotsi*3, 2);
}
}
else
mylotsi = lotsi;
//----
if(mylotsi > 100)
mylotsi = 100;
OrderSend(Symbol(), OP_BUY, mylotsi, BuyPrice, slippage, sl, tp, NULL, MagicNumber, 0, Blue);
return(0);
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---