GENIUSv101-ecn

GENIUSv101-ecn

开心版 无广告 448

更新日期:2022-02-24 分类标签: 语言:中文 平台:没限制

89 人已下载 手机查看

GENIUSv101-ecn GENIUSv101-ecn

 

 

// +------------------------------------------------------------------+
// | |
string VersionNumber = "GENIUSv101-ecn";
// | |
// | |
// +------------------------------------------------------------------+

#define EA "Genius"
#define VER "1_01"
#define OP_CLOSEBY 96
#define OP_MODIFY 97
#define OP_CLOSE 98
#define OP_NONE 99
#define OH1 0
#define CH1 1
#define OH2 2
#define CH2 3

#include <stdlib.mqh>

extern string OrderOptions= "-------- Orders options --------";
extern double Lots = 0;
extern int LotsPercent = 30;
int MaxDrawDown = 30;
extern bool UseAutosettings = true;
extern int TakeProfit = 30;
extern bool TryTakeProfit = true;
extern int StopLoss =35;
extern bool CheckFreezLevel = true;
extern double SafeSpread=3.0;
extern int Slippage=3;
extern int MagicNumber=887;
int TrailingStop = 50;
int MinProfitValue = 5;
string TradeOptions= "-------- Trade options --------";
int ChannelBars = 10;
int SellCorrection = 0;
int BuyCorrection = 0;
bool CheckTimeBar = false;
bool EqualBars = true;

string TransmiteOptions="--------Transmite options--------";
bool TradeTransferIn=false;
bool TradeTransferOut=false;
bool CheckDeleteFile=false;
int TimeOutDeleteFile=10;
bool CheckSetOrder=true;
int TimeOutSetOrder=10;
bool DeleteFileAfterChecking=false;
int NumberRepeatCloseOrder = 0;

extern string TimeOptions= "-------- Time options --------";
extern bool EachDayHourSettings=false;
extern int TradeTimeChoise = 1;
extern int TradeDayOfWeek=0;
extern int OpenHour1=21;
extern int CloseHour1=4;
extern int OpenHour2=22;
extern int CloseHour2=24;
extern int GMToffset=0;

string OtherOptions= "-------- Other options --------";
bool ShowComment=true;
bool ShowSettings=true;
int TimeOutComment=3;
bool ShowPrint=true;
bool ShowTime=true;
bool ShowNameID=false;
bool ShowMagicNumber=false;

int BarSlippage=2;
int BBPeriod=20;
int BBShift=0;
double BBDeviations=2.5;
int BBChannelValue = 50;
bool ReversTrades = false;
bool LackTrades = false;
bool OneTradesToDirection = true;
bool HideIndicators = false;
bool Result;

//
//
// Variables used in DisplayInfo Routine

double lots, Equity, Drawdown, WorstDrawdown;
double ChartProfit;
double SmallestSpread=1000,Spread,LargestSpread=0;
double LocalPoint;

int TickRotate, TickNumber, Trend;
int LotDigit;
int SellOpenOrders, BuyOpenOrders, BuyPendingOrders, SellPendingOrders;

string Margin = " "; //
string _text1, _text2, _text3, _text4, _text5, DisplayText, TickDisplay, CrLf = "\n";

//

int pipp;
double pip;
string NameID, InitString;
double LotsForTrade;
double HighestBarsValue, LowestBarsValue;
color ReversOrderColor = Black;
color BuyOrderColor = Blue;
color SellOrderColor = Red;
int LastOrderBar, LastOrderTicket, CurrentOrderTicket, CurrentOrderProfitPoint, CurrentOrderTrailingStop;
bool TradeLimit;
int opposite_id = 1;
double LastOrderTime=0;
double CurrentOrderProfit;
double BuyOrderPrice;
bool GoSell=false, GoBuy=false;
double MaxProfit=0, MaxLoss=0;
double UPmaxProfit=0, UPmaxLoss=0;
double UPminProfit=50, UPminLoss=50;
double DOWNmaxProfit=0,DOWNmaxLoss=0;
double DOWNminProfit=50, DOWNminLoss=50;
int ReadOperationCounter, SaveOperationCounter;
int CurrentDirection=OP_NONE, LastDirection=OP_NONE, CurrentMode=1,FileCounterMaxValue=10, CounterRepeatClose;
int RB_Counter=0, RB_TimeBar=0, RB_Operation=1, RB_Ticket=2, RB_Price=3, RB_StopLoss=4, RB_TakeProfit=5;
int CB_Counter=0, CB_TimeBar=0, CB_Operation=1, CB_RecTicket=2, CB_OurTicket=3, CB_OpenPrice=4, CB_ClosePrice=5, CB_StopLoss=6, CB_TakeProfit=7;
bool fTime=true, StopTradesByMargin, LastisOrderSell, LastisOrderBuy, TryRepeatCloseOrder;
int LastOpenHour1, LastCloseHour1, LastOpenHour2, LastCloseHour2;
bool RepeatCloseOrder, FirstComment=false;
string ErrorArray[4207];
int TradeTimeBuffer[5][4];
double ReceiveBuffer[1][6];
double CommandBuffer[1][8];
string CommentBuffer[20][2];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
Comment("");
InitString="";

LocalPoint = Point*MathPow(10,Digits%2);
LotDigit = MarketInfo( Symbol(), MODE_DIGITS );

if (Digits%2) pipp=10; else pipp=1;
pip=pipp*Point;
Slippage*=pipp;
NameID=EA+VER;
InitErrorArray();
OpenHour1=(OpenHour1+GMToffset)%24;
CloseHour1=(CloseHour1+GMToffset+23)%24+1;
OpenHour2=(OpenHour2+GMToffset)%24;
CloseHour2=(CloseHour2+GMToffset+23)%24+1;
if (HideIndicators) HideTestIndicators(true);
LastOrderTime=Time[0];
ClearBuffer("ReceiveBuffer",RB_Counter);
ClearBuffer("CommandBuffer",CB_Counter);
ClearBuffer("CommentBuffer",0);
InitString="Manual settings for "+AccountCompany()+" M"+Period()+"\n";
if (UseAutosettings)
{
if (SetAutoSettings())
{
InitString="Automatic settings for "+AccountCompany()+" M"+Period()+"\n";
}
}
LastOpenHour1=OpenHour1; LastCloseHour1=CloseHour1; LastOpenHour2=OpenHour2; LastCloseHour2=CloseHour2;
StartRulls();

if (Lots!=0)
{
InitString = InitString + "Lots = " + DoubleToStr(Lots,2) + "\n";
}
else
{
InitString = InitString + "LotsPercent = " + LotsPercent + " %" + "\n";
}

InitString = InitString + "Trade with the top 50 traders in the world today for free. Visit http://worldbest50.zulutrade.com\n";
InitString = InitString + "Get up to 40% of your spread costs back through our unbeatable rebates, and earn up to 0.7 pips back for every lot you trade. email scalpfox@rocketmail.com to join\n";
InitString = InitString + "This robot can double your money every 60 days. Get the current best settings at scalpfox@rocketmail.com for free\n";

if (TradeTransferOut)
{
SaveFileOrder(0, OP_NONE, 0, 0, 0, 0, 0);
}
else
{
//Comments("Initial");
}

Comment(CrLf+Margin+"EA is operational.\n" +Margin+"On next tick this message will disapear.");

return(0);}
// wrapper.
//+------------------------------------------------------------------+
int deinit()
{
ClearBuffer("ReceiveBuffer",RB_Counter);
ClearBuffer("CommandBuffer",CB_Counter);
ClearBuffer("CommentBuffer",0);
Comment("");
return(0);}
// main processor.
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
//
TickNumber = TickNumber + 1;

if (!StartRulls()) return(0);
if (TradeTransferIn)
{
if (ReadFileOrder()) CheckReceiveBuffer();
CheckCommandBuffer();
return(0);
}
//
PrepareIndicators();
// if (StopByMaxDrawDown()) return(0);

// Comments("Start()");

Spread = (Ask-Bid) / LocalPoint;
if (Spread > LargestSpread) LargestSpread = Spread;
if (Spread < SmallestSpread) SmallestSpread = Spread;

ShowInfo();

if (isOrderSell() && !TimeCurrentBar())
{
if (isGroDtoBuy() || isMinProfittoClose() || TryToCloseAgain())
{
if (CurrentOrderProfitPoint<0 && TryTakeProfit) return(0);
CloseSellOrder();
return(0);
}
return(0);
}

 

if (isOrderBuy() && !TimeCurrentBar())
{
if (isGroDtoSell() || isMinProfittoClose() || TryToCloseAgain())
{
if (CurrentOrderProfitPoint<0 && TryTakeProfit) return(0);
CloseBuyOrder();
return(0);
}
return(0);
}

 

if (isGroDtoSell(true) && !TimeCurrentBar() && (isTimetoTrade(OpenHour1, CloseHour1) || isTimetoTrade(OpenHour2, CloseHour2)))
{
{
SendSellOrder(StopLoss,TakeProfit);
return(0);
}
}

if (isGroDtoBuy(true) && !TimeCurrentBar() && (isTimetoTrade(OpenHour1, CloseHour1) || isTimetoTrade(OpenHour2, CloseHour2)))
{
{
SendBuyOrder(StopLoss,TakeProfit);
return(0);
}
}

return(0);}

bool StopByMaxDrawDown(){
bool result=false;
double CurrentMaxDrawDown;
if (MaxDrawDown==0 || (OpenHour1==0 && CloseHour1==12 && OpenHour2==12 && CloseHour2==24)) return(result);
if (!isTimetoTrade(OpenHour1, CloseHour1) && !isTimetoTrade(OpenHour2, CloseHour2))
{
//Comments("StopByMaxDrawDown(): Trade allow");
StopTradesByMargin=false;
GlobalVariableSet("MaxAccountValue",AccountBalance());
result=false;
return(result);
}
if (StopTradesByMargin)
{
result=true;
return(result);
}
if (GlobalVariableGet("MaxAccountValue")-AccountBalance()<0) GlobalVariableSet("MaxAccountValue",AccountBalance());
CurrentMaxDrawDown=GlobalVariableGet("MaxAccountValue")-GlobalVariableGet("MaxAccountValue")*MaxDrawDown/100;
/* Comment(
"CurrentMaxDrawDown= ",CurrentMaxDrawDown,"\n",
"MaxAccountValue= ",GlobalVariableGet("MaxAccountValue"),"\n",
"AccountBalance()= ",AccountBalance(),"\n",
"AccountEquity()= ",AccountEquity(),"\n"
);*/
if (CurrentMaxDrawDown-AccountEquity()>0)
{
while (isOrderBuy()) CloseBuyOrder();
while (isOrderSell()) CloseSellOrder();
//Comments("StopByMaxDrawDown(): Trade is permitted");
StopTradesByMargin=true;
result=true;
return(result);
}
return(result);}

 

void ResultTrades()
{
if (OrderType()==OP_BUY)
{
if (UPmaxProfit<MaxProfit) UPmaxProfit=MaxProfit;
if (UPmaxLoss<MaxLoss) UPmaxLoss=MaxLoss;
}
if (OrderType()==OP_SELL)
{
if (DOWNmaxProfit<MaxProfit) DOWNmaxProfit=MaxProfit;
if (DOWNmaxLoss<MaxLoss) DOWNmaxLoss=MaxLoss;
}
MaxProfit=0;
MaxLoss=0;
}

void CalculateTrades()
{
if (OrderType()==OP_BUY)
{
if ((Bid-OrderOpenPrice())>MaxProfit) MaxProfit=Bid-OrderOpenPrice();
if ((OrderOpenPrice()-Bid)>MaxLoss) MaxLoss=OrderOpenPrice()-Bid;
}
if (OrderType()==OP_SELL)
{
if ((OrderOpenPrice()-Ask)>MaxProfit) MaxProfit=OrderOpenPrice()-Ask;
if ((Ask-OrderOpenPrice())>MaxLoss) MaxLoss=Ask-OrderOpenPrice();
}
}

bool TimeCurrentBar(){
bool result=false;
if (CheckTimeBar && Time[0]==LastOrderTime) result=true;
return(result);}

bool isOrderSell(){
bool result=false;
int cnt=0, ticket, total;
total=OrdersTotal();
for (cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol()==Symbol() && OrderType()==OP_SELL)
{
if (!TradeTransferOut && OrderMagicNumber()!=MagicNumber) continue;
result=true;
CurrentOrderProfit = OrderProfit();
CurrentOrderProfitPoint = (OrderOpenPrice()-Ask)/pip;
break;
}
}
if (LastisOrderSell && !result)
{
if (OrderStopLoss()!=0 || OrderTakeProfit()!=0) LastOrderTime=Time[0];
}
LastisOrderSell=result;
return(result);}

 

bool isOrderBuy(){
bool result=false;
int cnt=0, ticket, total;
total=OrdersTotal();
for (cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol()==Symbol() && OrderType()==OP_BUY)
{
if (!TradeTransferOut && OrderMagicNumber()!=MagicNumber) continue;
result=true;
CurrentOrderProfit = OrderProfit();
CurrentOrderProfitPoint = (Bid-OrderOpenPrice())/pip;
break;
}
}
if (LastisOrderBuy && !result)
{
if (OrderStopLoss()!=0 || OrderTakeProfit()!=0) LastOrderTime=Time[0];
}
LastisOrderBuy=result;
return(result);}

bool OrderRevers(){
bool result=false;
int cnt=0, ticket, total;
total=OrdersTotal();
for (cnt=0;cnt<total;cnt++)
{
ticket = OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
ticket = OrderTicket();
if (OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && OrderType()<=OP_SELL)
{
RefreshRates();
if (OrderCloseBy(OrderTicket(),ticket,ReversOrderColor))
{
// //Comments("Order reversed : "+OrderOpenPrice());
opposite_id=opposite_id+1;
result=true;
LastOrderTime=Time[0];

if (TradeTransferOut) SaveFileOrder(Time[0], OP_CLOSEBY, ticket, OrderLots(), Bid, 0, 0);
}
else
{
//Comments("Error revers order: "+PrintError(GetLastError()));
}
}
}
return(result);}

bool CloseBuyOrder(){
bool result=false;
int cnt=0, ticket, total;
total=OrdersTotal();
for (cnt=0;cnt<total;cnt++)
{
ticket = OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol()==Symbol() && OrderType()==OP_BUY)
{
if (isFreezLevel()) continue;
if (!TradeTransferOut && OrderMagicNumber()==MagicNumber)
{
RefreshRates();
if (OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,BuyOrderColor))
{
// Comments("Buy order closed : "+OrderClosePrice());
result=true;
LastOrderTime=Time[0];
LastDirection=OP_BUY;
RepeatCloseOrder=false;

}
else
{
Print ("Error close Buy order: "+ErrorDescription(GetLastError()));
RepeatCloseOrder=true;
}
}
else
{
if (SaveFileOrder(Time[0], OP_CLOSE, OrderTicket(), OrderLots(), Bid, 0, 0))
{
// Comments("Close Buy order transmited");
result=true;
LastOrderTime=Time[0];
LastDirection=OP_BUY;
RepeatCloseOrder=false;
}
else
{
Print ("Error transmite Close Buy order "+ErrorDescription(GetLastError()));
RepeatCloseOrder=true;
}
}
}
}
return(result);}

bool CloseSellOrder(){
bool result=false;
int cnt=0, ticket, total;
total=OrdersTotal();
for (cnt=0;cnt<total;cnt++)
{
ticket = OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol()==Symbol() && OrderType()==OP_SELL)
{
if (isFreezLevel()) continue;
if (!TradeTransferOut && OrderMagicNumber()==MagicNumber)
{
RefreshRates();
if (OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,SellOrderColor))
{
// Comments("Sell order closed : "+OrderClosePrice());
result=true;
LastOrderTime=Time[0];
LastDirection=OP_SELL;
RepeatCloseOrder=false;

}
else
{
Print("Error close Sell order: "+ErrorDescription(GetLastError()));
RepeatCloseOrder=true;
}
}
else
{
if (SaveFileOrder(Time[0], OP_CLOSE, OrderTicket(), OrderLots(), Ask, 0, 0))
{
// Comments("Close Sell order transmited");
result=true;
LastOrderTime=Time[0];
LastDirection=OP_SELL;
RepeatCloseOrder=false;
}
else
{
Print("Error transmite Close Sell order "+ErrorDescription(GetLastError()));
RepeatCloseOrder=true;
}
}
}
}
return(result);}

 

bool TryToCloseAgain(){
bool result=false;
if (!RepeatCloseOrder)
{
CounterRepeatClose=NumberRepeatCloseOrder;
}
else
{
CounterRepeatClose=CounterRepeatClose-1;
if (CounterRepeatClose>0)
{
result=true;
}
else
{
RepeatCloseOrder=false;
Print("TryToCloseAgain(): Error after repeat Close order "+ErrorDescription(GetLastError()));
}
}
return(result);}

 

bool isFreezLevel()
{
bool result=false;
double Price, FreezLevelValue, CurrentSlippage;
if (CheckFreezLevel)
{
if (OrderStopLoss()!=0 || OrderTakeProfit()!=0)
{
if (OrderType()==OP_BUY) Price=Bid;
if (OrderType()==OP_SELL) Price=Ask;
FreezLevelValue=MarketInfo(Symbol(),MODE_FREEZELEVEL)*Point;
if ( OrderStopLoss()!=0 && FreezLevelValue>(MathAbs(Price-OrderStopLoss() ))) result=true;
if (OrderTakeProfit()!=0 && FreezLevelValue>(MathAbs(Price-OrderTakeProfit()))) result=true;
}
}
return(result);}

bool SendBuyOrder(double SBO_StopLoss, double SBO_TakeProfit)
{
int ticket=0;
RepeatCloseOrder=false;
RefreshRates();
if (SBO_StopLoss!=0)
{
if (SBO_StopLoss < MarketInfo(Symbol(),MODE_STOPLEVEL)/pipp) SBO_StopLoss = MarketInfo(Symbol(),MODE_STOPLEVEL)/pipp;
SBO_StopLoss = NormalizeDouble(Bid - SBO_StopLoss*pip,Digits);
}
if (SBO_TakeProfit!=0)
{
if (SBO_TakeProfit < MarketInfo(Symbol(),MODE_STOPLEVEL)/pipp) SBO_TakeProfit = MarketInfo(Symbol(),MODE_STOPLEVEL)/pipp;
SBO_TakeProfit = NormalizeDouble(Ask + SBO_TakeProfit*pip,Digits);
}
if (!TradeTransferOut)
{
RefreshRates();
ticket=OrderSend(Symbol(),OP_BUY,LotsForTrade,Ask,Slippage,0,0, NameID,MagicNumber,0,BuyOrderColor);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
{
// Comments("Buy order opened : "+OrderOpenPrice());

Result = OrderModify(ticket, OrderOpenPrice(), SBO_StopLoss, SBO_TakeProfit, 0, CLR_NONE);
if (!Result) Print("Error modifying BUY order : ", ErrorDescription(GetLastError()));

 

LastOrderTime=Time[0];
LastOrderBar=Bars;
CurrentOrderTicket=ticket;
CurrentOrderTrailingStop=0;

}
}
else
{
Print("Error open Buy order: "+ErrorDescription(GetLastError()));
return(false);
}
}
else
{
if (SaveFileOrder(Time[0], OP_BUY, ticket, LotsForTrade, Ask, SBO_StopLoss, SBO_TakeProfit))
{
// Comments("Buy order open transmited ");
LastOrderTime=Time[0];
LastOrderBar=Bars;
CurrentOrderTrailingStop=0;
}
else
{
Print("Error transmite open Buy order "+ErrorDescription(GetLastError()));
return(false);
}
}
return(true);}

bool SendSellOrder(double SSO_StopLoss, double SSO_TakeProfit)
{
int ticket=0;
RepeatCloseOrder=false;
RefreshRates();
if (SSO_StopLoss!=0)
{
if (SSO_StopLoss < MarketInfo(Symbol(),MODE_STOPLEVEL)/pipp) SSO_StopLoss = MarketInfo(Symbol(),MODE_STOPLEVEL)/pipp;
SSO_StopLoss = NormalizeDouble(Ask + SSO_StopLoss*pip,Digits);
}
if (SSO_TakeProfit!=0)
{
if (SSO_TakeProfit < MarketInfo(Symbol(),MODE_STOPLEVEL)/pipp) SSO_TakeProfit = MarketInfo(Symbol(),MODE_STOPLEVEL)/pipp;
SSO_TakeProfit = NormalizeDouble(Bid - SSO_TakeProfit*pip,Digits);
}
if (!TradeTransferOut)
{
RefreshRates();
ticket=OrderSend(Symbol(),OP_SELL,LotsForTrade,Bid,Slippage,0,0, NameID,MagicNumber,0,SellOrderColor);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
{
// Comments("Sell order opened : "+OrderOpenPrice());

Result = OrderModify(ticket, OrderOpenPrice(), SSO_StopLoss, SSO_TakeProfit, 0, CLR_NONE);
if (!Result) Print("Error modifying Sell order : ", ErrorDescription(GetLastError()));

 

LastOrderTime=Time[0];
LastOrderBar=Bars;
CurrentOrderTicket=ticket;
CurrentOrderTrailingStop=0;

}
}
else
{
Print("Error open Sell order: "+ErrorDescription(GetLastError()));
return(false);
}
}
else
{
if (SaveFileOrder(Time[0], OP_SELL, ticket, LotsForTrade, Bid, SSO_StopLoss, SSO_TakeProfit))
{
// Comments("Sell order open transmited: ");
LastOrderTime=Time[0];
LastOrderBar=Bars;
CurrentOrderTrailingStop=0;
}
else
{
Print("Error transmite open Sell order "+ErrorDescription(GetLastError()));
return(false);
}
}
return(true);}

 

 

 

 

bool StartRulls()
{
double LotsStep, LotsMin, LotsMax;
int LotsDigit;
if (EachDayHourSettings && DayOfWeek()>0)
{
OpenHour1 =TradeTimeBuffer[DayOfWeek()-1][OH1];
CloseHour1=TradeTimeBuffer[DayOfWeek()-1][CH1];
OpenHour2 =TradeTimeBuffer[DayOfWeek()-1][OH2];
CloseHour2=TradeTimeBuffer[DayOfWeek()-1][CH2];
}
if (!FirstComment)
{
FirstComment=true;
}
else
{
if (LastOpenHour1!=OpenHour1 || LastCloseHour1!=CloseHour1 || LastOpenHour2!=OpenHour2 || LastCloseHour2!=CloseHour2)
{
LastOpenHour1=OpenHour1; LastCloseHour1=CloseHour1; LastOpenHour2=OpenHour2; LastCloseHour2=CloseHour2;
//Comments("Another trade time EA");
}
}

if (IsOptimization())
{
if (OpenHour1>12) return(false);
if (CloseHour1>12) return(false);
if (OpenHour2<12) return(false);
if (CloseHour2<12) return(false);
if (OpenHour1>CloseHour1 || OpenHour2>CloseHour2) return(false);
}
if(Bars<100)
{
//Comments("StartRulls() Bars less than 100");
return(false);
}
if (IsTesting() || IsOptimization())
{
TradeTransferIn=false;
TradeTransferOut=false;
}
if (TradeTransferIn && TradeTransferOut)
{
// Comment ("TradeTransferIn and TradeTransferOut can't operate simultaneously!!!");
return(false);
}
LotsStep = NormalizeDouble(MarketInfo(Symbol(), MODE_LOTSTEP),2);
LotsMin=NormalizeDouble(MarketInfo(Symbol(),MODE_MINLOT),2);
LotsMax=NormalizeDouble(MarketInfo(Symbol(), MODE_MAXLOT),2);
if (LotsStep==0.01) LotsDigit=2; else LotsDigit=1;
// Lot size calculation
if (Lots==0) LotsForTrade=NormalizeDouble(AccountFreeMargin()*LotsPercent/100000,LotsDigit);
else LotsForTrade=Lots;
if (LotsForTrade>LotsMax) LotsForTrade=LotsMax;
if (LotsForTrade<LotsMin) LotsForTrade=LotsMin;
return(true);}

 

 

bool isBBtoBuy(){
bool result=false;
if ((iBBHigh(0)-iBBLow(0))/pip<=BBChannelValue && Bid<iBBMidle(0))
result=true;
return(result);}

bool isBBtoSell(){
bool result=false;
if ((iBBHigh(0)-iBBLow(0))/pip<=BBChannelValue && Bid>iBBMidle(0))
result=true;
return(result);}

 

bool isMinProfittoClose(){
bool result=false;
if (CurrentOrderProfitPoint>0 && CurrentOrderProfitPoint>=MinProfitValue && MinProfitValue!=0)
{
result=true;
}
return(result);}

bool isTrailingStop(){
bool result=false;
int OrderTrailingStop;
if (CurrentOrderProfitPoint>MinProfitValue)
{
OrderTrailingStop=MathCeil(CurrentOrderProfitPoint*TrailingStop/100);
if (OrderTrailingStop<1) OrderTrailingStop=1;
if (CurrentOrderTrailingStop<OrderTrailingStop) CurrentOrderTrailingStop=OrderTrailingStop;
}
if (CurrentOrderTrailingStop!=0 && CurrentOrderProfitPoint<=CurrentOrderTrailingStop) result=true;
return(result);}

 

 

bool isTradeLimit(){
bool result=false;
if (CurrentOrderTicket!=LastOrderTicket)
{
CurrentOrderTicket=LastOrderTicket;
TradeLimit=false;
}
if (TradeLimit) return(result);
if (OrderProfit()>0) return(result);
TradeLimit=true;
return(result);}

 

bool isGroDtoBuy(bool checkspread=false){
bool result=false;
if (checkspread) if (Ask-Bid>SafeSpread*pip) return(false);
if (!ReversTrades)
{
if (Bid < (LowestBarsValue-pip*BuyCorrection) || (EqualBars && Bid <= (LowestBarsValue-pip*BuyCorrection))) result=true;
}
else
{
if (Bid > HighestBarsValue || (EqualBars && Bid >= HighestBarsValue)) result=true;
}
return(result);}

bool isGroDtoSell(bool checkspread=false){
bool result=false;
if (checkspread) if (Ask-Bid>SafeSpread*pip) return(false);
if (!ReversTrades)
{
if (Bid > (HighestBarsValue+pip*SellCorrection) || (EqualBars && Bid >= (HighestBarsValue+pip*SellCorrection))) result=true;
}
else
{
if (Bid < LowestBarsValue || (EqualBars && Bid <= LowestBarsValue)) result=true;
}
return(result);}

 

bool isTimetoTrade(int OpenHour, int CloseHour)
{
bool result = false;
int CurrentHour=Hour();
if (OpenHour > 23 || OpenHour < 0 ) OpenHour = 0;
if (CloseHour > 23 || CloseHour < 0 ) CloseHour = 0;
if (OpenHour<CloseHour && (Hour()>=OpenHour && Hour()<CloseHour)) result=true;
if (OpenHour>CloseHour && (Hour()>=OpenHour || Hour()<CloseHour)) result=true;
if (DayOfWeek()!=TradeDayOfWeek && TradeDayOfWeek!=0) result = false;
return(result);}

//--------------------------------------------------------------------------
bool SaveFileOrder( int FileOrderTimeBar,int FileOrderOperation, int FileOrderTicket, double FileOrderLots, double FileOrderPrice, double FileOrderStopLoss, double FileOrderTakeProfit)
{
int handle;
bool result = false;
string FileName = Symbol() + ".csv" ;
handle=FileOpen(FileName,FILE_CSV|FILE_WRITE,';');
if(handle<1)
{
Print ("SaveFileOrder(): File "+FileName+" creation error :" +ErrorDescription(GetLastError()));
return(result);
}
FileWrite(handle,
// FileOrderTimeBar,
FileOrderOperation,
FileOrderLots,
FileOrderTicket,
FileOrderPrice,
DoubleToStr(FileOrderStopLoss,Digits),
DoubleToStr(FileOrderTakeProfit,Digits));
FileClose(handle);
// Comments("SaveFileOrder(): File saved : "+FileName);
result=true;

//if (FileOrderOperation==OP_BUY) Comments("BUY "+FileOrderOperation+" ; "+LotsForTrade+" ; "+FileOrderTicket+" ; "+FileOrderPrice+" ; "+FileOrderStopLoss+" ; "+FileOrderTakeProfit);
//if (FileOrderOperation==OP_SELL) Comments("SELL "+FileOrderOperation+" ; "+LotsForTrade+" ; "+FileOrderTicket+" ; "+FileOrderPrice+" ; "+FileOrderStopLoss+" ; "+FileOrderTakeProfit);
//if (FileOrderOperation==OP_CLOSE) Comments("CLOSE "+FileOrderOperation+" ; "+LotsForTrade+" ; "+FileOrderTicket+" ; "+FileOrderPrice+" ; "+FileOrderStopLoss+" ; "+FileOrderTakeProfit);
//if (FileOrderOperation==OP_NONE) Comments("NONE "+FileOrderOperation+" ; "+LotsForTrade+" ; "+FileOrderTicket+" ; "+FileOrderPrice+" ; "+FileOrderStopLoss+" ; "+FileOrderTakeProfit);

SaveOperationCounter =SaveOperationCounter + 1;
if (SaveOperationCounter>FileCounterMaxValue) SaveOperationCounter=0;

//Check directory for file
datetime TimeSaveFile=TimeLocal();
if (CheckDeleteFile)
{
// Comments("SaveFileOrder(): File deletion pending");
result=false;
while (TimeLocal()-TimeSaveFile < TimeOutDeleteFile)
{
if (!isFile())
{
result=true;
break;
}
Sleep(25);
}
if (!result)
{
if (DeleteFileAfterChecking)
{
if (FileErase(FileName))
{
//Comments("SaveFileOrder(): Deleted expired file.");
}
else
{
//Comments("SaveFileOrder(): Expired file deletion failed");
}
}
else
{
//Comments("SaveFileOrder(): File expired");
}
}
}
//Check open/close orders
TimeSaveFile=TimeLocal();
if (CheckSetOrder)
{
result=false;
// Comments("SaveFileOrder(): Waiting for operations...");
while (TimeLocal()-TimeSaveFile < TimeOutSetOrder)
{
if (FileOrderOperation==OP_SELL && isOrderSell())
{
result=true;
break;
}
if (FileOrderOperation==OP_BUY && isOrderBuy())
{
result=true;
break;
}
if (FileOrderOperation==OP_CLOSE && !isOrderSell() && !isOrderBuy())
{
result=true;
break;
}
if (FileOrderOperation==OP_NONE)
{
result=true;
break;
}
Sleep(25);
}
if (!result)
{
if (DeleteFileAfterChecking)
{
if (FileErase(FileName))
{
//Comments("SaveFileOrder(): Deleted expired file.");
}
else
{
//Comments("SaveFileOrder(): Expired file deletion failed");
}
}
else
{
// Comments("SaveFileOrder(): File expired");
}
}
}
return(result);}

 

 

 

 

//--------------------------------------------------------------------------
bool isFile()
{
int handle;
string FileName;
bool result=false;
FileName = Symbol() + ".csv";
handle=FileOpen(FileName,FILE_CSV|FILE_READ|FILE_WRITE);
if (handle>0 && FileSize(handle)>0)
{
FileClose(handle);
result=true;
}
return(result);}

//--------------------------------------------------------------------------
bool FileErase(string FileName)
{
int handle;
bool result=false;
handle=FileOpen(FileName,FILE_CSV|FILE_WRITE);
if (handle>0)
{
// Comments("FileErase(): handle>0");
FileClose(handle);
result=true;
}
return(result);}

 

//--------------------------------------------------------------------------
bool Comments(string CommentString){
bool result=false;
int i,j;
if (ShowPrint)
{
string str="";
if (ShowTime) str=str+TimeToStr(TimeCurrent(),TIME_SECONDS)+" : ";
if (ShowNameID) str=str+NameID;
if (ShowMagicNumber) str=str+"("+MagicNumber+")";
if (ShowNameID || ShowMagicNumber) str=str+": ";
Print(str+CommentString);
}
if (ShowSettings)
{
//if (ShowComment) Comment(InitString+str+CommentString);
}
else
{
//if (ShowComment) Comment(str+CommentString);
}
// if (ShowComment) ShowCommentList(false);
return(result);}

//--------------------------------------------------------------------------
bool ShowCommentList(bool CheckForOld){
bool result=false;
int i,j;
string str="";

CommentBuffer[19][0]="Hello";
CommentBuffer[19][1]="Hello";
{
for (i=0;i<=19;i++)
{
if (CommentBuffer[i][1]!="1")
{
str=str + i+": "+CommentBuffer[i][0]+"\n";
}
else
{
//Comment (str);
break;
}
}
}
return(result);}

//--------------------------------------------------------------------------
bool ReadFileOrder()
{
int handle, counter;
string str;
string FileName;
bool result=false;
if (fTime)
{
for(counter=0;counter<FileCounterMaxValue+1;counter++)
{
FileName = Symbol()+ (MagicNumber + Period()) + "_" + counter + ".csv";
handle=FileOpen(FileName,FILE_CSV|FILE_READ);
if (!handle<0)
{
ReadOperationCounter = counter;
fTime=false;
FileClose(handle);
break;
}
}
}
if (fTime) return(result);
FileName = Symbol()+ (MagicNumber + Period()) + "_" + ReadOperationCounter + ".csv";
handle=FileOpen(FileName,FILE_CSV|FILE_READ);
if (handle>0)
{
str=FileReadString(handle);
ReceiveBuffer[RB_Counter][RB_TimeBar] = StrToInteger(str);
str=FileReadString(handle);
ReceiveBuffer[RB_Counter][RB_Operation] = StrToInteger(str);
str=FileReadString(handle);
ReceiveBuffer[RB_Counter][RB_Ticket] = StrToInteger(str);
str=FileReadString(handle);
ReceiveBuffer[RB_Counter][RB_Price] = StrToDouble(str);
str=FileReadString(handle);
ReceiveBuffer[RB_Counter][RB_StopLoss] = StrToDouble(str);
str=FileReadString(handle);
ReceiveBuffer[RB_Counter][RB_TakeProfit] = StrToDouble(str);
FileClose(handle);
FileDelete(FileName);

ReadOperationCounter =ReadOperationCounter + 1;
if (ReadOperationCounter>FileCounterMaxValue) ReadOperationCounter=0;
//Comments("ReadFileOrder(): File read "+ FileName);
result=true;
}
return(true);}

bool CheckReceiveBuffer(){
bool result=false;
if (ReceiveBuffer[RB_Counter][RB_Operation]!=OP_NONE)
{
if (ReceiveBuffer[RB_Counter][RB_Operation]==OP_CLOSE)
{
if (CommandBuffer[CB_Counter][CB_OurTicket]!=0 && ReceiveBuffer[RB_Counter][RB_Ticket]==CommandBuffer[CB_Counter][CB_RecTicket])
{
CommandBuffer[CB_Counter][CB_Operation]=OP_CLOSE;
CommandBuffer[CB_Counter][CB_ClosePrice]=ReceiveBuffer[RB_Counter][RB_Price];
result = true;
}
}
if ((ReceiveBuffer[RB_Counter][RB_Operation]==OP_BUY || ReceiveBuffer[RB_Counter][RB_Operation]==OP_SELL) &&
CommandBuffer[CB_Counter][CB_Operation]==OP_NONE)
{
CommandBuffer[CB_Counter][CB_TimeBar] = ReceiveBuffer[RB_Counter][RB_TimeBar];
CommandBuffer[CB_Counter][CB_Operation] = ReceiveBuffer[RB_Counter][RB_Operation];
CommandBuffer[CB_Counter][CB_RecTicket] = ReceiveBuffer[RB_Counter][RB_Ticket];
CommandBuffer[CB_Counter][CB_OpenPrice] = ReceiveBuffer[RB_Counter][RB_Price];
CommandBuffer[CB_Counter][CB_StopLoss] = ReceiveBuffer[RB_Counter][RB_StopLoss];
CommandBuffer[CB_Counter][CB_TakeProfit]= ReceiveBuffer[RB_Counter][RB_TakeProfit];
result = true;
}
}
ClearBuffer("ReceiveBuffer",RB_Counter);
return(result);}

 

bool CheckCommandBuffer(){
bool result=false;
if (CommandBuffer[CB_Counter][CB_Operation]!=OP_NONE)
{
if (CommandBuffer[CB_Counter][CB_TimeBar]+BarSlippage*(Period()*60)<=Time[0])
{
if (CommandBuffer[CB_Counter][CB_Operation]==OP_BUY &&
CommandBuffer[CB_Counter][CB_OpenPrice]>=Ask)
{
if (SendBuyOrder(CommandBuffer[CB_Counter][CB_StopLoss], CommandBuffer[CB_Counter][CB_TakeProfit]))
{
result=true;
}
}
if (CommandBuffer[CB_Counter][CB_Operation]==OP_SELL &&
CommandBuffer[CB_Counter][CB_OpenPrice]<=Bid)
{
if (SendSellOrder(CommandBuffer[CB_Counter][CB_StopLoss], CommandBuffer[CB_Counter][CB_TakeProfit]))
{
result=true;
}
}
}
if (CommandBuffer[CB_Counter][CB_TimeBar]+BarSlippage*(Period()*60)<=Time[0])
{
}
}
return(result);}

bool ClearBuffer(string CurrentBuffer, int Row){
int result=false;
if (CurrentBuffer=="ReceiveBuffer")
{
ReceiveBuffer[RB_Counter][RB_TimeBar] = 0;
ReceiveBuffer[RB_Counter][RB_Operation] = OP_NONE;
ReceiveBuffer[RB_Counter][RB_Ticket] = 0;
ReceiveBuffer[RB_Counter][RB_Price] = 0;
ReceiveBuffer[RB_Counter][RB_StopLoss] = 0;
ReceiveBuffer[RB_Counter][RB_TakeProfit] = 0;
}
if (CurrentBuffer=="CommandBuffer")
{
ReceiveBuffer[CB_Counter][CB_TimeBar] = 0;
ReceiveBuffer[CB_Counter][CB_Operation] = OP_NONE;
ReceiveBuffer[CB_Counter][CB_RecTicket] = 0;
ReceiveBuffer[CB_Counter][CB_OurTicket] = 0;
ReceiveBuffer[CB_Counter][CB_OpenPrice] = 0;
ReceiveBuffer[CB_Counter][CB_ClosePrice] = 0;
ReceiveBuffer[CB_Counter][CB_StopLoss] = 0;
ReceiveBuffer[CB_Counter][CB_TakeProfit] = 0;
}
if (CurrentBuffer=="CommentBuffer")
{
for (int i=0;i<20;i++)
{
CommentBuffer[i][0]="";
CommentBuffer[i][1]="";
}
}
return(result);}

 

//--------------------------------------------------------------------------

bool CloseOrdersBuyMargin()
{ int counter;
double MinProfit=0;
bool result=false;
if ((AccountFreeMarginCheck(Symbol(),OP_BUY, 2*Lots)<=0 || AccountFreeMarginCheck(Symbol(),OP_SELL, 2*Lots)<=0)
&& (AccountBalance()>AccountEquity()) )
{
for(counter=0;counter<OrdersTotal();counter++)
{
OrderSelect(counter, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
if(OrderProfit()<=MinProfit) {MinProfit=OrderProfit();}
}
}
for(counter=0;counter<OrdersTotal();counter++)
{
OrderSelect(counter, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
if( (MinProfit-OrderProfit())==0
&& ( ((MathAbs(OrderOpenPrice()-Bid)-TrailingStop*pip)>0 && OrderType()==OP_BUY)
|| ((MathAbs(Ask-OrderOpenPrice())-TrailingStop*pip)>0 && OrderType()==OP_SELL) ) )
{
RefreshRates();
OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,White);

//if (OrderType()==OP_BUY) {Comments("Buy Order close by margin, profit= "+ OrderProfit());}
//if (OrderType()==OP_SELL) {Comments("Sell Order close by margin, profit= "+ OrderProfit());}
result=true;
break;
}
}
}
}
return(result);}

//
string PrintError(int ErrorCode)
{
return(ErrorArray[ErrorCode]);}

void InitErrorArray()
{
ErrorArray[0] = "No errors";
ErrorArray[1] = "No errors, but no resulting";
ErrorArray[2] = "General fault";
ErrorArray[3] = "Fault parameters";
ErrorArray[4] = "Trade busy";
ErrorArray[5] = "Old version of terminal";
ErrorArray[6] = "Not connect";
ErrorArray[7] = "Rules not good for you";
ErrorArray[8] = "Very many orders";
ErrorArray [9] = "Invalid operation disrupt the server";
ErrorArray [64] = "blocked account";
ErrorArray [65] = "Invalid account number";
ErrorArray [128] = "Expired expectations of the transaction";
ErrorArray [129] = "Invalid price";
ErrorArray [130] = "Wrong foot";
ErrorArray [131] = "Invalid volume";
ErrorArray [132] = "The market is closed";
ErrorArray [133] = "Trade is prohibited";
ErrorArray [134] = "Not enough money for the transaction";
ErrorArray [135] = "Price has changed";
ErrorArray [136] = "No price";
ErrorArray [137] = "Broker busy";
ErrorArray [138] = "New prices";
ErrorArray [139] = "Order has been blocked and processed";
ErrorArray [140] = "Allow only buy";
ErrorArray [141] = "Too many bugs";
ErrorArray [145] = "Modification is prohibited, as the warrant is too close to the market";
ErrorArray [146] = "subsystem busy trade";
ErrorArray [147] = "Using the date of expiry of the warrant is prohibited broker";
ErrorArray [148] = "The number of open orders and deferred reached the limit set by the broker";
ErrorArray [4000] = "No errors";
ErrorArray [4001] = "Invalid Index function";
ErrorArray [4002] = "Index array - out of range";
ErrorArray [4003] = "No memory to stack functions";
ErrorArray [4004] = "stack overflow after recursive call";
ErrorArray [4005] = "At no memory of the stack to pass options";
ErrorArray [4006] = "No memory for a string parameter";
ErrorArray [4007] = "No memory for a temporary line";
ErrorArray [4008] = "Neinitsializirovannaya line";
ErrorArray [4009] = "Neinitsializirovannaya line in the array";
ErrorArray [4010] = "No memory for an array string";
ErrorArray [4011] = "Too long line";
ErrorArray [4012] = "Balance of dividing by zero";
ErrorArray [4013] = "The division by zero";
ErrorArray [4014] = "Unknown command";
ErrorArray [4015] = "Invalid conversion";
ErrorArray [4016] = "Neinitsializirovanny array";
ErrorArray [4017] = "Challenge DLL not allowed ";
ErrorArray [4018] = "Can not load library";
ErrorArray [4019] = "Can not call";
ErrorArray [4020] = "Challenge external library functions are not allowed ";
ErrorArray [4021] = "Not enough memory to the line, recovery of the function";
ErrorArray [4022] = "system busy";
ErrorArray [4050] = "Wrong number of parameters function";
ErrorArray [4051] = "Invalid value functions";
ErrorArray [4052] = "Internal error string functions";
ErrorArray [4053] = "Error array";
ErrorArray [4054] = "Misuse of solid-taymserii";
ErrorArray [4055] = "user error indicator";
ErrorArray [4056] = "Arrays incompatible";
ErrorArray [4057] = "Error processing globalnyeh variables";
ErrorArray [4058] = "global variable is not detected";
ErrorArray [4059] = "function is not allowed in test mode";
ErrorArray [4060] = "function is not allowed";
ErrorArray [4061] = "Error sending";
ErrorArray [4062] = "expected parameter type string";
ErrorArray [4063] = "expected parameter type integer";
ErrorArray [4064] = "expected parameter type double";
ErrorArray [4065] = "As expected array parameter";
ErrorArray [4066] = "The requested historical data in a state of renewal";
ErrorArray [4067] = "Error executing trading operations";
ErrorArray [4099] = "End file";
ErrorArray [4100] = "error when working with the file";
ErrorArray [4101] = "Invalid file name";
ErrorArray [4102] = "Too many open files";
ErrorArray [4103] = "Can not open file";
ErrorArray [4104] = "Incompatible regime access to the file";
ErrorArray [4105] = "No warrant is not selected";
ErrorArray [4106] = "Unknown symbol";
ErrorArray [4107] = "Invalid setting prices for commercial functions";
ErrorArray [4108] = "Wrong number tiketa";
ErrorArray [4109] = "Trade is not allowed. You need to include the option Allow an adviser to trade in the properties of expert";
ErrorArray [4110] = "Long positions are not allowed. You should check the properties of expert";
ErrorArray [4111] = "Short positions are not allowed. You should check the properties of expert";
ErrorArray [4200] = "Object already exists";
ErrorArray [4201] = "Requested an unknown object property";
ErrorArray [4202] = "The object does not exist";
ErrorArray [4203] = "Unknown type of object";
ErrorArray [4204] = "No, the object name ";
ErrorArray [4205] = "Error coordinates object";
ErrorArray [4206] = "said subwindow Not Found";
ErrorArray [4207] = "error when working with the object";
}

//Indicator calculation
void PrepareIndicators()
{
/* HighestBarsValue =High[iHighest(NULL, 0, MODE_HIGH, ChannelBars, 1)]+pip;
LowestBarsValue =Low [iLowest (NULL, 0, MODE_LOW , ChannelBars, 1)]+pip;
if (IsTesting() || IsOptimization() || AccountCompany()!="Private Consulting Corp.")*/
{
HighestBarsValue =High[iHighest(NULL, 0, MODE_HIGH, ChannelBars, 1)];
LowestBarsValue =Low [iLowest (NULL, 0, MODE_LOW , ChannelBars, 1)];
}
}

 

//Bollinger Bands indicator
double iBBLow(int CurrentBar){
double result;
result = iCustom(NULL,0,"Bollinger Bands",BBPeriod,BBShift,BBDeviations,2,CurrentBar);
return(result);}

double iBBHigh(int CurrentBar){
double result;
result = iCustom(NULL,0,"Bollinger Bands",BBPeriod,BBShift,BBDeviations,1,CurrentBar);
return(result);}

double iBBMidle(int CurrentBar){
double result;
result = iCustom(NULL,0,"Bollinger Bands",BBPeriod,BBShift,BBDeviations,0,CurrentBar);
return(result);}

 

bool SetAutoSettings(){
bool result=false;
// Settings for Fibo Group
if (AccountCompany()=="FIBO Group, Ltd.")
{
if (Symbol()=="EURGBP" && Period()==PERIOD_M5)
{
ChannelBars=24; CheckTimeBar=false; EqualBars=true;
if (EachDayHourSettings) {OpenHour1=0; CloseHour1=1; OpenHour2=23; CloseHour2=0;}
if (TradeTimeChoise==0)
result=true;
}
if (Symbol()=="EURGBP" && Period()==PERIOD_M15)
{
ChannelBars=10; CheckTimeBar=false; EqualBars=true;
if (EachDayHourSettings) {OpenHour1=0; CloseHour1=1; OpenHour2=22; CloseHour2=0;}
{
//Trading hours (fixed)
TradeTimeBuffer[0][OH1]=0 ; TradeTimeBuffer[0][CH1]=1 ; TradeTimeBuffer[0][OH2]=22 ; TradeTimeBuffer[0][CH2]=24;
TradeTimeBuffer[1][OH1]=0 ; TradeTimeBuffer[1][CH1]=1 ; TradeTimeBuffer[1][OH2]=22 ; TradeTimeBuffer[1][CH2]=24;
TradeTimeBuffer[2][OH1]=0 ; TradeTimeBuffer[2][CH1]=1 ; TradeTimeBuffer[2][OH2]=22 ; TradeTimeBuffer[2][CH2]=24;
TradeTimeBuffer[3][OH1]=0 ; TradeTimeBuffer[3][CH1]=1 ; TradeTimeBuffer[3][OH2]=22 ; TradeTimeBuffer[3][CH2]=24;
TradeTimeBuffer[4][OH1]=0 ; TradeTimeBuffer[4][CH1]=1 ; TradeTimeBuffer[4][OH2]=22 ; TradeTimeBuffer[4][CH2]=24;
}
if (TradeTimeChoise==1)
{
//Trading hours (optimal)
TradeTimeBuffer[0][OH1]=0 ; TradeTimeBuffer[0][CH1]=1 ; TradeTimeBuffer[0][OH2]=20 ; TradeTimeBuffer[0][CH2]=24;
TradeTimeBuffer[1][OH1]=0 ; TradeTimeBuffer[1][CH1]=2 ; TradeTimeBuffer[1][OH2]=18 ; TradeTimeBuffer[1][CH2]=24;
TradeTimeBuffer[2][OH1]=0 ; TradeTimeBuffer[2][CH1]=0 ; TradeTimeBuffer[2][OH2]=21 ; TradeTimeBuffer[2][CH2]=24;
TradeTimeBuffer[3][OH1]=0 ; TradeTimeBuffer[3][CH1]=6 ; TradeTimeBuffer[3][OH2]=20 ; TradeTimeBuffer[3][CH2]=24;
TradeTimeBuffer[4][OH1]=0 ; TradeTimeBuffer[4][CH1]=3 ; TradeTimeBuffer[4][OH2]=22 ; TradeTimeBuffer[4][CH2]=24;
}
result=true;
}
}
if (AccountCompany()=="ODL Securities")
{
if (Symbol()=="EURGBP" && Period()==PERIOD_M5)
{
ChannelBars=24; CheckTimeBar=false; EqualBars=true;
if (EachDayHourSettings) {OpenHour1=0; CloseHour1=5; OpenHour2=22; CloseHour2=0;}
result=true;
}
if (Symbol()=="EURGBP" && Period()==PERIOD_M15)
{
ChannelBars=9; CheckTimeBar=false; EqualBars=true;
if (EachDayHourSettings) {OpenHour1=0; CloseHour1=5; OpenHour2=22; CloseHour2=0;}
result=true;
}
if (Symbol()=="EURCHF" && Period()==PERIOD_M15)
{
ChannelBars=15; CheckTimeBar=false; EqualBars=true;
if (EachDayHourSettings) {OpenHour1=0; CloseHour1=1; OpenHour2=22; CloseHour2=0;}
result=true;
}
}
if (AccountCompany()=="Alpari Ltd.")
{
if (Symbol()=="EURGBP" && Period()==PERIOD_M15)
{
ChannelBars=18; CheckTimeBar=false; EqualBars=true;
// TakeProfit = 20; StopLoss = 30;
if (EachDayHourSettings) {OpenHour1=0; CloseHour1=1; OpenHour2=22; CloseHour2=0;}
if (TradeTimeChoise==0)
{
//Trading hours (fixed)
TradeTimeBuffer[0][OH1]=0 ; TradeTimeBuffer[0][CH1]=1 ; TradeTimeBuffer[0][OH2]=22 ; TradeTimeBuffer[0][CH2]=24;
TradeTimeBuffer[1][OH1]=0 ; TradeTimeBuffer[1][CH1]=1 ; TradeTimeBuffer[1][OH2]=22 ; TradeTimeBuffer[1][CH2]=24;
TradeTimeBuffer[2][OH1]=0 ; TradeTimeBuffer[2][CH1]=1 ; TradeTimeBuffer[2][OH2]=22 ; TradeTimeBuffer[2][CH2]=24;
TradeTimeBuffer[3][OH1]=0 ; TradeTimeBuffer[3][CH1]=1 ; TradeTimeBuffer[3][OH2]=22 ; TradeTimeBuffer[3][CH2]=24;
TradeTimeBuffer[4][OH1]=0 ; TradeTimeBuffer[4][CH1]=1 ; TradeTimeBuffer[4][OH2]=22 ; TradeTimeBuffer[4][CH2]=24;
}
if (TradeTimeChoise==1)
{
//Trading hours (optimal)
TradeTimeBuffer[0][OH1]=0 ; TradeTimeBuffer[0][CH1]=1 ; TradeTimeBuffer[0][OH2]=20 ; TradeTimeBuffer[0][CH2]=24;
TradeTimeBuffer[1][OH1]=0 ; TradeTimeBuffer[1][CH1]=2 ; TradeTimeBuffer[1][OH2]=18 ; TradeTimeBuffer[1][CH2]=24;
TradeTimeBuffer[2][OH1]=0 ; TradeTimeBuffer[2][CH1]=0 ; TradeTimeBuffer[2][OH2]=21 ; TradeTimeBuffer[2][CH2]=24;
TradeTimeBuffer[3][OH1]=0 ; TradeTimeBuffer[3][CH1]=6 ; TradeTimeBuffer[3][OH2]=20 ; TradeTimeBuffer[3][CH2]=24;
TradeTimeBuffer[4][OH1]=0 ; TradeTimeBuffer[4][CH1]=3 ; TradeTimeBuffer[4][OH2]=22 ; TradeTimeBuffer[4][CH2]=24;
}
result=true;
}
}
if (AccountCompany()=="Private Consulting Corp.")
{
if (Symbol()=="EURCHF" && Period()==PERIOD_M1)
{
ChannelBars=1; CheckTimeBar=false; EqualBars=false;
if (EachDayHourSettings) {OpenHour1=0; CloseHour1=1; OpenHour2=23; CloseHour2=0;}
if (TradeTimeChoise==0)
{
//Trading hours (fixed)
TradeTimeBuffer[0][OH1]=0 ; TradeTimeBuffer[0][CH1]=1 ; TradeTimeBuffer[0][OH2]=23 ; TradeTimeBuffer[0][CH2]=24;
TradeTimeBuffer[1][OH1]=0 ; TradeTimeBuffer[1][CH1]=1 ; TradeTimeBuffer[1][OH2]=23 ; TradeTimeBuffer[1][CH2]=24;
TradeTimeBuffer[2][OH1]=0 ; TradeTimeBuffer[2][CH1]=1 ; TradeTimeBuffer[2][OH2]=23 ; TradeTimeBuffer[2][CH2]=24;
TradeTimeBuffer[3][OH1]=0 ; TradeTimeBuffer[3][CH1]=1 ; TradeTimeBuffer[3][OH2]=23 ; TradeTimeBuffer[3][CH2]=24;
TradeTimeBuffer[4][OH1]=0 ; TradeTimeBuffer[4][CH1]=1 ; TradeTimeBuffer[4][OH2]=23 ; TradeTimeBuffer[4][CH2]=24;
}
if (TradeTimeChoise==1)
{
//Trading hours (optimal)
TradeTimeBuffer[0][OH1]=0 ; TradeTimeBuffer[0][CH1]=0 ; TradeTimeBuffer[0][OH2]=21 ; TradeTimeBuffer[0][CH2]=24;
TradeTimeBuffer[1][OH1]=0 ; TradeTimeBuffer[1][CH1]=1 ; TradeTimeBuffer[1][OH2]=23 ; TradeTimeBuffer[1][CH2]=24;
TradeTimeBuffer[2][OH1]=0 ; TradeTimeBuffer[2][CH1]=0 ; TradeTimeBuffer[2][OH2]=23 ; TradeTimeBuffer[2][CH2]=24;
TradeTimeBuffer[3][OH1]=0 ; TradeTimeBuffer[3][CH1]=0 ; TradeTimeBuffer[3][OH2]=22 ; TradeTimeBuffer[3][CH2]=24;
TradeTimeBuffer[4][OH1]=0 ; TradeTimeBuffer[4][CH1]=6 ; TradeTimeBuffer[4][OH2]=24 ; TradeTimeBuffer[4][CH2]=24;
}
if (TradeTimeChoise>1)
{
//Trading hours (most profitable)
TradeTimeBuffer[0][OH1]=0 ; TradeTimeBuffer[0][CH1]=1 ; TradeTimeBuffer[0][OH2]=21 ; TradeTimeBuffer[0][CH2]=24;
TradeTimeBuffer[1][OH1]=0 ; TradeTimeBuffer[1][CH1]=7 ; TradeTimeBuffer[1][OH2]=23 ; TradeTimeBuffer[1][CH2]=24;
TradeTimeBuffer[2][OH1]=0 ; TradeTimeBuffer[2][CH1]=0 ; TradeTimeBuffer[2][OH2]=23 ; TradeTimeBuffer[2][CH2]=24;
TradeTimeBuffer[3][OH1]=0 ; TradeTimeBuffer[3][CH1]=7 ; TradeTimeBuffer[3][OH2]=21 ; TradeTimeBuffer[3][CH2]=24;
TradeTimeBuffer[4][OH1]=0 ; TradeTimeBuffer[4][CH1]=8 ; TradeTimeBuffer[4][OH2]=24 ; TradeTimeBuffer[4][CH2]=24;
}
result=true;
}
}
return(result);

}

 

//+-----------------------------------------------------+
//| show summary panel on chart |
//+-----------------------------------------------------+
void ShowInfo()
{

ChartProfit=0;
BuyOpenOrders=0;
SellOpenOrders=0;
BuyPendingOrders=0;
SellPendingOrders=0;
//BuyFlag=False;
//SellFlag=False;
_text1="---";
_text2="";
_text3="---";

for(int cnt=0; cnt<OrdersTotal(); cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if (OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber)
{
if (OrderType()== OP_BUY)
{
BuyOpenOrders++;
ChartProfit=ChartProfit+OrderProfit();

}
if (OrderType()== OP_SELL)
{
SellOpenOrders++;
ChartProfit=ChartProfit+OrderProfit();

}
if (OrderType()== OP_SELLSTOP)
{
SellPendingOrders++;
}
if (OrderType()== OP_BUYSTOP)
{
BuyPendingOrders++;
}
}
}

switch(TickRotate)
{
case 0: TickDisplay=" . "; TickRotate = TickRotate + 1; break;
case 1: TickDisplay=" .. "; TickRotate = TickRotate + 1; break;
case 2: TickDisplay=" ... "; TickRotate = TickRotate + 1; break;
case 3: TickDisplay=" .... "; TickRotate = TickRotate + 1; break;
case 4: TickDisplay=" ..... "; TickRotate = TickRotate + 1; break;
case 5: TickDisplay=" ...... "; TickRotate = TickRotate + 1; break;
case 6: TickDisplay=" ....... "; TickRotate = TickRotate + 1; break;
case 7: TickDisplay=" ........ "; TickRotate = TickRotate + 1; break;
case 8: TickDisplay=" ......... "; TickRotate = TickRotate + 1; break;
case 9: TickDisplay=" .......... "; TickRotate = 0; break;
}

//if (Trend==0) _text1 = "---";
//if (Trend==1) _text1 = "UP";
//if (Trend==-1) _text1 = "DOWN";

//if (subOkToTrade()) _text2=" ** Trading Allowed **";

Drawdown = (AccountEquity() / AccountBalance() - 1.0) / (-0.01);
if (Drawdown < 0.0) Drawdown=0.0;

if (Drawdown>WorstDrawdown) {WorstDrawdown=Drawdown;}

DisplayText =CrLf + Margin + "...::: "+VersionNumber+" :::..."+ _text2+CrLf;

DisplayText = DisplayText + Margin +"Date: "+Month()+"-"+Day()+"-"+Year()+" Server Time: "+TimeToStr(TimeCurrent(), TIME_SECONDS)+" Magic# "+MagicNumber+TickDisplay+CrLf; //DoubleToStr( ,2)
DisplayText = DisplayText + Margin +"Pair: "+ Symbol()+ " Price: "+DoubleToStr(NormalizeDouble(Bid,LotDigit),LotDigit)+" Lot Size: "+DoubleToStr(LotsForTrade,2)+CrLf; //+ " Trend: "+ _text1
DisplayText = DisplayText + Margin +"Largest Spread: "+DoubleToStr(LargestSpread,2)+" Smallest Spread: "+DoubleToStr(SmallestSpread,2)+" Current Spread: "+DoubleToStr(Spread,2)+CrLf;
//DisplayText = DisplayText + Margin +"COG Diff: "+DoubleToStr(NormalizeDouble(((GlobalCOGRangeValue)/LocalPoint),LotDigit),LotDigit)+" TrailingStop: "+DoubleToStr(NormalizeDouble(TrailingStop,LotDigit),LotDigit)+ CrLf; //"COG Upper: "+DoubleToStr(NormalizeDouble(GlobalCOGUpperValue,LotDigit),LotDigit)+" COG Lower: "+DoubleToStr(NormalizeDouble(GlobalCOGLowerValue,LotDigit),LotDigit)+
//DisplayText = DisplayText + Margin +"COG C0: "+ DoubleToStr(NormalizeDouble(GlobalCOGValueC0,LotDigit),LotDigit)+ CrLf;

//DisplayText = DisplayText + Margin +"TCCI Sequence: "+Tcci5+" "+Tcci4+" "+Tcci3+" "+Tcci2+" "+Tcci1+" TCCI: "+ _text3 + CrLf;
//DisplayText = DisplayText + Margin +"BAND Sequence: "+Band5+" "+Band4+" "+Band3+" "+Band2+" "+Band1+" Band: "+ _text4 + CrLf;

//DisplayText = DisplayText + Margin +"CurTrend: "+ ld_44 + CrLf;// ld_44 = GetEntrySignal();
//DisplayText = DisplayText + Margin +"Indi Trend: "+ _text3 + " EA Last Trend: "+ _text1 +CrLf;
DisplayText = DisplayText + Margin +"Open Buy Orders: "+ BuyOpenOrders+ " Open Sell Orders: "+ SellOpenOrders+CrLf;
//DisplayText = DisplayText + Margin +"Buy Pending Orders: "+BuyPendingOrders+ " Sell Pending Orders: "+ SellPendingOrders+CrLf;
DisplayText = DisplayText + Margin +"Largest Drawdown: "+DoubleToStr(WorstDrawdown,2)+ " % Current Drawdown: "+DoubleToStr(Drawdown,2)+" %" +CrLf;

DisplayText = DisplayText + Margin +"Account Balance: "+ DoubleToStr(AccountBalance(),2)+" Account Equity: "+ DoubleToStr(AccountEquity(),2)+" ChartProfit: "+DoubleToStr(AccountProfit(),2)+ CrLf; //+" Account Profit: "+ DoubleToStr(AccountProfit(),2)

Comment(DisplayText);

return(0);
}

相关资源

暂无评论

暂无评论...