Dragon Pips v2.02 Rev

Dragon Pips v2.02 Rev 最新版

官方版 无广告 159

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

34 人已下载 手机查看

#property copyright "copyright © 2019 - Dragonpips.com"
#property link "http://www.Dragonpips.com"
#include <stdlib.mqh>

#import "kernel32.dll"
void GetLocalTime(int& TimeArray[]);
int GetTimeZoneInformation(int& TZInfoArray[]);
#import

extern string SetYourBalanceTargetBelow = "- Stop if balance target equal or bigger than --";
extern double BalanceTarget = 10000000.0;
extern string za="-- Trading Time (GMT) --------------------------------------------";
extern string TradingTime = "19:00-23:00 GMT is default";
extern string OpenHour = "19:00"; // 19:00 GMT
extern string CloseHour = "23:00"; // 23:00 GMT
extern string xa="-- Money Management ----------------------------------------------";
extern string lotsInfo = "-- balance under $1000 start with 0.01 Lots";
extern bool MoneyManagement = false; // Change to false to shutdown money management controls.
// Lots = 1 will be in effect and only 1 lot will be open regardless of equity.
extern string mmm="Mode: 1-FreeMargin 2-Equity 3-Balance";
extern int MM_Mode = 1;
extern double TradeSizePercent = 5; // Change to whatever percent of equity you wish to risk.
extern double Lots = 0.1; // standard lot size.
extern double MaxLots = 10;

extern string zb="----------------------------------------------";
extern bool Aggressive = true;

extern string xb="-- Trade Management ----------------------------------------------";
extern int MaxTrades = 3;
extern int MaxTrades_x_Bar = 1;
extern string xc = "---------------------------";

extern string BrokerSpread = "-- Set spread not over than 4 --";
extern double Spread = 4.0;
extern double TakeProfit = 5.0;
extern double StopLoss = 25.0;
extern string x0 = "---------------------------";
extern bool ECN_STP = true;
extern string x1 = "---------------------------";
extern bool Use_TimeProtectionLevels = true;
extern int MinutesToClose_Level_1 = 60;
extern double PipsToClose_Level_1 = 3.0;
extern int MinutesToClose_Level_2 = 140;
extern double PipsToClose_Level_2 = 2.0;
extern int MinutesToClose_Level_3 = 170;
extern double PipsToClose_Level_3 = 1.0;
extern int MinutesToClose_Level_4 = 200;
extern double PipsToClose_Level_4 = -1.0;
extern int MinutesToClose_Level_5 = 240;
extern double PipsToClose_Level_5 = -4.0;
extern string s1 = "---------------------------";
extern bool Use_RangeFilter = true;
extern int Range_PreviousBars = 8;
extern double Max_Range = 45.0;
extern string s2 = "---------------------------";
extern bool Use_Close_AllTrades = false;
extern string Close_AllTrades_At = "23:30";
extern string s3 = "---------------------------";
extern bool Use_Strategy1 = true;
extern bool Use_Strategy2 = true;
extern bool Use_Strategy3 = true;
extern bool Use_Strategy4 = true;
extern string x2 = "-- Extreme Edition -------------------------";
extern int ATR_Threshold = 20;
extern int Slippage = 1;
extern string x3 = "---------------------------";
extern int MagicNumber = 0;
extern string x4 = "---------------------------";
extern string ExpertInfo = "-- Change EA name to hide EA identity -----------------";
extern string ExpertName = "DragonPips Ultimate v2.02";
extern string x90="-- Alerts control ----------------------------------------------";
extern bool MessageAlert = false;
extern bool SoundAlert = false;
extern string SoundFileAtOpen = "alert.wav";
extern string SoundFileAtClose = "news.wav";
extern string x91="-- Manual GMT Offset -------------------------------------------";
extern bool Use_Manual_GMTOffset = false;
extern int Manual_GMTOffset = 0;
extern string x92="-- Backtests use only ------------------------------------------";
extern int GMTOffset_for_Backtests=0;

bool gi_76;
bool gi_80;
bool gi_84;
bool gi_88;
bool gi_196 = TRUE;
bool gi_200 = TRUE;
double gd_164 = 0.0001;
int g_slippage_220;
int gi_224 = 32;
int gi_232 = 3;
int g_magic_240 = 371443;
int g_magic_244 = 3714431;
int g_magic_248 = 3714432;
int g_magic_252 = 3714433;
int gi_256;
double gi_260;
int gi_264;
double gi_268;
int gi_272;
double gi_276;
int gi_280;
double gi_284;
int gi_288;
double gi_292;
bool gi_296 = TRUE;
double gd_300 = 0.001;
double gd_308 = 0.001;
double gd_316 = 0.0012;
int gi_324 = 55;
bool gi_328 = TRUE;
bool gi_332 = TRUE;
bool gi_336 = TRUE;
bool gi_340 = TRUE;
bool gi_344 = TRUE;
bool gi_348 = TRUE;
bool gi_352 = TRUE;
bool gi_356 = TRUE;
double g_minlot_360 = 0.0;
double g_maxlot_368 = 0.0;
int g_lotsize_376 = 0;
int g_leverage_380 = 0;
double g_lots_384;
double g_lots_392;
int g_pos_400;
int gi_404 = 0;
int g_count_408 = 0;
int g_count_412 = 0;
int g_count_416 = 0;
int g_count_420 = 0;
int g_count_424 = 0;
int gi_428 = 0;
int gi_432 = 0;
int gi_436 = 0;
int gi_440 = 0;
int gi_444 = 0;
int gi_448 = 0;
int gi_452 = 0;
int gi_456 = 0;
int gi_460 = 0;
int gi_464 = 0;
double g_ord_open_price_468 = 0.0;
double g_ord_open_price_476 = 0.0;
double g_ord_open_price_484 = 0.0;
double g_ord_open_price_492 = 0.0;
double g_ord_open_price_500 = 0.0;
double g_ord_open_price_508 = 0.0;
double g_ord_open_price_516 = 0.0;
double g_ord_open_price_524 = 0.0;
double g_ord_open_price_532 = 0.0;
double g_ord_open_price_540 = 0.0;
double g_price_564 = 0.0;
double g_price_572 = 0.0;
double g_ifractals_580;
double g_ifractals_588;
double g_ifractals_612;
double g_ifractals_620;
int gi_644 = 0;
double gd_652 = 0.0;
int gi_660 = 0;

bool HighRange=false;
double Rx;
string msg1;
int err;
string ddx[] = {".", "..", "...", "....", "....."};
int gmt_shift=0;
int GMTOffset;
datetime GMT;
int time;
int BarCount;
int TradesITB = 0;
int DigitsLots = 1;
double iMinLot;
int TimeH;
int OpenH;
int CloseH;
bool TimeOK;
int minX;

int init() {
g_slippage_220 = Slippage;
if (Digits%2!=0) g_slippage_220*=10;
if (Digits<4) gd_164=0.01;
if (StringFind(OpenHour, ":",2)==-1 || StringLen(OpenHour)!=5) Alert ("Wrong time for OpenHour... Please enter HH:MM format.");
if (StringFind(CloseHour, ":",2)==-1 || StringLen(CloseHour)!=5) Alert ("Wrong time for CloseHour... Please enter HH:MM format.");
if (StringFind(Close_AllTrades_At, ":",2)==-1 || StringLen(Close_AllTrades_At)!=5) Alert ("Wrong time for Close_AllTrades_At... Please enter HH:MM format.");
if (OpenHour=="24:00") OpenHour="00:00";
if (CloseHour=="24:00") CloseHour="00:00";
if (Period() != 15) Alert ("Error: Wrong TimeFrame. Use DragonPips on 15 Minutes Time Frame chart.");
gi_256 = MinutesToClose_Level_1;
gi_260 = PipsToClose_Level_1;
gi_264 = MinutesToClose_Level_2;
gi_268 = PipsToClose_Level_2;
gi_272 = MinutesToClose_Level_3;
gi_276 = PipsToClose_Level_3;
gi_280 = MinutesToClose_Level_4;
gi_284 = PipsToClose_Level_4;
gi_288 = MinutesToClose_Level_5;
gi_292 = PipsToClose_Level_5;
if (MagicNumber>0) {
g_magic_240 = MagicNumber;
g_magic_244 = MagicNumber+1;
g_magic_248 = MagicNumber+2;
g_magic_252 = MagicNumber+3;
}
gi_76 = Use_Strategy1;
gi_80 = Use_Strategy2;
gi_84 = Use_Strategy3;
gi_88 = Use_Strategy4;
iMinLot = MarketInfo(Symbol(), MODE_MINLOT);
//+--------------------------------------------------------
if (iMinLot == 0.05) DigitsLots = 1; // TadawulFX
else if (iMinLot < 0.1) DigitsLots = 2; // micro account
else DigitsLots = 1; // mini & standard account
//+--------------------------------------------------------
if (!IsDllsAllowed())
{
Alert ("DragonPips: DLLs are Disabled. To enable, tick the -Allow DLL import- checkbox in the Common Tab on properties window");
Comment ("\n\n DLLs are Disabled. To enable, tick the -Allow DLL import- checkbox in the Common Tab on properties window.");
Sleep(4000);
return (0);
}
if (IsExpertEnabled()) Comment ("\n\n DragonPips initializing...");
else Comment ("\n\n DragonPips is DISABLED...");
Sleep(4000);
ObjectCreate("Session", OBJ_LABEL, 0, 0, 0);
ObjectSetText("Session", "", 9, "Arial", Silver);
ObjectSet("Session", OBJPROP_CORNER, 2);
ObjectSet("Session", OBJPROP_XDISTANCE, 5);
ObjectSet("Session", OBJPROP_YDISTANCE, 8);
for (int lv0 = 0; !IsStopped() && !IsConnected(); lv0++)
{
Comment("\n\n Waiting for connection to server" + WaitW(lv0));
Sleep(200);
}
Atenea();
if (IsExpertEnabled()) Comment ("\n\n DragonPips initialized\n\n Waiting for price data...");
else Comment ("\n\n DragonPips is DISABLED...");
BarCount = -1;
TradesITB = 0;
return (0);
}

int deinit() {
ObjectDelete("Session");
return (0);
}

int start() {
if (StringFind(OpenHour, ":",2)==-1 || StringLen(OpenHour)!=5) return(0);
if (StringFind(CloseHour, ":",2)==-1 || StringLen(CloseHour)!=5) return(0);
if (StringFind(Close_AllTrades_At, ":",2)==-1 || StringLen(Close_AllTrades_At)!=5) return(0);
if (!IsDllsAllowed()) return (0);
if (GMTOffset <= -8 || GMTOffset >= 8)
{
Atenea();
return (0);
}
if (Use_Manual_GMTOffset==true) GMTOffset = Manual_GMTOffset;
GMT = TimeCurrent() - (GMTOffset * 3600);
time = GMT;

g_price_564 = TakeProfit;
g_price_572 = 0;
int l_cmd_0;
g_count_408 = 0;
g_count_412 = 0;
g_count_416 = 0;
g_count_420 = 0;
g_count_424 = 0;
gi_428 = 0.0;
gi_432 = 0.0;
gi_436 = 0.0;
gi_440 = 0.0;
gi_444 = 0.0;
gi_448 = 0.0;
gi_452 = 0.0;
gi_456 = 0.0;
gi_460 = 0.0;
gi_464 = 0.0;
g_ord_open_price_468 = 0.0;
g_ord_open_price_476 = 0.0;
g_ord_open_price_484 = 0.0;
g_ord_open_price_492 = 0.0;
g_ord_open_price_500 = 0.0;
g_ord_open_price_508 = 0.0;
g_ord_open_price_516 = 0.0;
g_ord_open_price_524 = 0.0;
g_ord_open_price_532 = 0.0;
g_ord_open_price_540 = 0.0;

for (int l_pos_32 = 0; l_pos_32 < OrdersTotal(); l_pos_32++) {
OrderSelect(l_pos_32, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol() && (OrderMagicNumber() == g_magic_240 || OrderMagicNumber() == g_magic_244 || OrderMagicNumber() == g_magic_248 || OrderMagicNumber() == g_magic_252)) {
g_count_408++;
if (OrderType() == OP_BUY) {
gi_448++;
g_ord_open_price_508 = OrderOpenPrice();
}
if (OrderType() == OP_SELL) {
gi_428++;
g_ord_open_price_468 = OrderOpenPrice();
}
}
}

if (BalanceTarget > 0.0 && AccountEquity() >= BalanceTarget)
{
if (g_count_408>0)
{
CloseAll();
Print("Account Profit Reached. All Open Trades Have Been Closed");
}
Comment("\n\n Dragon Ultimate\n\n Account Profit Reached. New trades are NOT allowed.");
return (0);
}

if (Use_Close_AllTrades==true && g_count_408>0)
{
if (minX!=Minute())
{
if (TimeHour(GMT)==TimeHour(StrToTime(Close_AllTrades_At)) && TimeMinute(GMT)==TimeMinute(StrToTime(Close_AllTrades_At)))
{
CloseAll();
g_count_408=0;
if (MessageAlert) Alert ("All Open Trades Have Been Closed at " + Close_AllTrades_At + " GMT.");
else Print("All Open Trades Have Been Closed at " + Close_AllTrades_At + " GMT.");
}
}
}

onScreenComment();

HideTestIndicators(TRUE);

for (int li_12 = 1; li_12 < Bars; li_12++) {
if (iFractals(NULL, PERIOD_M15, MODE_UPPER, li_12) != 0.0) {
g_ifractals_580 = iFractals(NULL, PERIOD_M15, MODE_UPPER, li_12);
break;
}
}
for (int li_16 = 1; li_16 < Bars; li_16++) {
if (iFractals(NULL, PERIOD_M15, MODE_LOWER, li_16) != 0.0) {
g_ifractals_588 = iFractals(NULL, PERIOD_M15, MODE_LOWER, li_16);
break;
}
}
for (int li_20 = 1; li_20 < Bars; li_20++) {
if (iFractals(NULL, PERIOD_H1, MODE_UPPER, li_20) != 0.0) {
g_ifractals_612 = iFractals(NULL, PERIOD_H1, MODE_UPPER, li_20);
break;
}
}
for (int li_24 = 1; li_24 < Bars; li_24++) {
if (iFractals(NULL, PERIOD_H1, MODE_LOWER, li_24) != 0.0) {
g_ifractals_620 = iFractals(NULL, PERIOD_H1, MODE_LOWER, li_24);
break;
}
}
gi_644 = MathRound((g_ifractals_580 - g_ifractals_588) / gd_164);
gd_652 = 0;
gd_652 = g_ifractals_580 - (g_ifractals_580 - g_ifractals_588) / 2.0;
gi_660 = MathRound(iATR(Symbol(), PERIOD_M15, 4, 0) / gd_164);
bool li_28 = FALSE;
if (Close[0] <= g_ifractals_612 && Close[0] >= g_ifractals_620) li_28 = TRUE;

if (gi_196 == TRUE) {
double OOPx=0, MP, MyB, MyA;
for (int l_pos_36 = 0; l_pos_36 < OrdersTotal(); l_pos_36++) {
OrderSelect(l_pos_36, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol()!=Symbol()) continue;
OOPx = OrderOpenPrice();
MP = Bid;
MyB = NormalizeDouble(MP, Digits);
MP = Ask;
MyA = NormalizeDouble(MP, Digits);
if (OrderType() == OP_BUY && OrderMagicNumber() == g_magic_240) {
if (MyB >= NormalizeDouble(OOPx + (TakeProfit * gd_164),Digits)) {
if (ECN_STP==false) RefreshRates();
if (!OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_220, Orange)) errClose(OrderTicket());
if (SoundAlert) PlaySound(SoundFileAtClose);
Print ("Trade Closed on TP."); //*********************
}
}
if (OrderType() == OP_BUY && OrderMagicNumber() == g_magic_244) {
if (MyB >= NormalizeDouble(OOPx + ((TakeProfit - 2.0) * gd_164),Digits)) {
if (ECN_STP==false) RefreshRates();
if (!OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_220, Orange)) errClose(OrderTicket());
if (SoundAlert) PlaySound(SoundFileAtClose);
Print ("Trade Closed on TP-2."); //*********************
}
}
if (OrderType() == OP_BUY && OrderMagicNumber() == g_magic_248) {
if (MyB >= NormalizeDouble(OOPx + ((TakeProfit - 1.0) * gd_164),Digits)) {
if (ECN_STP==false) RefreshRates();
if (!OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_220, Orange)) errClose(OrderTicket());
if (SoundAlert) PlaySound(SoundFileAtClose);
Print ("Trade Closed on TP-1."); //*********************
}
}
if (OrderType() == OP_BUY && OrderMagicNumber() == g_magic_252) {
if (MyB >= NormalizeDouble(OOPx + ((TakeProfit - 2.0) * gd_164),Digits)) {
if (ECN_STP==false) RefreshRates();
if (!OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_220, Orange)) errClose(OrderTicket());
if (SoundAlert) PlaySound(SoundFileAtClose);
Print ("Trade Closed on TP-2."); //*********************
}
}
if (OrderType() == OP_SELL && OrderMagicNumber() == g_magic_240) {
if (MyA <= NormalizeDouble(OOPx - (TakeProfit * gd_164),Digits)) {
if (ECN_STP==false) RefreshRates();
if (!OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_220, Orange)) errClose(OrderTicket());
if (SoundAlert) PlaySound(SoundFileAtClose);
Print ("Trade Closed on TP."); //*********************
}
}
if (OrderType() == OP_SELL && OrderMagicNumber() == g_magic_244) {
if (MyA <= NormalizeDouble(OOPx - ((TakeProfit - 2.0) * gd_164),Digits)) {
if (ECN_STP==false) RefreshRates();
if (!OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_220, Orange)) errClose(OrderTicket());
if (SoundAlert) PlaySound(SoundFileAtClose);
Print ("Trade Closed on TP-2."); //*********************
}
}
if (OrderType() == OP_SELL && OrderMagicNumber() == g_magic_248) {
if (MyA <= NormalizeDouble(OOPx - ((TakeProfit - 1.0) * gd_164),Digits)) {
if (ECN_STP==false) RefreshRates();
if (!OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_220, Orange)) errClose(OrderTicket());
if (SoundAlert) PlaySound(SoundFileAtClose);
Print ("Trade Closed on TP-1."); //*********************
}
}
if (OrderType() == OP_SELL && OrderMagicNumber() == g_magic_252) {
if (MyA <= NormalizeDouble(OOPx - ((TakeProfit - 2.0) * gd_164),Digits)) {
if (ECN_STP==false) RefreshRates();
if (!OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_220, Orange)) errClose(OrderTicket());
if (SoundAlert) PlaySound(SoundFileAtClose);
Print ("Trade Closed on TP-2."); //*********************
}
}
}
}
if (Use_TimeProtectionLevels==TRUE) {
for (int l_pos_40 = 0; l_pos_40 < OrdersTotal(); l_pos_40++) {
OrderSelect(l_pos_40, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol()!=Symbol()) continue;
if (OrderType() == OP_BUY && (OrderMagicNumber() == g_magic_240 || OrderMagicNumber() == g_magic_244 || OrderMagicNumber() == g_magic_248 || OrderMagicNumber() == g_magic_252)) {
if (TimeCurrent() - OrderOpenTime() > 60 * gi_256 && TimeCurrent() - OrderOpenTime() < 60 * gi_264 && Bid >= NormalizeDouble(OrderOpenPrice() + (gi_260 * gd_164),Digits)) {
if (ECN_STP==false) RefreshRates();
if (!OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_220, Orange)) errClose(OrderTicket());
if (SoundAlert) PlaySound(SoundFileAtClose);
Print("Prot. Level 1 - Close Price :" + DoubleToStr(OrderClosePrice(), Digits) + " Lots : " + DoubleToStr(OrderLots(), 2) + " Order Number : " + DoubleToStr(OrderTicket(), 0) +
" Profit : $ " + DoubleToStr(OrderProfit(), 2));
}
if (TimeCurrent() - OrderOpenTime() > 60 * gi_264 && TimeCurrent() - OrderOpenTime() < 60 * gi_272 && Bid >= NormalizeDouble(OrderOpenPrice() + (gi_268 * gd_164),Digits)) {
if (ECN_STP==false) RefreshRates();
if (!OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_220, Orange)) errClose(OrderTicket());
if (SoundAlert) PlaySound(SoundFileAtClose);
Print("Prot. Level 2 - Close Price :" + DoubleToStr(OrderClosePrice(), Digits) + " Lots : " + DoubleToStr(OrderLots(), 2) + " Order Number : " + DoubleToStr(OrderTicket(), 0) +
" Profit : $ " + DoubleToStr(OrderProfit(), 2));
}
if (TimeCurrent() - OrderOpenTime() > 60 * gi_272 && TimeCurrent() - OrderOpenTime() < 60 * gi_280 && Bid >= NormalizeDouble(OrderOpenPrice() + (gi_276 * gd_164),Digits)) {
if (ECN_STP==false) RefreshRates();
if (!OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_220, Orange)) errClose(OrderTicket());
if (SoundAlert) PlaySound(SoundFileAtClose);
Print("Prot. Level 3 - Close Price :" + DoubleToStr(OrderClosePrice(), Digits) + " Lots : " + DoubleToStr(OrderLots(), 2) + " Order Number : " + DoubleToStr(OrderTicket(), 0) +
" Profit : $ " + DoubleToStr(OrderProfit(), 2));
}
if (TimeCurrent() - OrderOpenTime() > 60 * gi_280 && TimeCurrent() - OrderOpenTime() < 60 * gi_288 && Bid >= NormalizeDouble(OrderOpenPrice() + (gi_284 * gd_164),Digits)) {
if (ECN_STP==false) RefreshRates();
if (!OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_220, Orange)) errClose(OrderTicket());
if (SoundAlert) PlaySound(SoundFileAtClose);
Print("Prot. Level 4 - Close Price :" + DoubleToStr(OrderClosePrice(), Digits) + " Lots : " + DoubleToStr(OrderLots(), 2) + " Order Number : " + DoubleToStr(OrderTicket(), 0) +
" Profit : $ " + DoubleToStr(OrderProfit(), 2));
}
if (TimeCurrent() - OrderOpenTime() > 60 * gi_288 && Bid >= NormalizeDouble(OrderOpenPrice() + (gi_292 * gd_164),Digits)) {
if (ECN_STP==false) RefreshRates();
if (!OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_220, Orange)) errClose(OrderTicket());
if (SoundAlert) PlaySound(SoundFileAtClose);
Print("Prot. Level 5 - Close Price :" + DoubleToStr(OrderClosePrice(), Digits) + " Lots : " + DoubleToStr(OrderLots(), 2) + " Order Number : " + DoubleToStr(OrderTicket(), 0) +
" Profit : $ " + DoubleToStr(OrderProfit(), 2));
}
if (TimeDayOfWeek(time) == 5 && TimeHour(time) >= 19) {
if (ECN_STP==false) RefreshRates();
if (!OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_220, Orange)) errClose(OrderTicket());
if (SoundAlert) PlaySound(SoundFileAtClose);
Print("Prot. Level 5 - Close Price :" + DoubleToStr(OrderClosePrice(), Digits) + " Lots : " + DoubleToStr(OrderLots(), 2) + " Order Number : " + DoubleToStr(OrderTicket(), 0) +
" Profit : $ " + DoubleToStr(OrderProfit(), 2));
}
}
if (OrderType() == OP_SELL && (OrderMagicNumber() == g_magic_240 || OrderMagicNumber() == g_magic_244 || OrderMagicNumber() == g_magic_248 || OrderMagicNumber() == g_magic_252)) {
if (TimeCurrent() - OrderOpenTime() > 60 * gi_256 && TimeCurrent() - OrderOpenTime() < 60 * gi_264 && Ask <= NormalizeDouble(OrderOpenPrice() - (gi_260 * gd_164),Digits)) {
if (ECN_STP==false) RefreshRates();
if (!OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_220, Orange)) errClose(OrderTicket());
if (SoundAlert) PlaySound(SoundFileAtClose);
Print("Prot. Level 1 - Close Price :" + DoubleToStr(OrderClosePrice(), Digits) + " Lots : " + DoubleToStr(OrderLots(), 2) + " Order Number : " + DoubleToStr(OrderTicket(), 0) +
" Profit : $ " + DoubleToStr(OrderProfit(), 2));
}
if (TimeCurrent() - OrderOpenTime() > 60 * gi_264 && TimeCurrent() - OrderOpenTime() < 60 * gi_272 && Ask <= NormalizeDouble(OrderOpenPrice() - (gi_268 * gd_164),Digits)) {
if (ECN_STP==false) RefreshRates();
if (!OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_220, Orange)) errClose(OrderTicket());
if (SoundAlert) PlaySound(SoundFileAtClose);
Print("Prot. Level 2 - Close Price :" + DoubleToStr(OrderClosePrice(), Digits) + " Lots : " + DoubleToStr(OrderLots(), 2) + " Order Number : " + DoubleToStr(OrderTicket(), 0) +
" Profit : $ " + DoubleToStr(OrderProfit(), 2));
}
if (TimeCurrent() - OrderOpenTime() > 60 * gi_272 && TimeCurrent() - OrderOpenTime() < 60 * gi_280 && Ask <= NormalizeDouble(OrderOpenPrice() - (gi_276 * gd_164),Digits)) {
if (ECN_STP==false) RefreshRates();
if (!OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_220, Orange)) errClose(OrderTicket());
if (SoundAlert) PlaySound(SoundFileAtClose);
Print("Prot. Level 3 - Close Price :" + DoubleToStr(OrderClosePrice(), Digits) + " Lots : " + DoubleToStr(OrderLots(), 2) + " Order Number : " + DoubleToStr(OrderTicket(), 0) +
" Profit : $ " + DoubleToStr(OrderProfit(), 2));
}
if (TimeCurrent() - OrderOpenTime() > 60 * gi_280 && TimeCurrent() - OrderOpenTime() < 60 * gi_288 && Ask <= NormalizeDouble(OrderOpenPrice() - (gi_284 * gd_164),Digits)) {
if (ECN_STP==false) RefreshRates();
if (!OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_220, Orange)) errClose(OrderTicket());
if (SoundAlert) PlaySound(SoundFileAtClose);
Print("Prot. Level 4 - Close Price :" + DoubleToStr(OrderClosePrice(), Digits) + " Lots : " + DoubleToStr(OrderLots(), 2) + " Order Number : " + DoubleToStr(OrderTicket(), 0) +
" Profit : $ " + DoubleToStr(OrderProfit(), 2));
}
if (TimeCurrent() - OrderOpenTime() > 60 * gi_288 && Ask <= (OrderOpenPrice() - (gi_292 * gd_164))) {
if (ECN_STP==false) RefreshRates();
if (!OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_220, Orange)) errClose(OrderTicket());
if (SoundAlert) PlaySound(SoundFileAtClose);
Print("Prot. Level 5 - Close Price :" + DoubleToStr(OrderClosePrice(), Digits) + " Lots : " + DoubleToStr(OrderLots(), 2) + " Order Number : " + DoubleToStr(OrderTicket(), 0) +
" Profit : $ " + DoubleToStr(OrderProfit(), 2));
}
if (TimeDayOfWeek(time) == 5 && TimeHour(time) >= 19) {
if (ECN_STP==false) RefreshRates();
if (!OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_220, Orange)) errClose(OrderTicket());
if (SoundAlert) PlaySound(SoundFileAtClose);
Print("Prot. Level 5 - Close Price :" + DoubleToStr(OrderClosePrice(), Digits) + " Lots : " + DoubleToStr(OrderLots(), 2) + " Order Number : " + DoubleToStr(OrderTicket(), 0) +
" Profit : $ " + DoubleToStr(OrderProfit(), 2));
}
}
}
}
if (BarCount!=Bars)
{
BarCount = Bars;
TradesITB = 0;
if (Use_RangeFilter==true)
{
if (ScanRange()==true) return (0);
}
}
if (HighRange==true) return (0);
if (gi_296 == TRUE) {
if (iOpen(Symbol(), PERIOD_M5, 0) >= Ask + gd_300) return;
if (iOpen(Symbol(), PERIOD_M5, 0) <= Bid - gd_300) return;
if (iOpen(Symbol(), PERIOD_M5, 1) >= Ask + gd_308) return;
if (iOpen(Symbol(), PERIOD_M5, 1) <= Bid - gd_308) return;
if (iOpen(Symbol(), PERIOD_M5, 2) >= Ask + gd_316) return;
if (iOpen(Symbol(), PERIOD_M5, 2) <= Bid - gd_316) return;
}
if (Ask - Bid > Spread * gd_164)
{
if (IsTesting())
{
string DSd;
if (Digits == 5 || Digits == 3) DSd = DoubleToStr(NormalizeDouble(MarketInfo(Symbol(), MODE_SPREAD)*0.1,1),1);
else DSd = DoubleToStr(NormalizeDouble(MarketInfo(Symbol(), MODE_SPREAD),0),0);
Print ("Spread: " + DSd + " more than Max Spread allowed: " + DoubleToStr(Spread,1));
}
return (0);
}
gi_404 = NormalizeDouble(MaxTrades / 2, 0);
if (gi_404<1) gi_404=1;
g_lots_384 = GetLots();
g_leverage_380 = AccountLeverage();
g_lotsize_376 = MarketInfo(Symbol(), MODE_LOTSIZE);
if (AccountFreeMargin() < Ask * g_lots_384 * g_lotsize_376 / g_leverage_380) {
Print("Low Account Balance. Lots = ", g_lots_384, " , Free Margin = ", AccountFreeMargin());
Comment("Low Account Balance. Lots = ", g_lots_384, " , Free Margin = ", AccountFreeMargin());
if (g_count_408==0) Sleep(6000);
return;
}
//double l_iclose_44 = iClose(Symbol(), PERIOD_M15, 0);
//double l_iopen_52 = iOpen(Symbol(), PERIOD_M15, 0);
//double l_ilow_60 = iLow(Symbol(), PERIOD_M15, 0);
//double l_ihigh_68 = iHigh(Symbol(), PERIOD_M15, 0);
double l_irsi_76 = iRSI(NULL, PERIOD_M15, 6, PRICE_CLOSE, 0);
double l_irsi_84 = iRSI(NULL, PERIOD_M1, 20, PRICE_CLOSE, 0);
double ld_92 = NormalizeDouble(iMA(NULL, 0, 8, 0, MODE_SMA, PRICE_WEIGHTED, 1), 4);
double ld_100 = NormalizeDouble(iMA(NULL, 0, 8, 0, MODE_SMA, PRICE_WEIGHTED, 1), 4);
double l_icci_108 = iCCI(Symbol(), PERIOD_M15, 14, PRICE_CLOSE, 0);
double l_icci_116 = iCCI(Symbol(), PERIOD_M5, 42, PRICE_CLOSE, 0);
double l_icci_124 = iCCI(Symbol(), PERIOD_M1, 210, PRICE_CLOSE, 0);
double l_icci_132 = iCCI(Symbol(), PERIOD_M1, 80, PRICE_CLOSE, 0);
//double l_imomentum_140 = iMomentum(Symbol(), PERIOD_M1, 60, PRICE_CLOSE, 0);
double l_imomentum_148 = iMomentum(Symbol(), PERIOD_M5, 4, PRICE_CLOSE, 0);
//double l_imomentum_156 = iMomentum(Symbol(), PERIOD_M15, 14, PRICE_CLOSE, 0);
//double l_iwpr_164 = iWPR(Symbol(), PERIOD_M1, 14, 0);
double l_iwpr_172 = iWPR(Symbol(), PERIOD_M5, 14, 0);
//double l_iwpr_180 = iWPR(Symbol(), PERIOD_M15, 14, 0);
double l_iforce_188 = iForce(Symbol(), PERIOD_M5, 13, MODE_SMA, PRICE_CLOSE, 0);
double l_ibands_196 = iBands(Symbol(), PERIOD_M5, 20, 2, 0, PRICE_WEIGHTED, MODE_UPPER, 1);
//double l_ibands_204 = iBands(Symbol(), PERIOD_M5, 20, 2, 0, PRICE_WEIGHTED, MODE_BASE, 1);
double l_ibands_212 = iBands(Symbol(), PERIOD_M5, 20, 2, 0, PRICE_WEIGHTED, MODE_LOWER, 1);
double l_ima_220 = iMA(Symbol(), PERIOD_M5, 1, 0, MODE_EMA, PRICE_HIGH, 0);
//double l_ima_228 = iMA(Symbol(), PERIOD_M5, 1, 0, MODE_EMA, PRICE_MEDIAN, 0);
double l_ima_236 = iMA(Symbol(), PERIOD_M5, 1, 0, MODE_EMA, PRICE_LOW, 0);
//double l_ibands_244 = iBands(Symbol(), PERIOD_M5, 20, 2, 0, PRICE_WEIGHTED, MODE_UPPER, 0);
//double l_ibands_252 = iBands(Symbol(), PERIOD_M5, 20, 2, 0, PRICE_WEIGHTED, MODE_BASE, 0);
//double l_ibands_260 = iBands(Symbol(), PERIOD_M5, 20, 2, 0, PRICE_WEIGHTED, MODE_LOWER, 0);
//double l_ima_268 = iMA(Symbol(), PERIOD_M1, 1, 0, MODE_EMA, PRICE_HIGH, 0);
//double l_ima_276 = iMA(Symbol(), PERIOD_M1, 1, 0, MODE_EMA, PRICE_MEDIAN, 0);
//double l_ima_284 = iMA(Symbol(), PERIOD_M1, 1, 0, MODE_EMA, PRICE_LOW, 0);

if (IsTradeTime() && g_count_408 < MaxTrades && li_28) {
if (!ExistPosition1() && gi_76 == TRUE) {
if (TimeDayOfWeek(time) == 0 || TimeDayOfWeek(time) == 5 && TimeHour(time) >= 14) return (0);
if (TradesITB >= MaxTrades_x_Bar) return(0);
if (l_irsi_76 < 30.0 || l_irsi_84 < 36.0 && ld_92 >= Ask + 20.0 * gd_164) {
if (gi_452 < 1 && gi_328) {
g_price_564 = 0;
g_price_572 = 0;
if (!gi_196) g_price_564 = Ask + TakeProfit * gd_164;
g_price_572 = Ask - StopLoss * gd_164;
if (Aggressive==true && NormalizeDouble(g_lots_384 * 2, DigitsLots) < MaxLots) g_lots_392 = NormalizeDouble(g_lots_384 * 2, DigitsLots);
else g_lots_392 = g_lots_384;
l_cmd_0=OrderSend(Symbol(), OP_SELL, g_lots_392, Ask, g_slippage_220, 0, 0, ExpertName + " 1", g_magic_240, 0, Green);
if (l_cmd_0>0)
{
waitIfBusy();
OrderModify(l_cmd_0, Ask, g_price_572, g_price_564, 0);
AlertIf ("BUY","S1");
gi_328 = FALSE;
gi_332 = TRUE;
if (TradesITB >= MaxTrades_x_Bar) return(0);
if (MaxTrades==1) return (0);
if (MaxTrades==g_count_408+1) return (0);
}
else
{
err = GetLastError();
msg1= DoubleToStr(Ask,Digits);
Print("Error opening BUY order : (" + err + ") " + ErrorDescription(err) + " | at " + msg1);
}
}
}
if (l_irsi_76 > 70.0 || l_irsi_84 > 64.0 && ld_100 <= Bid - 20.0 * gd_164) {
if (gi_432 < 1 && gi_332) {
g_price_564 = 0;
g_price_572 = 0;
if (!gi_196) g_price_564 = Bid - TakeProfit * gd_164;
g_price_572 = Bid + StopLoss * gd_164;
if (Aggressive==true && NormalizeDouble(g_lots_384 * 2, DigitsLots) < MaxLots) g_lots_392 = NormalizeDouble(g_lots_384 * 2, DigitsLots);
else g_lots_392 = g_lots_384;
l_cmd_0=OrderSend(Symbol(), OP_BUY, g_lots_392, Bid, g_slippage_220, 0, 0, ExpertName + " 1", g_magic_240, 0, Red);
if (l_cmd_0>0)
{
waitIfBusy();
OrderModify(l_cmd_0, Bid, g_price_572, g_price_564, 0);
AlertIf ("SELL","S1");
gi_332 = FALSE;
gi_328 = TRUE;
if (TradesITB >= MaxTrades_x_Bar) return(0);
if (MaxTrades==1) return (0);
if (MaxTrades==g_count_408+1) return (0);
}
else
{
err = GetLastError();
msg1= DoubleToStr(Bid,Digits);
Print("Error opening SELL order : (" + err + ") " + ErrorDescription(err) + " | at " + msg1);
}
}
}
if (l_irsi_76 < 60.0 && l_irsi_76 > 40.0) {
gi_332 = TRUE;
gi_328 = TRUE;
}
}
}
if (IsTradeTime() && gi_644 < gi_224 && gi_660 < ATR_Threshold && g_count_408 < MaxTrades && li_28) {
if (!ExistPosition2() && gi_80 == TRUE) {
if (TimeDayOfWeek(time) == 0 || TimeDayOfWeek(time) == 5 && TimeHour(time) >= 14) return (0);
if (TradesITB >= MaxTrades_x_Bar) return(0);
if (l_icci_116 <= -150.0 && l_icci_124 <= -120.0 || l_icci_108 <= -150.0 && l_icci_124 <= -120.0 && Bid <= gd_652 - gi_232 * gd_164) {
if (gi_456 < gi_404 && gi_336) {
g_price_564 = 0;
g_price_572 = 0;
if (gi_196) g_price_564 = g_ifractals_580;
g_price_572 = Ask - StopLoss * gd_164;
l_cmd_0=OrderSend(Symbol(), OP_SELL, g_lots_384, Ask, g_slippage_220, 0, 0, ExpertName + " 2", g_magic_244, 0, Green);
if (l_cmd_0>0)
{
waitIfBusy();
OrderModify(l_cmd_0, Ask, g_price_572, g_price_564, 0);
AlertIf ("BUY","S2");
gi_336 = FALSE;
gi_340 = TRUE;
if (TradesITB >= MaxTrades_x_Bar) return(0);
if (MaxTrades==1) return (0);
if (MaxTrades==g_count_408+1) return (0);
}
else
{
err = GetLastError();
msg1= DoubleToStr(Ask,Digits);
Print("Error opening BUY order : (" + err + ") " + ErrorDescription(err) + " | at " + msg1);
}
}
}
if (l_icci_116 >= 150.0 && l_icci_124 >= 120.0 || l_icci_108 >= 150.0 && l_icci_124 >= 120.0 && Ask >= gd_652 + gi_232 * gd_164) {
if (gi_436 < gi_404 && gi_340) {
g_price_564 = 0;
g_price_572 = 0;
if (gi_196) g_price_564 = g_ifractals_588;
g_price_572 = Bid + StopLoss * gd_164;
l_cmd_0=OrderSend(Symbol(), OP_BUY, g_lots_384, Bid, g_slippage_220, 0, 0, ExpertName + " 2", g_magic_244, 0, Red);
if (l_cmd_0>0)
{
waitIfBusy();
OrderModify(l_cmd_0, Bid, g_price_572, g_price_564, 0);
AlertIf ("SELL","S2");
gi_340 = FALSE;
gi_336 = TRUE;
if (TradesITB >= MaxTrades_x_Bar) return(0);
if (MaxTrades==1) return (0);
if (MaxTrades==g_count_408+1) return (0);
}
else
{
err = GetLastError();
msg1= DoubleToStr(Bid,Digits);
Print("Error opening SELL order : (" + err + ") " + ErrorDescription(err) + " | at " + msg1);
}
}
}
if (l_icci_108 < 50.0 && l_icci_108 > -50.0) {
gi_340 = TRUE;
gi_336 = TRUE;
}
}
if (!ExistPosition3() && gi_84 == TRUE) {
if (TimeDayOfWeek(time) == 0 || TimeDayOfWeek(time) == 5 && TimeHour(time) >= 14) return (0);
if (TradesITB >= MaxTrades_x_Bar) return(0);
if (l_imomentum_148 >= 99.85 && l_icci_132 <= -200.0 && Bid <= gd_652 - gi_232 * gd_164) {
if (gi_460 < gi_404 && gi_344) {
g_price_564 = 0;
g_price_572 = 0;
if (gi_196) g_price_564 = g_ifractals_580;
if (gi_200) g_price_572 = g_ifractals_588 - StopLoss * gd_164;
else g_price_572 = Ask - StopLoss * gd_164;
l_cmd_0=OrderSend(Symbol(), OP_SELL, g_lots_384, Ask, g_slippage_220, 0, 0, ExpertName + " 3", g_magic_248, 0, Green);
if (l_cmd_0>0)
{
waitIfBusy();
OrderModify(l_cmd_0, Ask, g_price_572, g_price_564, 0);
AlertIf ("BUY","S3");
gi_344 = FALSE;
gi_348 = TRUE;
if (TradesITB >= MaxTrades_x_Bar) return(0);
if (MaxTrades==1) return (0);
if (MaxTrades==g_count_408+1) return (0);
}
else
{
err = GetLastError();
msg1= DoubleToStr(Ask,Digits);
Print("Error opening BUY order : (" + err + ") " + ErrorDescription(err) + " | at " + msg1);
}
}
}
if (l_imomentum_148 <= 100.15 && l_icci_132 >= 200.0 && Ask >= gd_652 + gi_232 * gd_164) {
if (gi_440 < gi_404 && gi_348) {
g_price_564 = 0;
g_price_572 = 0;
if (gi_196) g_price_564 = g_ifractals_588;
if (gi_200) g_price_572 = g_ifractals_580 + StopLoss * gd_164;
else g_price_572 = Bid + StopLoss * gd_164;
l_cmd_0=OrderSend(Symbol(), OP_BUY, g_lots_384, Bid, g_slippage_220, 0, 0, ExpertName + " 3", g_magic_248, 0, Red);
if (l_cmd_0>0)
{
waitIfBusy();
OrderModify(l_cmd_0, Bid, g_price_572, g_price_564, 0);
AlertIf ("SELL","S3");
gi_348 = FALSE;
gi_344 = TRUE;
if (TradesITB >= MaxTrades_x_Bar) return(0);
if (MaxTrades==1) return (0);
if (MaxTrades==g_count_408+1) return (0);
}
else
{
err = GetLastError();
msg1= DoubleToStr(Bid,Digits);
Print("Error opening SELL order : (" + err + ") " + ErrorDescription(err) + " | at " + msg1);
}
}
}
if (l_icci_132 >= -50.0 && l_icci_132 <= 50.0) {
gi_348 = TRUE;
gi_344 = TRUE;
}
}
if (!ExistPosition4() && gi_88 == TRUE) {
if (TimeDayOfWeek(time) == 0 || TimeDayOfWeek(time) == 5 && TimeHour(time) >= 14) return (0);
if (TradesITB >= MaxTrades_x_Bar) return(0);
if (l_iwpr_172 <= -90.0 && l_ima_236 < l_ibands_212 && Ask <= gd_652 - gi_232 * gd_164) {
if (gi_464 < gi_404 && gi_352) {
g_price_564 = 0;
g_price_572 = 0;
if (gi_196) g_price_564 = g_ifractals_580;
if (gi_200) g_price_572 = Ask - gi_224 * gd_164;
else g_price_572 = Ask - StopLoss * gd_164;
l_cmd_0=OrderSend(Symbol(), OP_SELL, g_lots_384, Ask, g_slippage_220, 0, 0, ExpertName + " 4", g_magic_252, 0, Green);
if (l_cmd_0>0)
{
waitIfBusy();
OrderModify(l_cmd_0, Ask, g_price_572, g_price_564, 0);
AlertIf ("BUY","S4");
gi_352 = FALSE;
gi_356 = TRUE;
if (TradesITB >= MaxTrades_x_Bar) return(0);
if (MaxTrades==1) return (0);
if (MaxTrades==g_count_408+1) return (0);
}
else
{
err = GetLastError();
msg1= DoubleToStr(Ask,Digits);
Print("Error opening BUY order : (" + err + ") " + ErrorDescription(err) + " | at " + msg1);
}
}
}
if (l_iwpr_172 >= -10.0 && l_ima_220 > l_ibands_196 && Bid >= gd_652 + gi_232 * gd_164) {
if (gi_444 < gi_404 && gi_356) {
g_price_564 = 0;
g_price_572 = 0;
if (gi_196) g_price_564 = g_ifractals_588;
if (gi_200) g_price_572 = Bid + gi_224 * gd_164;
else g_price_572 = Bid + StopLoss * gd_164;
l_cmd_0=OrderSend(Symbol(), OP_BUY, g_lots_384, Bid, g_slippage_220, 0, 0, ExpertName + " 4", g_magic_252, 0, Red);
if (l_cmd_0>0)
{
waitIfBusy();
OrderModify(l_cmd_0, Bid, g_price_572, g_price_564, 0);
AlertIf ("SELL","S4");
gi_356 = FALSE;
gi_352 = TRUE;
if (TradesITB >= MaxTrades_x_Bar) return(0);
if (MaxTrades==1) return (0);
if (MaxTrades==g_count_408+1) return (0);
}
else
{
err = GetLastError();
msg1= DoubleToStr(Bid,Digits);
Print("Error opening SELL order : (" + err + ") " + ErrorDescription(err) + " | at " + msg1);
}
}
}
if (l_irsi_76 < 60.0 && l_irsi_76 > 40.0) {
gi_356 = TRUE;
gi_352 = TRUE;
}
}
}
return (0);
}

int IsTradeTime() {

if (minX==Minute()) return (TimeOK);
minX=Minute();
TimeH = GMT % (60*60*24);
OpenH = StrToTime(OpenHour) % (60*60*24);
CloseH = StrToTime(CloseHour) % (60*60*24);
if (OpenH < CloseH && (TimeH <= OpenH || TimeH >= CloseH)) TimeOK=false;
else if (OpenH > CloseH && (TimeH < OpenH && TimeH > CloseH)) TimeOK=false;
else TimeOK=true;

return (TimeOK);
}

bool ExistPosition1() {
bool li_ret_0 = FALSE;
for (int l_pos_4 = 0; l_pos_4 < OrdersTotal(); l_pos_4++) {
if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_240) {
if (OrderType() == OP_BUY || OrderType() == OP_SELL) {
li_ret_0 = TRUE;
break;
}
}
}
}
return (li_ret_0);
}

bool ExistPosition2() {
bool li_ret_0 = FALSE;
for (int l_pos_4 = 0; l_pos_4 < OrdersTotal(); l_pos_4++) {
if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_244) {
if (OrderType() == OP_BUY || OrderType() == OP_SELL) {
li_ret_0 = TRUE;
break;
}
}
}
}
return (li_ret_0);
}

bool ExistPosition3() {
bool li_ret_0 = FALSE;
for (int l_pos_4 = 0; l_pos_4 < OrdersTotal(); l_pos_4++) {
if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_248) {
if (OrderType() == OP_BUY || OrderType() == OP_SELL) {
li_ret_0 = TRUE;
break;
}
}
}
}
return (li_ret_0);
}

bool ExistPosition4() {
bool li_ret_0 = FALSE;
for (int l_pos_4 = 0; l_pos_4 < OrdersTotal(); l_pos_4++) {
if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_252) {
if (OrderType() == OP_BUY || OrderType() == OP_SELL) {
li_ret_0 = TRUE;
break;
}
}
}
}
return (li_ret_0);
}

void onScreenComment()
{
string Msg77="", Msg88="";
string l_dbl2str_4 = DoubleToStr(balanceDeviation(2), 2);
g_lots_384 = GetLots();
string DisplaySpread;
if (Digits == 5 || Digits == 3) DisplaySpread = DoubleToStr(NormalizeDouble(MarketInfo(Symbol(), MODE_SPREAD)*0.1,1),1);
else DisplaySpread = DoubleToStr(NormalizeDouble(MarketInfo(Symbol(), MODE_SPREAD),0),0);

string lsx;
if (TimeDayOfWeek(time) == 0) lsx = " OUT of SESSION (" + OpenHour + " - " + CloseHour + " GMT) Trade on Sunday NOT Allowed";
else if (TimeDayOfWeek(time) == 5 && TimeHour(time) >= 14) lsx = " OUT of SESSION (" + OpenHour + " - " + CloseHour + " GMT) Trade on Friday NOT Allowed";
else
{
if (IsTradeTime()==1)
{
lsx = " TRADE SESSION (" + OpenHour + " - " + CloseHour + " GMT)";
if (HighRange==true) Msg88="\n\n RANGE FILTER is ON. Range is > " + DoubleToStr(Max_Range,1) + " pips. Trade do not allowed.";
}
else lsx = " OUT of SESSION (" + OpenHour + " - " + CloseHour + " GMT)";
}
ObjectSetText("Session", lsx, 9, "Arial", Silver);
if (Use_Manual_GMTOffset==true) Msg77=" (manual)";
else Msg77=" (automatic)";

string ls_108 = "\n DragonPips Ultimate v2.02 \n"
+ "-----------------------------------------------------------------------"
+ "\n"
+ " GMT Time : " + TimeToStr(GMT,TIME_MINUTES)
+ "\n"
+ " Server Time : " + TimeToStr(TimeCurrent(), TIME_MINUTES)
+ "\n"
+ " GMT Offset : " + DoubleToStr(GMTOffset,0) + Msg77
+ "\n"
+ "-----------------------------------------------------------------------"
+ "\n"
+ " Account Type : " + AccountServer()
+ "\n\n"
+ " MaxTrades : " + DoubleToStr(MaxTrades,0)
+ "\n"
+ " MaxTrades_x_Bar : " + DoubleToStr(MaxTrades_x_Bar,0)
+ "\n\n"
+ " Trades Opened : " + DoubleToStr(g_count_408,0)
+ "\n\n"
+ " Drawdown : " + l_dbl2str_4
+ "%\n\n\n Range (" + DoubleToStr(Range_PreviousBars,0) + " bars): " + DoubleToStr(Rx,1) + " pips"
+ "\n\n\n--------------------------------\n LOTS: " + DoubleToStr(g_lots_384, 2)
+ "\n--------------------------------\n SPREAD: " + DisplaySpread + " pips\n--------------------------------\n" + Msg88;

Comment(ls_108);

return;

}

bool CloseAll()
{
int l_cmd_0;
bool l_ord_close_4;

for (g_pos_400 = OrdersTotal() - 1; g_pos_400 >= 0; g_pos_400--)
{
OrderSelect(g_pos_400, SELECT_BY_POS);
if (OrderSymbol()!=Symbol()) continue;
if (OrderMagicNumber() != g_magic_240 && OrderMagicNumber() != g_magic_244 && OrderMagicNumber() != g_magic_248 && OrderMagicNumber() != g_magic_252) continue;
l_cmd_0 = OrderType();
l_ord_close_4 = FALSE;
waitIfBusy();
switch (l_cmd_0)
{
case OP_BUY:
l_ord_close_4 = OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), g_slippage_220, Pink);
break;
case OP_SELL:
l_ord_close_4 = OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), g_slippage_220, Pink);
}
if (l_ord_close_4 == 0) Sleep(3000);
}
if (SoundAlert) PlaySound(SoundFileAtClose);
}

double balanceDeviation(int ai_0) {
double ld_ret_4;
if (ai_0 == 2) {
ld_ret_4 = (AccountEquity() / AccountBalance() - 1.0) / (-0.01);
if (ld_ret_4 > 0.0) return (ld_ret_4);
return (0);
}
if (ai_0 == 1) {
ld_ret_4 = 100.0 * (AccountEquity() / AccountBalance() - 1.0);
if (ld_ret_4 > 0.0) return (ld_ret_4);
return (0);
}
return (0.0);
}

bool ScanRange()
{
double Hx = High[iHighest(NULL, 0, 2, Range_PreviousBars, 1)];
double Lx = Low[iLowest(NULL, 0, 1, Range_PreviousBars, 1)];
Rx = (Hx-Lx)/gd_164;
if (Rx >= Max_Range) HighRange=true;
else HighRange=false;
//Print("Range for previous " + DoubleToStr(Range_PreviousBars,0) + " bars is: " + DoubleToStr(Rx,1) + " pips.");
return (HighRange);
}

bool errClose(int otx)
{
err = GetLastError();
Print("Error Closing order #[" + DoubleToStr(otx,0) + "] : (" + err + ") " + ErrorDescription(err));
}

int waitIfBusy()
{
for (int Yx = 0; IsTradeContextBusy() && Yx < 50; Yx++) Sleep(125);
if (Yx >= 50) Print("Trade context is busy more than ", DoubleToStr(25 * Yx / 1000, 2), " seconds");
else if (Yx > 0) Print("Trade context was busy ", DoubleToStr(25 * Yx / 1000, 2), " seconds");
return (Yx);
}

string WaitW(int rtw)
{
int lhj = MathMod(rtw, 5);
return (ddx[lhj]);
}

bool AlertIf (string txx, string txy)
{
TradesITB++;
if (MessageAlert) Alert ("DragonPips - " + txx + " order opened. [" + txy + "]");
else
{
if (SoundAlert) PlaySound(SoundFileAtOpen);
Print (txx + " order opened. [" + txy + "]");
}
}

int Atenea()
{
if (IsTesting())
{
GMTOffset = GMTOffset_for_Backtests;
Print ("GMTOffset for Backtests: " + DoubleToStr(GMTOffset,0));
}
else
{
if (Use_Manual_GMTOffset==true)
{
GMTOffset = Manual_GMTOffset;
GMT = TimeCurrent() - (GMTOffset * 3600);
Print ("MANUAL GMTOffset: " + DoubleToStr(GMTOffset,0));
}
else
{
GMTOffset = GetGmtOffset();
Print ("AUTO GMTOffset: " + DoubleToStr(GMTOffset,0));
}
}
}

double GetGmtOffset()
{
return(TimeZoneServer());
}

double TimeZoneServer()
{
int li_0 = (TimeCurrent() - TimeLocal()) / 60;
int li_4 = MathRound(li_0 / 30.0);
li_0 = 30 * li_4;
double CurBrokerGMTOffset = TimeZoneLocal() + li_0 / 60.0;
return (CurBrokerGMTOffset);
}

double TimeZoneLocal()
{
int temp[43];
switch (GetTimeZoneInformation(temp))
{
case 0: return (temp[0] / (-60.0));
case 1: return (temp[0] / (-60.0));
case 2: return ((temp[0] + temp[42]) / (-60.0));
}
return (0);
}

 

double GetLots()
{
double lot;

if (MoneyManagement)
{
lot = LotsOptimized();
}
else
{
lot = Lots;
}

if (lot < iMinLot) lot = iMinLot;
if (lot > MaxLots) lot = MaxLots;

return(lot);
}

double LotsOptimized()
{
double lot=Lots;

//---- select lot size

if (MM_Mode==1) // Free Margin
{
lot=NormalizeDouble((AccountFreeMargin()*TradeSizePercent/10000)/10,DigitsLots);
}
else if (MM_Mode==2) // Equity
{
lot=NormalizeDouble((AccountEquity()*TradeSizePercent/10000)/10,DigitsLots);
}
else if (MM_Mode==3) // Balance
{
lot=NormalizeDouble((AccountBalance()*TradeSizePercent/10000)/10,DigitsLots);
}

return(lot);
}

相关资源

暂无评论

暂无评论...