Skip to content

Instantly share code, notes, and snippets.

@APPEA
Last active December 17, 2019 13:20
Show Gist options
  • Save APPEA/07d8d255231f62df0388 to your computer and use it in GitHub Desktop.
Save APPEA/07d8d255231f62df0388 to your computer and use it in GitHub Desktop.
神鬼戰士
//+------------------------------------------------------------------+
//| ProjectName |
//| Copyright 2012, CompanyName |
//| http://www.companyname.net |
//+------------------------------------------------------------------+
#property strict
#include <WarGameDLL.mqh>
#include <WinUser32.mqh>
#import "stdlib.ex4"
string ErrorDescription(int error_code);
#import "User32.dll"
int GetDC(int);
int ReleaseDC(int,int);
#import "Gdi32.dll"
int GetDeviceCaps(int,int);
#import "shell32.dll"
int ShellExecuteW(int hWnd, string lpVerb, string lpFile, string lpParameters, string lpDirectory, int nCmdShow);
#import "kernel32.dll"
ulong GetVersion(void);
#import "wininet.dll"
int InternetOpenUrlW(int hInternetSession,string sUrl,string sHeaders="",int lHeadersLength=0,uint lFlags=0,int lContext=0);
int InternetReadFile(int hFile,uchar &sBuffer[],int lNumBytesToRead,int& lNumberOfBytesRead[]);
int InternetCloseHandle(int hInet);
int InternetOpenW(string sAgent,int lAccessType,string sProxyName="",string sProxyBypass="",int lFlags=0);
#import
//#define MODE_MOON_AREA51 1
#define MODE_AREA51 1
//#define MODE_DEMO 1
#define MAX 128
#define MODE_NEWS 0
#define MODE_CSV 1
#define MODE_ENERGY 2
#define MODE_VLINE 3
#define OP_ALL 101
#define EA_VERSION "5.0"
#define BUFFER_LEN 1024
#define INTERNET_FLAG_PRAGMA_NOCACHE 0x00000100 // Forces the request to be resolved by the origin server, even if a cached copy exists on the proxy.
#define INTERNET_FLAG_NO_CACHE_WRITE 0x04000000 // Does not add the returned entity to the cache.
#define INTERNET_FLAG_RELOAD 0x80000000 // Forces a download of the requested file, object, or directory listing from the origin server, not from the cache.
#ifdef MODE_AREA51
#ifdef MODE_MOON_AREA51
enum enum_Mode
{
Mode0 = MODE_NEWS, //新聞模式
Mode1 = MODE_CSV, //排程模式
Mode2 = MODE_ENERGY, //能量模式
Mode3 = MODE_VLINE //垂直線模式
};
#else
enum enum_Mode
{
Mode0 = MODE_NEWS, //新聞模式
Mode1 = MODE_CSV, //排程模式
Mode3 = MODE_VLINE //垂直線模式
};
#endif
#else
enum enum_Mode
{
Mode0 = MODE_NEWS, //新聞模式
Mode1 = MODE_CSV //排程模式
};
#endif
extern string TEXT0 = "------------------------"; //--------------------------------------------------------------
extern enum_Mode Mode = Mode1; //神鬼情資選擇
#ifdef MODE_MOON_AREA51
extern string TEXT1 = "------------------------"; //--------------------------------------------------------------
extern double Energy=4; //能量偵測靈敏度
extern int SleepTime=1; //能量引擎啟動時間(分鐘)
#endif
extern string TEXT2 = "------------------------"; //--------------------------------------------------------------
extern int BeforeEvent = 30; //新聞幾秒前開始監控
extern int AbortTime = 20; //新聞後幾秒取消
extern double SpreadIn = 10; //點差擴大幾點延長取消(點數)
extern int MoreTime = 10; //點差擴大時延長取消(秒數)
extern string TEXT3 = "------------------------"; //--------------------------------------------------------------
extern double Range=15; //距離現價上下幾點進單
extern double SpreadNotIn = 10; //點差保護裝置
extern double TrailStop=10.0; //追蹤止損點數(0:關閉)
extern int Orders = 1; //單邊攻擊次數
extern double Wide = 3; //單邊攻擊間距
extern string TEXT4 = "------------------------"; //--------------------------------------------------------------
extern double Lot=0.1; //固定手數
extern bool MM=false; //資金管理功能
extern double SLP=2; //資金管理功能停損%數
extern double TakeProfit=10; //獲利點數
extern double StopLoss=20; //停損點數
extern bool TimeCloseSW = true; //獲利保護
extern int TimeClose = 10; //獲利保護秒數
extern double TCpips = 20; //獲利保護失效點數
double point;
double GetinArr[5];
double start_balance;
double FontDPI=96;
double BuyCloseData[MAX][2] = {0};
double SellCloseData[MAX][2] = {0};
int Otime;
int id_1 = 555556;
int bar_s,bar_b,bars,bar2,bar3,bar4,start_p,first_in,news_p,count,Pos=50;
int hourr=0;
int minutee;
bool BuyOrderSW = true;
bool SellOrderSW = true;
bool BrakeSW = true;
datetime Open_O_Time = 0;
datetime LaunchTime[1] = {0};
datetime AfterBrake = 0;
datetime TimeNow = 0;
int TiB = 0;
int TiS = 0;
int TiB_Brake = 0;
int TiS_Brake = 0;
int Position=0;
int Status[1]={0};
int Last_Time[1]={0};
int SleepStop[1]={0};
double Last_Price[1]={-1.0};
double MinPriceShot;
#ifdef MODE_AREA51
string buttonID[6] = {"Button0", "Button1", "Button2", "Button3", "Button4" ,"Button5"};
string Text[6] = {"部隊編制(F7)", "戰鬥排程", "離開戰場", "水雷掃除部隊","增加垂直線", "刪除垂直線"};
#else
string buttonID[4] = {"Button0", "Button1", "Button2", "Button3"};
string Text[4] = {"部隊編制(F7)", "戰鬥排程", "離開戰場", "水雷掃除部隊"};
#endif
struct systemtime
{
ushort wYear;
ushort wMonth;
ushort wDayOfWeek;
ushort wDay;
ushort wHour;
ushort wMinute;
ushort wSecond;
ushort wMilliseconds;
};
int A = 0;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OnInit()
{
ulong dwVersion = GetVersion();
uint dwMajorVersion = (uchar)(((ushort)(dwVersion & 0xffff)) & 0xff);
printf("Major Version Of OS: %d",dwMajorVersion);
if (dwMajorVersion < 6)
{
Alert("請注意!使用Windows XP(Server 2003)之系統將無法保證交易能正常執行!");
}
// CheckNewVersion("Gladiator",EA_VERSION);
CheckServerLocalTime();
InitAllVar();
if (Orders >= 5)
{
Alert("單邊攻擊次數過高");
return(-99);
}
int dc=GetDC(0);
FontDPI=GetDeviceCaps(dc,88);
if (FontDPI==0) FontDPI=96;
ReleaseDC(0,dc);
//+------------------------------------------------------------------+
if (Digits==5 || Digits==3)
{
point=Point*10;
}
else
{
point=Point;
}
#ifdef MODE_MOON_AREA51
if (Mode == MODE_ENERGY)
{
id_1 = 555558;
if (Energy < 4) Energy = 4;
MinPriceShot=Energy;
}
#endif
int i = 0;
string sBuffer = "";
string EventFile = "";
int h1 = 0;
if (Mode == MODE_VLINE)
{
id_1 = 555559;
}
if (Mode == MODE_CSV)
{
id_1 = 555560;
string SymbolCut = StringSubstr(Symbol(),0,6);
sBuffer = "";
EventFile = "Event.csv";
i = 0;
h1 = FileOpen(EventFile,FILE_SHARE_READ|FILE_CSV);
while(!FileIsEnding(h1))
{
sBuffer = FileReadString(h1);
if (StringFind(sBuffer,SymbolCut) >= 0)
{
ArrayResize(LaunchTime,i+2);
sBuffer = FileReadString(h1);
LaunchTime[i+1] = StrToTime(sBuffer);
i++;
}
}
FileClose(h1);
}
if (Mode == MODE_NEWS)
{
id_1 = 555561;
//NewGet();
sBuffer = "";
EventFile = "NewsEvent.csv";
i = 0;
h1 = FileOpen(EventFile,FILE_SHARE_READ|FILE_CSV);
while(!FileIsEnding(h1))
{
sBuffer = FileReadString(h1);
if (StringFind(Symbol(),sBuffer) >= 0)
{
ArrayResize(LaunchTime,i+2);
sBuffer = FileReadString(h1);
LaunchTime[i+1] = StrToTime(sBuffer);
i++;
}
}
FileClose(h1);
}
Otime=0;
EventSetMillisecondTimer(1000);
//+------------------------------------------------------------------+
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//----
EventKillTimer();
//Delete Button
string obj_str = "";
int obj_total = 0;
obj_total = ObjectsTotal();
for (int i=obj_total;i>=0;i--)
{
obj_str = ObjectName(i);
if (ObjectType(obj_str) == OBJ_BUTTON)
{
ObjectDelete(0,obj_str);
}
if (ObjectType(obj_str) == OBJ_LABEL)
{
if (StringFind(obj_str,"Sch",0) >= 0)
ObjectDelete(0,obj_str);
}
}
//ObjectsDeleteAll();
if (reason == 5)
{
ArrayInitialize(BuyCloseData,0);
ArrayInitialize(SellCloseData,0);
}
ObjectDelete("LOGO");
ObjectDelete("LOGO0");
ObjectDelete("NAME");
ObjectDelete("MSG0");
ObjectDelete("MSG0.0");
ObjectDelete("MSG1");
ObjectDelete("MSG1.1");
ObjectDelete("MSG2");
ObjectDelete("MSG2.1");
ObjectDelete("MSG3");
ObjectDelete("MSG3.1");
ObjectDelete("tete");
ObjectDelete("percent");
ObjectDelete("takepercent_day");
ObjectDelete("Newsinfo");
ObjectDelete("Newsinfo2");
ObjectDelete("Expert");
ObjectDelete("ERR");
ObjectDelete("ERR2");
ObjectDelete(DoubleToStr(GetinArr[0],0)+"H");
ObjectDelete(DoubleToStr(GetinArr[0],0)+"L");
ObjectDelete(DoubleToStr(GetinArr[0],0)+"Hin");
ObjectDelete(DoubleToStr(GetinArr[0],0)+"Lin");
ObjectDelete("CntDText");
GlobalVariableSet("DNSW",0);
ObjectDelete("Light");
ObjectDelete("Light2");
ObjectDelete("lightstatus");
//----
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTimer()
{
if (GlobalVariableGet("RUNEA")==1) //EA控制器
{
Alert("EA is not working");
return;
}
//+------------------------------------------------Author End----------------------------------------------------------------------------+
datetime iAbortTime = 0;
F_SpreadIn(iAbortTime);
int i = 0;
int j = 0;
if (Mode == MODE_VLINE)
{
//VLINE Use Server time
TimeNow = TimeCurrent();
ArrayResize(LaunchTime,1);
ArrayInitialize(LaunchTime,0);
for (i=0;i<ObjectsTotal();i++)
{
if (StringFind(ObjectName(i),"GL") >= 0 && ObjectType(ObjectName(i)) == OBJ_VLINE)
{
ArrayResize(LaunchTime,j+2);
LaunchTime[j+1] = (datetime)ObjectGetInteger(0,ObjectName(i),OBJPROP_TIME,0);
j++;
}
}
ArraySort(LaunchTime,WHOLE_ARRAY,0,MODE_ASCEND);
}
if (Mode == MODE_CSV || Mode == MODE_NEWS)
{
//CSV use Local time
TimeNow = TimeLocal();
}
if ((ArraySize(LaunchTime) == 1 && LaunchTime[0] == 0) || ArraySize(LaunchTime) == 0) Open_O_Time = 0;
//+------------------------------------------------Money Manager-------------------------------------------------------------------------+
//int i=0,j=0,
//datetime TimeNow = TimeLocal();
int q=0;
if (MM)
{
Lot=AccountBalance()*SLP*0.01/(StopLoss*10);
Lot=NormalizeDouble(Lot,2);
}
if (TrailStop!=0.0)
{
int BuyTrailCnt=0;
int SellTrailCnt=0;
if (MyOrderTotal(OP_SELL)>0)
{
for (i=0;i<OrdersTotal();i++)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if (OrderType()==OP_SELL && OrderMagicNumber()==id_1 && OrderSymbol()==Symbol())
{
RefreshRates();
if (Ask+TrailStop*point<=OrderOpenPrice())
{
if (SearchArray(SellCloseData,OrderTicket()) == -1)
{
SellCloseData[SellTrailCnt][0] = OrderTicket();
SellCloseData[SellTrailCnt][1] = Ask + TrailStop * point;
SellTrailCnt++;
continue;
}
if (Ask+TrailStop*point<SellCloseData[SearchArray(SellCloseData,OrderTicket())][1])
{
SellCloseData[SearchArray(SellCloseData,OrderTicket())][0] = OrderTicket();
SellCloseData[SearchArray(SellCloseData,OrderTicket())][1] = Ask + TrailStop * point;
}
}
}
}
}
else
{
ArrayInitialize(SellCloseData,0);
}
for (i=0;i<MAX;i++)
{
if (!OrderSelect((int)SellCloseData[i][0],SELECT_BY_TICKET,MODE_TRADES))
{
SellCloseData[i][0] = 0;
SellCloseData[i][1] = 0;
continue;
}
RefreshRates();
if (ObjectFind(DoubleToStr(SellCloseData[i][0],0))<0)
ObjectCreate(DoubleToStr(SellCloseData[i][0],0),OBJ_HLINE,0,Time[0],SellCloseData[i][1],0,0);
//ObjectMove(DoubleToStr(SellCloseData[i][0],0),1,Time[0],SellCloseData[i][1]);
ObjectSetDouble(0,DoubleToStr(SellCloseData[i][0],0),OBJPROP_PRICE,SellCloseData[i][1]);
if (Ask>=SellCloseData[i][1])
{
if (!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),20,Gold))
{
Alert(ErrorDescription(GetLastError()));
}
}
}
if (MyOrderTotal(OP_BUY)>0)
{
for (i=0;i<OrdersTotal();i++)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if (OrderType()==OP_BUY && OrderMagicNumber()==id_1 && OrderSymbol()==Symbol())
{
RefreshRates();
if (Bid-TrailStop*point>=OrderOpenPrice())
{
if (SearchArray(BuyCloseData,OrderTicket()) == -1)
{
BuyCloseData[BuyTrailCnt][0] = OrderTicket();
BuyCloseData[BuyTrailCnt][1] = Bid - TrailStop * point;
BuyTrailCnt++;
Print("A");
continue;
}
if (Bid-TrailStop*point>BuyCloseData[SearchArray(BuyCloseData,OrderTicket())][1])
{
BuyCloseData[SearchArray(BuyCloseData,OrderTicket())][0] = OrderTicket();
BuyCloseData[SearchArray(BuyCloseData,OrderTicket())][1] = Bid - TrailStop * point;
}
}
}
}
}
else
{
ArrayInitialize(BuyCloseData,0);
}
for (i=0;i<MAX;i++)
{
if (!OrderSelect((int)BuyCloseData[i][0],SELECT_BY_TICKET,MODE_TRADES))
{
BuyCloseData[i][0] = 0;
BuyCloseData[i][1] = 0;
continue;
}
RefreshRates();
if (ObjectFind(DoubleToStr(BuyCloseData[i][0],0))<0)
ObjectCreate(DoubleToStr(BuyCloseData[i][0],0),OBJ_HLINE,0,Time[0],BuyCloseData[i][1],0,0);
ObjectSetDouble(0,DoubleToStr(BuyCloseData[i][0],0),OBJPROP_PRICE,BuyCloseData[i][1]);
if (Bid<=BuyCloseData[i][1])
{
if (!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),20,Gold))
{
Alert(ErrorDescription(GetLastError()));
}
}
}
}
for (j=0;j<ArraySize(LaunchTime)-1;j++)
{
if (TimeNow > LaunchTime[j] && TimeNow <= LaunchTime[j] + iAbortTime)
{
Open_O_Time = LaunchTime[j];
}
if (TimeNow > LaunchTime[j] + iAbortTime && TimeNow < LaunchTime[j+1])
{
if (Open_O_Time != LaunchTime[j+1])
{
BuyOrderSW = true;
SellOrderSW = true;
}
Open_O_Time = LaunchTime[j+1];
break;
}
}
if (Mode == MODE_ENERGY)
{
string Active="煞車系統啟動中";
string Deactive="煞車系統待命中";
color Light_status=Gold;
double Position_L=Bid+Position*point;
if (ObjectFind("Light") == -1) ObjectCreate("Light",OBJ_ARROW,0,0,0);
ObjectSet("Light",OBJPROP_ARROWCODE,108);
ObjectSet("Light", OBJPROP_CORNER, 1);
ObjectSet("Light", OBJPROP_COLOR, Lime);
ObjectSet("Light",OBJPROP_WIDTH,5);
if (ObjectFind("Light2") == -1) ObjectCreate("Light2",OBJ_ARROW,0,0,0);
ObjectSet("Light2",OBJPROP_ARROWCODE,161);
ObjectSet("Light2", OBJPROP_CORNER, 1);
ObjectSet("Light2", OBJPROP_COLOR, LawnGreen);
ObjectSet("Light2",OBJPROP_WIDTH,5);
if (ObjectFind("lightstatus") == -1)ObjectCreate("lightstatus",OBJ_LABEL,0,0,0);
ObjectSet("lightstatus", OBJPROP_CORNER, 1);
ObjectSet("lightstatus", OBJPROP_COLOR, Gold);
ObjectSet("lightstatus", OBJPROP_XDISTANCE, 20);
ObjectSet("lightstatus", OBJPROP_YDISTANCE, Pos+155);
ObjectSet("Light",OBJPROP_TIME1,TimeCurrent()+300);
ObjectSet("Light",OBJPROP_PRICE1,Position_L);
ObjectSet("Light2",OBJPROP_TIME1,TimeCurrent()+300);
ObjectSet("Light2",OBJPROP_PRICE1,Position_L);
#ifdef MODE_MOON_AREA51
int EnergyBall = Ball(Status,SleepStop,Last_Time,Last_Price,SleepTime,(int)TimeCurrent(),point,MinPriceShot,Close[0]);
if (EnergyBall < 0) {
Print("Energy Brake Error");
return;
}
#endif
if (TimeCurrent() <= SleepStop[0])
{
//SEND BUY
SendBuy();
//SEND SELL
SendSell();
if (BrakeSW)
{
AfterBrake = TimeCurrent();
BrakeSW = false;
}
if (TimeCurrent() >= AfterBrake + iAbortTime && !BrakeSW)
{
iCloseOrders(OP_SELLSTOP);
iCloseOrders(OP_BUYSTOP);
Status[0]=0;
Last_Time[0]=0;
SleepStop[0]=0;
Last_Price[0]=-1.0;
}
/*if (BrakeSW)
{
AfterBrake = TimeCurrent();
BrakeSW = false;
}
if (TimeCurrent() >= AfterBrake + AbortTime && !BrakeSW)
{
iCloseOrders(OP_SELLSTOP);
iCloseOrders(OP_BUYSTOP);
SleepStop[0]
}*/
ObjectSet("Light", OBJPROP_COLOR, Red);
ObjectSet("Light2", OBJPROP_COLOR, Crimson);
ObjectSetText("lightstatus", Active+", "+DoubleToStr((SleepStop[0]-TimeCurrent()),0)+" 秒後返回",10,"微軟正黑體", Light_status);
}else {
BrakeSW = true;
BuyOrderSW = true;
SellOrderSW = true;
if (MyOrderTotal(OP_SELLSTOP) > 0) iCloseOrders(OP_SELLSTOP);
if (MyOrderTotal(OP_BUYSTOP) > 0) iCloseOrders(OP_BUYSTOP);
ObjectSet("Light",OBJPROP_COLOR, Lime);
ObjectSet("Light2", OBJPROP_COLOR, LawnGreen);
ObjectSetText("lightstatus", Deactive,10,"微軟正黑體", Light_status);
}
}else {
//if (MyOrderTotal(OP_SELLSTOP) > 0) iCloseOrders(OP_SELLSTOP);
//if (MyOrderTotal(OP_BUYSTOP) > 0) iCloseOrders(OP_BUYSTOP);
ObjectDelete("Light");
ObjectDelete("Light2");
ObjectDelete("lightstatus");
}
if (TimeNow > Open_O_Time + iAbortTime) Open_O_Time = 0;
if (TimeNow >= Open_O_Time - BeforeEvent && TimeNow < Open_O_Time + iAbortTime)
{
if (Mode != MODE_ENERGY)
{
//SEND BUY
SendBuy();
//SEND SELL
SendSell();
}
}
Set_sl_tp(OP_BUY,TakeProfit,StopLoss);
Set_sl_tp(OP_SELL,TakeProfit,StopLoss);
if (MyOrderTotal(OP_SELLSTOP) > 0 && MyOrderTotal(OP_BUY) > 0) iCloseOrders(OP_SELLSTOP);
if (MyOrderTotal(OP_BUYSTOP) > 0 && MyOrderTotal(OP_SELL) > 0) iCloseOrders(OP_BUYSTOP);
//if (MyOrderTotal(OP_BUYSTOP) > 0 && MathAbs(Bid - Ask)/point >= SpreadNotIn) iCloseOrders(OP_BUYSTOP);
//if (MyOrderTotal(OP_SELLSTOP) > 0 && MathAbs(Bid - Ask)/point >= SpreadNotIn) iCloseOrders(OP_SELLSTOP);
//if (CheckDelete)
//{
for (i=OrdersTotal()-1;i>=0;i--)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == id_1 && (OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP))
{
if (StringFind(OrderComment(),TimeToString(Open_O_Time,TIME_DATE|TIME_MINUTES)) < 0)
{
if (!OrderDelete(OrderTicket(),clrWhite))
{
Alert("#"+IntegerToString(OrderTicket()) + "Order Delete Error");
}
}
}
}
//}
ShowMSG();
if (Mode == MODE_CSV || Mode == MODE_NEWS)
ShowSch();
SetButtonNTEXT();
SetButtonSize();
if (TimeCloseSW) TC();
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double NormPoint(double inF)
{
return(inF * point);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void ShowMSG()
{
double Scale = StrToDouble(DoubleToStr(FontDPI/96,2));
int Start = 55;
Start = (int)(Start * Scale);
int Y = 20;
Y = (int)(Y * Scale);
if (ObjectFind("LOGO")==-1)
{
ObjectCreate(0,"LOGO",OBJ_BITMAP_LABEL,0,0,0);
}
ObjectSetString(0,"LOGO",OBJPROP_BMPFILE,"\\Images\\Helmet.bmp");
ObjectSetInteger(0,"LOGO",OBJPROP_CORNER,0);
ObjectSetInteger(0,"LOGO",OBJPROP_XDISTANCE,8);
ObjectSetInteger(0,"LOGO",OBJPROP_YDISTANCE,15);
ObjectSetInteger(0,"LOGO",OBJPROP_ANCHOR,ANCHOR_LEFT_UPPER);
if (ObjectFind("LOGO0")==-1)
{
ObjectCreate("LOGO0",OBJ_LABEL,0,0,0);
}
ObjectSet("LOGO0",OBJPROP_CORNER,0);
ObjectSet("LOGO0",OBJPROP_XDISTANCE,73*Scale);
ObjectSet("LOGO0",OBJPROP_YDISTANCE,10*Scale);
ObjectSetText("LOGO0","神鬼戰士",30,"標楷體",White);
if (ObjectFind("NAME")==-1)
{
ObjectCreate("NAME",OBJ_LABEL,0,0,0);
}
ObjectSet("NAME",OBJPROP_CORNER,0);
ObjectSet("NAME",OBJPROP_XDISTANCE,73*Scale);
ObjectSet("NAME",OBJPROP_YDISTANCE,50*Scale+Y*0);
ObjectSetText("NAME"," All New Gladiator",16,"Impact",GreenYellow);
if (ObjectFind("MSG0")==-1)
{
ObjectCreate("MSG0",OBJ_LABEL,0,0,0);
}
ObjectSet("MSG0",OBJPROP_CORNER,0);
ObjectSet("MSG0",OBJPROP_XDISTANCE,10*Scale);
ObjectSet("MSG0",OBJPROP_YDISTANCE,Start+Y*1);
ObjectSetText("MSG0","Launch Time: ",14,"Impact",CornflowerBlue);
if (ObjectFind("MSG0.0")==-1)
{
ObjectCreate("MSG0.0",OBJ_LABEL,0,0,0);
}
ObjectSet("MSG0.0",OBJPROP_CORNER,0);
ObjectSet("MSG0.0",OBJPROP_XDISTANCE,120*Scale);
ObjectSet("MSG0.0",OBJPROP_YDISTANCE,Start+Y*1);
ObjectSetText("MSG0.0",TimeToString(Open_O_Time,TIME_DATE|TIME_MINUTES|TIME_SECONDS),14,"Impact",Gold);
if (ObjectFind("MSG1")==-1)
{
ObjectCreate("MSG1",OBJ_LABEL,0,0,0);
}
ObjectSet("MSG1",OBJPROP_CORNER,0);
ObjectSet("MSG1",OBJPROP_XDISTANCE,10*Scale);
ObjectSet("MSG1",OBJPROP_YDISTANCE,Start+Y*3);
ObjectSetText("MSG1","Local Time: ",14,"Impact",CornflowerBlue);
if (ObjectFind("MSG1.1")==-1)
{
ObjectCreate("MSG1.1",OBJ_LABEL,0,0,0);
}
ObjectSet("MSG1.1",OBJPROP_CORNER,0);
ObjectSet("MSG1.1",OBJPROP_XDISTANCE,120*Scale);
ObjectSet("MSG1.1",OBJPROP_YDISTANCE,Start+Y*3);
ObjectSetText("MSG1.1",TimeToString(TimeLocal(),TIME_DATE|TIME_MINUTES|TIME_SECONDS),14,"Impact",Gold);
if (ObjectFind("MSG3")==-1)
{
ObjectCreate("MSG3",OBJ_LABEL,0,0,0);
}
ObjectSet("MSG3",OBJPROP_CORNER,0);
ObjectSet("MSG3",OBJPROP_XDISTANCE,10*Scale);
ObjectSet("MSG3",OBJPROP_YDISTANCE,Start+Y*2);
ObjectSetText("MSG3","Server Time: ",14,"Impact",CornflowerBlue);
if (ObjectFind("MSG3.1")==-1)
{
ObjectCreate("MSG3.1",OBJ_LABEL,0,0,0);
}
ObjectSet("MSG3.1",OBJPROP_CORNER,0);
ObjectSet("MSG3.1",OBJPROP_XDISTANCE,120*Scale);
ObjectSet("MSG3.1",OBJPROP_YDISTANCE,Start+Y*2);
ObjectSetText("MSG3.1",TimeToString(TimeCurrent(),TIME_DATE|TIME_MINUTES|TIME_SECONDS),14,"Impact",Gold);
if (ObjectFind("MSG2")==-1)
{
ObjectCreate("MSG2",OBJ_LABEL,0,0,0);
}
ObjectSet("MSG2",OBJPROP_CORNER,0);
ObjectSet("MSG2",OBJPROP_XDISTANCE,10*Scale);
ObjectSet("MSG2",OBJPROP_YDISTANCE,Start+Y*4);
ObjectSetText("MSG2","MODE: ",14,"Impact",CornflowerBlue);
if (ObjectFind("MSG2.1")==-1)
{
ObjectCreate("MSG2.1",OBJ_LABEL,0,0,0);
}
ObjectSet("MSG2.1",OBJPROP_CORNER,0);
ObjectSet("MSG2.1",OBJPROP_XDISTANCE,120*Scale);
ObjectSet("MSG2.1",OBJPROP_YDISTANCE,Start+Y*4);
ObjectSetText("MSG2.1",ModeText(),14,"Impact",Gold);
}
void ShowSch()
{
int Scale = (int)(FontDPI/96);
int Start = 50;
Start = (int)(Start * Scale);
int Y = 20;
Y = (int)(Y * Scale);
int cnt = 1;
for(int i=1;i<ArraySize(LaunchTime);i++)
{
string name_0 = "Sch0_" + IntegerToString(i);
string name_1 = "Sch1_" + IntegerToString(i);
if (TimeLocal() > LaunchTime[i])
{
if (ObjectFind(name_0) >= 0) ObjectDelete(name_0);
if (ObjectFind(name_1) >= 0) ObjectDelete(name_1);
continue;
}
int pos = 3 - cnt;
if (ObjectFind(name_0) < 0) ObjectCreate(0,name_0,OBJ_LABEL,0,0,0);
ObjectSetInteger(0,name_0,OBJPROP_CORNER,2);
ObjectSetInteger(0,name_0,OBJPROP_XDISTANCE,10*Scale);
ObjectSetInteger(0,name_0,OBJPROP_YDISTANCE,Start+Y*pos);
ObjectSetInteger(0,name_0,OBJPROP_ANCHOR,ANCHOR_LEFT_LOWER);
ObjectSetString(0,name_0,OBJPROP_TEXT,IntegerToString(cnt) + ":");
ObjectSetString(0,name_0,OBJPROP_FONT,"Impact");
ObjectSetInteger(0,name_0,OBJPROP_FONTSIZE,14);
ObjectSetInteger(0,name_0,OBJPROP_COLOR,CornflowerBlue);
if (ObjectFind(name_1) < 0) ObjectCreate(0,name_1,OBJ_LABEL,0,0,0);
ObjectSetInteger(0,name_1,OBJPROP_CORNER,2);
ObjectSetInteger(0,name_1,OBJPROP_XDISTANCE,30*Scale);
ObjectSetInteger(0,name_1,OBJPROP_YDISTANCE,Start+Y*pos);
ObjectSetInteger(0,name_1,OBJPROP_ANCHOR,ANCHOR_LEFT_LOWER);
ObjectSetString(0,name_1,OBJPROP_TEXT,TimeToString(LaunchTime[i],TIME_DATE|TIME_MINUTES|TIME_SECONDS));
ObjectSetString(0,name_1,OBJPROP_FONT,"Impact");
ObjectSetInteger(0,name_1,OBJPROP_FONTSIZE,14);
ObjectSetInteger(0,name_1,OBJPROP_COLOR,Gold);
cnt++;
if (cnt == 4) break;
}
}
bool FindCommentOrder(int type,string in)
{
for (int i = 0;i<OrdersTotal();i++)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if (OrderMagicNumber() == id_1 && OrderSymbol() == Symbol())
{
if (StringFind(OrderComment(),in) >= 0)
return(true);
}
}
return(false);
}
//+------------------------------------------------------------------+
int MyOrderTotal(int type)
{
int x=0;
for(int z=0;z<OrdersTotal();z++)
{
if (!OrderSelect(z,SELECT_BY_POS,MODE_TRADES)) continue;
if(OrderSymbol()==Symbol() && OrderType()==type && OrderMagicNumber()==id_1)
{
x++;
}
}
return(x);
}
void iCloseOrders(int type)
{
int C0_cnt,close_t[];
if (type == OP_BUYSTOP)
{
for(C0_cnt=OrdersTotal();C0_cnt>=0;C0_cnt--) //從最近一張單開始
{
if (OrderSelect(C0_cnt,SELECT_BY_POS,MODE_TRADES)==false) continue;
if (OrderSymbol()==Symbol()&&OrderType()==OP_BUYSTOP && OrderMagicNumber()==id_1){
if (!OrderDelete(OrderTicket()))
{
Alert(ErrorDescription(GetLastError()));
}
}
}
}
if (type == OP_SELLSTOP)
{
for(C0_cnt=OrdersTotal();C0_cnt>=0;C0_cnt--) //從最近一張單開始
{
if (OrderSelect(C0_cnt,SELECT_BY_POS,MODE_TRADES)==false) continue;
if (OrderSymbol()==Symbol()&&OrderType()==OP_SELLSTOP && OrderMagicNumber()==id_1){
if (!OrderDelete(OrderTicket()))
{
Alert(ErrorDescription(GetLastError()));
}
}
}
}
if (type == OP_BUY)
{
for(C0_cnt=OrdersTotal();C0_cnt>=0;C0_cnt--) //從最近一張單開始
{
if (OrderSelect(C0_cnt,SELECT_BY_POS,MODE_TRADES)==false) continue;
if (OrderSymbol()==Symbol()&&OrderType()==OP_BUY && OrderMagicNumber()==id_1){
if (!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),clrLime))
{
Alert(ErrorDescription(GetLastError()));
}
}
}
}
if (type == OP_SELL)
{
for(C0_cnt=OrdersTotal();C0_cnt>=0;C0_cnt--) //從最近一張單開始
{
if (OrderSelect(C0_cnt,SELECT_BY_POS,MODE_TRADES)==false) continue;
if (OrderSymbol()==Symbol()&&OrderType()==OP_SELL && OrderMagicNumber()==id_1){
if (!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),clrRed))
{
Alert(ErrorDescription(GetLastError()));
}
}
}
}
if (type == OP_ALL)
{
for(C0_cnt=OrdersTotal();C0_cnt>=0;C0_cnt--) //從最近一張單開始
{
if (OrderSelect(C0_cnt,SELECT_BY_POS,MODE_TRADES)==false) continue;
if (OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP || OrderType() == OP_BUYLIMIT || OrderType() == OP_SELLLIMIT)
{
if (!OrderDelete(OrderTicket()))
{
Alert(ErrorDescription(GetLastError()));
}
}else {
if (!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),clrRed))
{
Alert(ErrorDescription(GetLastError()));
}
}
}
}
}
void Set_sl_tp(int type,double tp,double sl) {
double stoploss = 0.0,takeprofit = 0.0;
for(int z=0;z<OrdersTotal();z++)
{
if (!OrderSelect(z,SELECT_BY_POS,MODE_TRADES)) continue;
if(OrderType() == type && OrderSymbol()==Symbol() && OrderMagicNumber()==id_1)
{
switch(type)
{
case OP_BUY:
stoploss=OrderOpenPrice()-sl*point;
takeprofit=OrderOpenPrice()+tp*point;
break;
case OP_BUYSTOP:
stoploss=OrderOpenPrice()-sl*point;
takeprofit=OrderOpenPrice()+tp*point;
break;
case OP_SELL:
stoploss=OrderOpenPrice()+sl*point;
takeprofit=OrderOpenPrice()-tp*point;
break;
case OP_SELLSTOP:
stoploss=OrderOpenPrice()+sl*point;
takeprofit=OrderOpenPrice()-tp*point;
break;
}
if (sl == 0)
{
stoploss = 0;
}else if (sl < 0)
{
stoploss = OrderStopLoss();
}
if (tp == 0)
{
takeprofit=0;
}else if(tp < 0)
{
takeprofit = OrderTakeProfit();
}
if (DoubleToStr(stoploss,Digits)==DoubleToStr(OrderStopLoss(),Digits) && DoubleToStr(takeprofit,Digits)==DoubleToStr(OrderTakeProfit(),Digits))
{
continue;
}
RefreshRates();
if (!OrderModify(OrderTicket(),OrderOpenPrice(),stoploss,takeprofit,0,White))
{
Alert("OrderModify Error: " + ErrorDescription(GetLastError()));
}
}
}
}
int SearchArray(double& in[][],int match)
{
for (int i=0;i<MAX;i++)
{
if ((double)match == in[i][0]) return(i);
}
return(-1);
}
void SendBuy()
{
//SEND BUY
if (MyOrderTotal(OP_SELL) == 0 && MyOrderTotal(OP_BUY) == 0 && MyOrderTotal(OP_BUYSTOP) == 0 && BuyOrderSW)
{
if (MathAbs(Bid - Ask)/point <= SpreadNotIn)
{
TiB = OrderSend(Symbol(),
OP_BUYSTOP,Lot,
Ask + NormPoint(Range),
2*(int)(point/Point),
0,
0,
Symbol()+"_"+TimeToString(Open_O_Time),
id_1,
0,
clrLime);
}else
{
Alert(Symbol() + "海象異常,不適合出兵");
}
if (TiB <= 0)
{
Alert("OrderSend OP_BUYSTOP Error: " + ErrorDescription(GetLastError()));
return;
}else
{
for (int i=0;i<Orders - 1;i++)
{
if (!OrderSelect(TiB,SELECT_BY_TICKET,MODE_TRADES))
{
Alert("Multiple Orders Error: " + ErrorDescription(GetLastError()));
break;
}
TiB = OrderSend(Symbol(),
OP_BUYSTOP,Lot,
OrderOpenPrice() + NormPoint(Wide),
2*(int)(point/Point),
0,
0,
Symbol()+"_"+TimeToString(Open_O_Time),
id_1,
0,
clrLime);
}
if (MyOrderTotal(OP_BUYSTOP) == Orders) BuyOrderSW = false;
}
}
}
void SendSell()
{
//SEND SELL
if (MyOrderTotal(OP_SELL) == 0 && MyOrderTotal(OP_BUY) == 0 && MyOrderTotal(OP_SELLSTOP) == 0 && SellOrderSW)
{
if (MathAbs(Bid - Ask)/point <= SpreadNotIn)
{
TiS = OrderSend(Symbol(),
OP_SELLSTOP,Lot,
Bid - NormPoint(Range),
2*(int)(point/Point),
0,
0,
Symbol()+"_"+TimeToString(Open_O_Time),
id_1,
0,
clrLime);
}else
{
Alert(Symbol() + "海象異常,不適合出兵");
}
if (TiS <= 0)
{
Alert("OrderSend OP_SELLSTOP Error: " + ErrorDescription(GetLastError()));
return;
}else
{
for (int i=0;i<Orders - 1;i++)
{
if (!OrderSelect(TiS,SELECT_BY_TICKET,MODE_TRADES))
{
Alert("Multiple Orders Error: " + ErrorDescription(GetLastError()));
break;
}
TiS = OrderSend(Symbol(),
OP_SELLSTOP,Lot,
OrderOpenPrice() - NormPoint(Wide),
2*(int)(point/Point),
0,
0,
Symbol()+"_"+TimeToString(Open_O_Time),
id_1,
0,
clrLime);
}
if (MyOrderTotal(OP_SELLSTOP) == Orders) SellOrderSW = false;
}
}
}
void SetKbar(double& Kbar[])
{
Kbar[0] = (double)iTime(Symbol(),1,0);
Kbar[1] = iOpen(Symbol(),1,0);
Kbar[2] = iHigh(Symbol(),1,0);
Kbar[3] = iLow(Symbol(),1,0);
Kbar[4] = iClose(Symbol(),1,0);
Kbar[5] = (double)iVolume(Symbol(),1,0);
}
void InitAllVar()
{
BuyOrderSW = true;
SellOrderSW = true;
BrakeSW = true;
Open_O_Time = 0;
ArrayResize(LaunchTime,1);
ArrayInitialize(LaunchTime,0);
AfterBrake = 0;
TimeNow = 0;
TiB = 0;
TiS = 0;
TiB_Brake = 0;
TiS_Brake = 0;
Position=0;
/*ArrayResize(Status,1);
ArrayInitialize(Status,0);
ArrayResize(Last_Time,1);
ArrayInitialize(Last_Time,0);
ArrayResize(SleepStop,1);
ArrayInitialize(SleepStop,0);
ArrayResize(Last_Price,1);
ArrayInitialize(Last_Price,-1);
MinPriceShot = 0.0;*/
}
void SetButtonNTEXT()
{
int chart_width=(int)ChartGetInteger(0,CHART_WIDTH_IN_PIXELS);
int i = 0;
for (;i<ArraySize(buttonID);i++)
{
if (ObjectFind(0,buttonID[i]) < 0) ObjectCreate(0,buttonID[i],OBJ_BUTTON,0,100,100);
ObjectSetInteger(0,buttonID[i],OBJPROP_COLOR,clrWhite);
ObjectSetInteger(0,buttonID[i],OBJPROP_BGCOLOR,clrDimGray);
ObjectSetInteger(0,buttonID[i],OBJPROP_XDISTANCE,i*(chart_width/10));
ObjectSetInteger(0,buttonID[i],OBJPROP_YDISTANCE,50);
ObjectSetInteger(0,buttonID[i],OBJPROP_CORNER,CORNER_LEFT_LOWER);
ObjectSetString(0,buttonID[i],OBJPROP_FONT,"微軟正黑體");
ObjectSetInteger(0,buttonID[i],OBJPROP_COLOR,clrWhite);
ObjectSetString(0,buttonID[i],OBJPROP_TEXT,Text[i]);
ObjectSetInteger(0,buttonID[i],OBJPROP_FONTSIZE,10);
ObjectSetInteger(0,buttonID[i],OBJPROP_SELECTABLE,0);
//ObjectSetInteger(0,buttonID[i],OBJPROP_ANCHOR,ANCHOR_LEFT_UPPER);
}
string obj_str = "";
string obj_vline_lable = "";
string obj_edit = "";
string obj_button1 = "";
datetime obj_time = 0;
datetime TimeOffset = TimeLocal() - TimeCurrent();
datetime obj_time_convert = 0;
double obj_pos = 0.0;
int obj_cnt = 0;
for (i=0;i<ObjectsTotal();i++)
{
obj_str = ObjectName(i);
obj_time = (datetime)ObjectGetInteger(0,obj_str,OBJPROP_TIME);
if (StringFind(obj_str,"GL") >= 0 && ObjectType(obj_str) == OBJ_VLINE)
{
obj_vline_lable = obj_str + "L";
obj_time_convert = obj_time + TimeOffset;
obj_pos = ChartGetDouble(0,CHART_PRICE_MAX,0) - ((ChartGetDouble(0,CHART_PRICE_MAX,0) - ChartGetDouble(0,CHART_PRICE_MIN,0)) / 30) * obj_cnt;
if (ObjectFind(obj_vline_lable) < 0) ObjectCreate(0,obj_vline_lable,OBJ_TEXT,0,0,0);
ObjectSetInteger(0,obj_vline_lable,OBJPROP_TIME,obj_time+1*Period()*60);
ObjectSetDouble(0,obj_vline_lable,OBJPROP_PRICE,obj_pos);
ObjectSetString(0,obj_vline_lable,OBJPROP_TEXT,IntegerToString(obj_cnt) + " " + TimeToString(obj_time_convert,TIME_DATE|TIME_MINUTES));
ObjectSetString(0,obj_vline_lable,OBJPROP_FONT,"Arial");
ObjectSetInteger(0,obj_vline_lable,OBJPROP_COLOR,clrGold);
ObjectSetInteger(0,obj_vline_lable,OBJPROP_ANCHOR,ANCHOR_LEFT_UPPER);
obj_cnt++;
}
}
}
void SetButtonSize()
{
int chart_width=(int)ChartGetInteger(0,CHART_WIDTH_IN_PIXELS);
int i = 0;
for (;i<ArraySize(buttonID);i++)
{
ObjectSetInteger(0,buttonID[i],OBJPROP_XSIZE,chart_width/10);
ObjectSetInteger(0,buttonID[i],OBJPROP_YSIZE,50);
}
}
void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam)
{
if(id==CHARTEVENT_OBJECT_CLICK)
{
string clickedChartObject=sparam;
//--- If you click on the object with the name buttonID
if(clickedChartObject==buttonID[0])
{
bool selected = ObjectGetInteger(0,buttonID[0],OBJPROP_STATE);
if (selected)
{
Sleep(50);
keybd_event(118,0,0,0);
keybd_event(118,0,0x0002,0);
ObjectSetInteger(0,buttonID[0],OBJPROP_STATE,false);
}
}
if(clickedChartObject==buttonID[1])
{
bool selected = ObjectGetInteger(0,buttonID[1],OBJPROP_STATE);
if (selected)
{
Sleep(50);
ShellExecuteW(NULL, "open", "notepad.exe", TerminalInfoString(TERMINAL_PATH) + "\\MQL4\\Files\\Event.csv", NULL, 5);
ObjectSetInteger(0,buttonID[1],OBJPROP_STATE,false);
}
}
if(clickedChartObject == buttonID[2])
{
bool selected = ObjectGetInteger(0,buttonID[2],OBJPROP_STATE);
if (selected)
{
Sleep(50);
int ans_remove = MessageBox("確認是否離開戰場?","確認命令",MB_YESNO|MB_ICONQUESTION);
if (ans_remove == 6) PostMessageW(WindowHandle(Symbol(),Period()),WM_COMMAND,33050,0);
ObjectSetInteger(0,buttonID[2],OBJPROP_STATE,false);
}
}
if(clickedChartObject == buttonID[3])
{
bool selected = ObjectGetInteger(0,buttonID[3],OBJPROP_STATE);
if (selected)
{
Sleep(50);
int ans_bomb = MessageBox("確認是否掃除水雷?","確認命令",MB_YESNO|MB_ICONQUESTION);
if (ans_bomb == 6) iCloseOrders(OP_ALL);
ObjectSetInteger(0,buttonID[3],OBJPROP_STATE,false);
}
}
#ifdef MODE_AREA51
if(clickedChartObject == buttonID[4])
{
bool selected = ObjectGetInteger(0,buttonID[4],OBJPROP_STATE);
if (selected)
{
Sleep(50);
string obj_vlinename = "GL_" + IntegerToString(GetVLineNumber());
//string obj_vline_lable = "GL_" + IntegerToString(GetVLineNumber()) + "L";
ObjectCreate(0,obj_vlinename,OBJ_VLINE,0,0,0);
ObjectSetInteger(0,obj_vlinename,OBJPROP_TIME,TimeCurrent() + Period() * 600);
// ObjectCreate(0,obj_vline_lable,OBJ_TEXT,0,0,0);
ObjectSetInteger(0,buttonID[4],OBJPROP_STATE,false);
}
}
if(clickedChartObject == buttonID[5])
{
bool selected = ObjectGetInteger(0,buttonID[5],OBJPROP_STATE);
if (selected)
{
Sleep(50);
ObjectSetInteger(0,buttonID[5],OBJPROP_STATE,false);
string obj_str = "";
int obj_total = 0;
obj_total = ObjectsTotal();
for (int i=obj_total;i>=0;i--)
{
obj_str = ObjectName(i);
if (
(ObjectType(obj_str) == OBJ_VLINE && StringFind(obj_str,"GL") >= 0) ||
(ObjectType(obj_str) == OBJ_TEXT && StringFind(obj_str,"GL") >= 0)
)
{
ObjectDelete(0,obj_str);
}
}
}
}
#endif
ChartRedraw();// Forced redraw all chart objects
}
}
int GetVLineNumber()
{
int i = 0,Out = 0;
for (;i<ObjectsTotal();i++)
{
if(ObjectType(ObjectName(i)) == OBJ_VLINE && StringFind(ObjectName(i),"GL") >= 0)
{
Out++;
}
}
return(Out);
}
string MakeDateTime(string strDate, string strTime)
{
// Print("Converting Forex Factory Time into Metatrader time..."); //added by MN
// Converts forexfactory time & date into yyyy.mm.dd hh:mm
int n1stDash = StringFind(strDate, "-");
int n2ndDash = StringFind(strDate, "-", n1stDash+1);
string strMonth = StringSubstr(strDate, 0, 2);
string strDay = StringSubstr(strDate, 3, 2);
string strYear = StringSubstr(strDate, 6, 4);
// strYear = "20" + strYear;
int nTimeColonPos = StringFind(strTime, ":");
string strHour = StringSubstr(strTime, 0, nTimeColonPos);
string strMinute = StringSubstr(strTime, nTimeColonPos+1, 2);
string strAM_PM = StringSubstr(strTime, StringLen(strTime)-2);
int nHour24 = StrToInteger(strHour);
if ((strAM_PM == "pm" || strAM_PM == "PM") && nHour24 != 12)
{
nHour24 += 12;
}
if ((strAM_PM == "am" || strAM_PM == "AM") && nHour24 == 12)
{
nHour24 = 0;
}
string strHourPad = "";
if (nHour24 < 10)
strHourPad = "0";
return(StringConcatenate(strYear, ".", strMonth, ".", strDay, " ", strHourPad, nHour24, ":", strMinute));
}
string ModeText()
{
switch (Mode)
{
case MODE_CSV:
return("Schedule");
case MODE_NEWS:
return("NEWS");
#ifdef MODE_AREA51
#ifdef MODE_MOON_AREA51
case MODE_ENERGY:
return("Energy Ball");
#endif
case MODE_VLINE:
return("Event Line");
#endif
}
return("");
}
void TC()
{
for (int i=OrdersTotal()-1;i>=0;i--)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if (OrderMagicNumber() == id_1 && OrderSymbol() == Symbol() && (OrderType() == OP_BUY || OrderType() == OP_SELL))
{
if (OrderProfit() > 0 &&
TimeCurrent() >= OrderOpenTime() + TimeClose &&
MathAbs(OrderClosePrice() - OrderOpenPrice())/point <= TCpips)
{
if (!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,White))
{
Alert(ErrorDescription(GetLastError()));
}
}
}
}
}
void F_SpreadIn(datetime& iAbortTime)
{
if (MathAbs(Bid - Ask)/point >= SpreadIn)
{
iAbortTime = AbortTime + MoreTime;
}
else
{
iAbortTime = AbortTime;
}
return;
}
//+------------------------------------------------------------------+
int hSession(bool Direct)
{
int hSession_IEType = 0;
int hSession_Direct = 0;
int Internet_Open_Type_Preconfig = 0;
int Internet_Open_Type_Direct = 1;
int Internet_Open_Type_Proxy = 3;
string InternetAgent="";
if(hSession_IEType == 0)
{
InternetAgent="Mozilla/4.0 (compatible; MSIE 8.0; Win32)";
hSession_IEType = InternetOpenW(InternetAgent, Internet_Open_Type_Preconfig, "", "", 0);
hSession_Direct = InternetOpenW(InternetAgent, Internet_Open_Type_Direct, "", "", 0);
}
if(Direct)
{
return(hSession_Direct);
}
else
{
return(hSession_IEType);
}
}
void CheckServerLocalTime()
{
int LocalMinute = TimeMinute(TimeLocal());
int LocalSeconds = TimeSeconds(TimeLocal());
int ServerMinute = TimeMinute(TimeCurrent());
int ServerSeconds = TimeSeconds(TimeCurrent());
if (AccountInfoInteger(ACCOUNT_TRADE_ALLOWED))
{
Print("System Time: " + IntegerToString(LocalMinute) + ":" + IntegerToString(LocalSeconds));
Print("Server Time: " + IntegerToString(ServerMinute) + ":" + IntegerToString(ServerSeconds));
if (MathAbs(LocalMinute - ServerMinute) >= 1 || MathAbs(LocalSeconds - ServerSeconds) >= 5)
{
Alert("系統與伺服器時間分鐘或秒數不同步,請檢查設定");
}
}
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment