#include <stdlib.mqh>
extern bool Debug=false;
extern string TradeLog="TradeLog";
extern int MagicNumber=11111;
extern double Lots=0.1;
extern double HedgeBase=2.0;
extern int Slippage=5;
extern bool shutdownGrid=false;
extern int TunnelWidth=20;
extern double profitTarget=100; // if > 0, will close out all positions once the pip target has been met
extern int EMAShortPeriod=8; // original was 7, change based on new optimization Mar06
extern int EMALongPeriod=21; // original was 16, change based on new optimization Mar06
extern int PauseSeconds= 6; // Number of seconds to "sleep" before closing the next winning trade
extern int MillisPerSec=1000; // DO NOT CHANGE - Standard multiplier to convert seconds to milliseconds
double TunnelSize;
string setup;
double startBuyRate, startSellRate;
int currentOpen;
int NumBuyTrades, NumSellTrades; // Number of buy and sell trades in this symbol
bool myWantLongs;
double lotMM;
double Profit;
bool OK2Buy,OK2Sell, FirstDirSell;
int CheckDirection()
{
double SlowEMA, FastEMA;
double Dif;
FastEMA=iMA(NULL,0,EMAShortPeriod,0,MODE_EMA,PRICE_CLOSE,1);
SlowEMA=iMA(NULL,0,EMALongPeriod,0,MODE_EMA,PRICE_CLOSE,1);
Dif=FastEMA-SlowEMA;
if(Dif > 0)return(1);
if(Dif < 0)return(-1);
return(0);
}
int init()
{
// код доступен только после оплаты
}
int deinit()
{
int handle;
if (Debug)
{
if (GlobalVariableCheck("MyHandle"))
{
handle=GlobalVariableGet("MyHandle");
FileFlush(handle);
FileClose(handle);
GlobalVariableDel("MyHandle");
}
}
return(0);
}
int Write(string str)
{
int handle;
if (GlobalVariableCheck("MyHandle"))
{
handle=GlobalVariableGet("MyHandle");
FileWrite(handle,str + " Time " + TimeToStr(CurTime(),TIME_DATE|TIME_SECONDS));
}
}
void CloseOpenPositions()
{
int cnt, err;
for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
{
OrderSelect (cnt, SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol()) continue;
if(OrderMagicNumber()!=MagicNumber) continue;
if(OrderType()==OP_BUY && OrderProfit() < 0)
{
if (OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Violet))
{
if (Debug) Write("Buy Order closed for " + Symbol() + " at " + Bid + ".");
}
else
{
err=GetLastError();
Print("Error closing order : (", err , ") " + ErrorDescription(err));
if (Debug)
{
Write("Error closing order : (" + err + ") " + ErrorDescription(err));
}
}
}
if(OrderType()==OP_SELL && OrderProfit() < 0)
{
if (OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Violet))
{
if (Debug) Write("Sell Order closed for " + Symbol() + " at " + Ask + ".");
}
else
{
err=GetLastError();
Print("Error closing order : (", err , ") " + ErrorDescription(err));
if (Debug)
{
Write("Error closing order : (" + err + ") " + ErrorDescription(err));
}
}
}
}
for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
{
OrderSelect (cnt, SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol()) continue;
if(OrderMagicNumber()!=MagicNumber) continue;
if(OrderType()==OP_BUY && OrderProfit() > 0)
{
Sleep(PauseSeconds*MillisPerSec);
if (OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Gold))
{
if (Debug) Write("Buy Order closed for " + Symbol() + " at " + Bid + ".");
}
else
{
err=GetLastError();
Print("Error closing order : (", err , ") " + ErrorDescription(err));
if (Debug)
{
Write("Error closing order : (" + err + ") " + ErrorDescription(err));
}
}
}
if(OrderType()==OP_SELL && OrderProfit() > 0)
{
Sleep(PauseSeconds*MillisPerSec);
if (OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Gold))
{
Показано первые 50% кода (символов: 6597)
Введите ваш email и нажмите кнопку, чтобы перейти к оплате.