Skip to content

Instantly share code, notes, and snippets.

@APPEA
Last active December 17, 2019 13:19
Show Gist options
  • Save APPEA/d89b3da08df9e6fe9549 to your computer and use it in GitHub Desktop.
Save APPEA/d89b3da08df9e6fe9549 to your computer and use it in GitHub Desktop.
天網戰艦
//+------------------------------------------------------------------+
//| EAManager.mq4 |
//| APP Wargame-Hydra |
//| http://www.facebook.com/groups/moneywargame/ |
//+------------------------------------------------------------------+
#property copyright "APP Wargame-Hydra"
#property link "http://www.facebook.com/groups/moneywargame/"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
#define SKYNET 1
#define NEW_WARGAMELIB 1
#define CURRVER "V01.09.00"
#include <WarGameLib.mqh>
#include <WinUser32.mqh>
input double iBalance = 0; //止盈計算本金基準
input bool TakeProfitPercentSW = false; //次止盈開關
input double TakeProfitPercent = 1000; //次止盈,每次最多獲利%,立即平倉歸零重啟新局
input double TakeProfitDollar = 1000; //次止盈金額
input bool TakeProfitPercentAccSW = false; //浮盈次止盈開關
input double TakeProfitAccPercent = 1000; //浮盈次止盈%
input double TakeProfitAccDollar = 1000; //浮盈次止盈金額
input bool TakeProfitPercentDaySW = false; //日止盈開關
//input double TakeProfitPercentDay = 1000; //日止盈,每日最多獲利%,立即停止交易,隔日重新啟動
input double TakeProfitDollarDay = 1000; //日止盈金額
input bool StopLossPercentSW = false; //浮虧止損開關
input double StopLossPercent = 10000; //現時帳戶浮虧止損%,止損基準值:帳戶餘額
input double StopLossDollar = 10000; //止損金額
input bool SleepLoss = false; //止損後不再出兵
input bool ForceOutSW = false; //時間到強制水雷開關
input string ForceOut = "00:00"; //強制水雷時間 24小時制(HH:MM)
input bool Reset = false; //下局立即開始
input double NextTime=0.5; //水雷後休息時間
input string b = "-------------------"; // 
input bool SmallLossWinSW = true; //小虧為贏開關
input int MaxTime = 150; //每局最長時間(分鐘)
input int MaxIn = 10; //每局最多兵力
input double MaxP = 0.5; //達成以上條件小虧為贏
input string c = "-------------------"; // 
input bool ClearMaxEq = false; //最大被擄獲兵力歸零
datetime ForceOutBarTime = 0;
class GlobalFile_class
{
private:
string GlobalVars_EARunTime;
string GlobalVars_MaxEquity;
string GlobalVars_Start_Balance;
string GlobalVars_Start_P;
string GlobalVars_EASW;
public:
GlobalFile_class();
datetime Read_EARunTime();
double Read_MaxEquity();
double Read_Start_Balance();
datetime Read_Start_P();
int Read_EASW();
datetime Write_EARunTime(datetime);
datetime Write_MaxEquity(double);
datetime Write_Start_Balance(double);
datetime Write_Start_P(datetime);
datetime Write_EASW(int);
}GlobalObj;
void GlobalFile_class::GlobalFile_class()
{
GlobalVars_EARunTime = "__G_EARunTime";
GlobalVars_MaxEquity = "__G_MaxEquity";
GlobalVars_Start_Balance = "__G_Start_Balance";
GlobalVars_Start_P = "__G_Start_P";
GlobalVars_EASW = "__G_EASW";
}
datetime GlobalFile_class::Read_EARunTime()
{
return((datetime)GlobalVariableGet(GlobalVars_EARunTime));
}
double GlobalFile_class::Read_MaxEquity()
{
return(GlobalVariableGet(GlobalVars_MaxEquity));
}
double GlobalFile_class::Read_Start_Balance()
{
return(GlobalVariableGet(GlobalVars_Start_Balance));
}
datetime GlobalFile_class::Read_Start_P()
{
return((datetime)GlobalVariableGet(GlobalVars_Start_P));
}
int GlobalFile_class::Read_EASW()
{
return((int)GlobalVariableGet(GlobalVars_EASW));
}
datetime GlobalFile_class::Write_EARunTime(datetime inTime)
{
return(GlobalVariableSet(GlobalVars_EARunTime,inTime));
}
datetime GlobalFile_class::Write_MaxEquity(double inMaxEquity)
{
return(GlobalVariableSet(GlobalVars_MaxEquity,inMaxEquity));
}
datetime GlobalFile_class::Write_Start_Balance(double inStart_Balance)
{
return(GlobalVariableSet(GlobalVars_Start_Balance,inStart_Balance));
}
datetime GlobalFile_class::Write_Start_P(datetime inStart_P)
{
return(GlobalVariableSet(GlobalVars_Start_P,inStart_P));
}
datetime GlobalFile_class::Write_EASW(int inEASW)
{
return(GlobalVariableSet(GlobalVars_EASW,inEASW));
}
bool timerSwitch = true;
int newverMT4=1;
int accountMode=1;
string accountID="836685848547207712003728188444451105127785883063480237626581654545235641770673812083627580576101756005466171348506351718018477636640738024712447610326370743607336407840750431123515858787882858337116175315867043222431215716160410560707354632265722702582645";
string EndDate="078056226088564058147325163351668042665625580487527727070848364555136220168667182336200530684107467458184240761072013026064210412037270821623423154838710458724001833706723015346513187521281841184141761711068151412357157331260206615504132577761814210124420";
int OnInit()
{
//---
if (!CheckRemove(MODE_INIT)) return(-1);
MathSrand(GetTickCount());
DownloadMin = (uchar)(1 + ((59 * MathRand()) / 32768));
UpdateFiles(MODE_INIT);
TimesStopConfig();
GlobalVariableSet("AutoOpenChart",ChartID());
EventSetMillisecondTimer(10);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
EventKillTimer();
GlobalVariableSet("DNSW",0);
DeleteObjects();
GlobalVariableSet(IntegerToString(ChartID()),reason);
switch (reason)
{
case REASON_CHARTCLOSE:
case REASON_REMOVE:
GlobalVariableSet("AutoOpenChart",0);
break;
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTimer()
{
//---
if (!timerSwitch) return;
if (!CheckRemove(MODE_TICK)) return;
double TimesProfit = 0.0;
double TodayProfit = 0.0;
if (!TimesStop(TimesProfit,TodayProfit)) return;
CheckTimeIn(TimesProfit);
Displayprofit(TimesProfit,TodayProfit);
if (!CloseAllTrades()) return;
//+------------------------------------------------------------------+
//|Shutdown EA |
//+------------------------------------------------------------------+
}
//+------------------------------------------------------------------+
bool TimesStop(double &TimesProfit, double &TodayProfit)
{
double TimesDollar = 0.0;
double TodayDollar = 0.0;
if (OrdersTotal()==0)
{
//GlobalVars.Start_Balance = AccountBalance();
//GlobalVars.Start_P = TimeCurrent();
GlobalObj.Write_Start_Balance(AccountBalance());
GlobalObj.Write_Start_P(TimeCurrent());
GlobalVariableSet(NextSW_str,0);
Sleep(1000);
}
//+------------------------------------------------------------------+
//|Read Status |
//+------------------------------------------------------------------+
if(!EqualZero(iBalance))
{ //GlobalVars.Start_Balance = iBalance;
GlobalObj.Write_Start_Balance(iBalance);
} //Start_Balance = GlobalVars.G_Start_Balance;
//else
//Start_P = GlobalVars.G_Start_P;
//EARunTime = GlobalVars.G_EARunTime;
//+------------------------------------------------------------------+
//|Renew Max Equity |
//+------------------------------------------------------------------+
if ((AccountProfit() / GlobalObj.Read_Start_Balance()) * 100 < GlobalObj.Read_MaxEquity())
{
GlobalObj.Write_MaxEquity((AccountProfit() / GlobalObj.Read_Start_Balance()) * 100);
}
//if ((AccountProfit() / GlobalVars.Start_Balance) * 100 < GlobalVars.MaxEquity)
//{
// GlobalVars.MaxEquity = (AccountProfit() / GlobalVars.Start_Balance) * 100;
//}
if (ClearMaxEq)
{
GlobalObj.Write_MaxEquity(0.0);
//GlobalVars.MaxEquity = 0;
}
//+------------------------------------------------------------------+
//|Check Balance |
//+------------------------------------------------------------------+
if (GlobalObj.Read_Start_Balance() < AccountBalance() / 2 || GlobalObj.Read_Start_P() == 0)
{
Alert("Check your balance setting");
return(false);
}
//+------------------------------------------------------------------+
//|Times Take Profit |
//+------------------------------------------------------------------+
TimesProfit = ((GetProfitPeriod(GlobalObj.Read_Start_P()) + AccountProfit()) / GlobalObj.Read_Start_Balance()) * 100;
TimesDollar = GetProfitPeriod(GlobalObj.Read_Start_P()) + AccountProfit();
//TimesProfit = ((GetProfitPeriod(GlobalVars.Start_P) + AccountProfit()) / GlobalVars.Start_Balance) * 100;
//TimesDollar = GetProfitPeriod(GlobalVars.Start_P) + AccountProfit();
if (TakeProfitPercentSW)
{
if (!EqualZero(TakeProfitPercent) && TimesProfit >= TakeProfitPercent)
{
GlobalVariableSet(NextSW_str,1);
GlobalObj.Write_EARunTime((datetime)(TimeCurrent() + NextTime * 60));
WriteLog(MODE_TIMESTP,DoubleToString(TimesProfit,2) + "%");
}
if (!EqualZero(TakeProfitDollar) && TimesDollar >= TakeProfitDollar)
{
GlobalVariableSet(NextSW_str,1);
GlobalObj.Write_EARunTime((datetime)(TimeCurrent() + NextTime * 60));
WriteLog(MODE_TIMESTP,DoubleToString(TimesDollar,2) + "USD");
}
}
if (TakeProfitPercentAccSW)
{
if (CheckSLTicket(GlobalObj.Read_Start_P()))
{
if (!EqualZero(TakeProfitAccPercent) && (AccountProfit() / GlobalObj.Read_Start_Balance()) * 100 >= TakeProfitAccPercent)
{
GlobalVariableSet(NextSW_str,1);
GlobalObj.Write_EARunTime((datetime)(TimeCurrent() + NextTime * 60));
WriteLog(MODE_TIMESTP,DoubleToString((AccountProfit() / GlobalObj.Read_Start_Balance()) * 100,2) + "%");
}
if (!EqualZero(TakeProfitAccDollar) && AccountProfit() >= TakeProfitAccDollar)
{
GlobalVariableSet(NextSW_str,1);
GlobalObj.Write_EARunTime((datetime)(TimeCurrent() + NextTime * 60));
WriteLog(MODE_TIMESTP,DoubleToString(AccountProfit(),2) + "%");
}
}
}
//+------------------------------------------------------------------+
//|Daily Take Profit |
//+------------------------------------------------------------------+
TodayProfit = ((GetProfitPeriod(StrToTime(TimeToStr(TimeCurrent(),TIME_DATE))) + AccountProfit()) / GlobalObj.Read_Start_Balance())* 100;
TodayDollar = GetProfitPeriod(StrToTime(TimeToStr(TimeCurrent(),TIME_DATE))) + AccountProfit();
if (TakeProfitPercentDaySW)
{
/*if (!EqualZero(TakeProfitPercentDay))
{
if (TodayProfit >= TakeProfitPercentDay)
{
GlobalVariableSet(NextSW_str,1);
GlobalVars.EARunTime = iTime(Symbol(),PERIOD_D1,0) + 86400;
WriteLog(MODE_DAILYTP,DoubleToString(TodayProfit,2) + "%");
}else
{
if (OrdersTotal() == 0)
{
GlobalVars.EARunTime = 0;
}
}
}*/
if (!EqualZero(TakeProfitDollarDay))
{
if (TodayDollar >= TakeProfitDollarDay)
{
GlobalVariableSet(NextSW_str,1);
if (GlobalObj.Read_EARunTime() != iTime(Symbol(),PERIOD_D1,0) + 86400)
WriteLog(MODE_DAILYTP,DoubleToString(TodayDollar,2) + "USD");
GlobalObj.Write_EARunTime(iTime(Symbol(),PERIOD_D1,0) + 86400);
//GlobalVars.EARunTime = iTime(Symbol(),PERIOD_D1,0) + 86400;
}
}
}
//+------------------------------------------------------------------+
//|Account Stop Loss |
//+------------------------------------------------------------------+
if (StopLossPercentSW)
{
if (!EqualZero(StopLossPercent) && (AccountProfit() / AccountBalance()) * 100 <= -1 * StopLossPercent)
{
GlobalVariableSet(NextSW_str,1);
GlobalObj.Write_EARunTime((datetime)(TimeCurrent() + NextTime * 60));
WriteLog(MODE_TIMESSL,DoubleToString((AccountProfit() / AccountBalance()) * 100,2) + "%");
if (SleepLoss)
{
//GlobalObj.Write_EARunTime(iTime(Symbol(),PERIOD_D1,0) + 86400);
GlobalObj.Write_EASW(0);
}
}
if (!EqualZero(StopLossDollar) && AccountProfit() <= -1 * StopLossDollar)
{
GlobalVariableSet(NextSW_str,1);
GlobalObj.Write_EARunTime((datetime)(TimeCurrent() + NextTime * 60));
WriteLog(MODE_TIMESSL,DoubleToString(AccountProfit(),2) + "USD");
if (SleepLoss)
{
//GlobalObj.Write_EARunTime(iTime(Symbol(),PERIOD_D1,0) + 86400);
GlobalObj.Write_EASW(0);
}
}
}
//+------------------------------------------------------------------+
//|Force Out |
//+------------------------------------------------------------------+
if (ForceOutSW)
{
int ForceOutHour = 0;
int ForceOutMin = 0;
ForceOutTime(ForceOutHour,ForceOutMin);
if (ForceOutHour == TimeHour(TimeLocal()) && TimeMinute(TimeLocal()) >= ForceOutMin && TimeMinute(TimeLocal()) < ForceOutMin + 5)
{
if (ForceOutBarTime != iTime(Symbol(),PERIOD_H1,0))
{
GlobalVariableSet(NextSW_str,1);
GlobalObj.Write_EARunTime((datetime)(TimeCurrent() + NextTime * 60));
WriteLog(MODE_FORCEOUT,DoubleToString(AccountProfit(),2) + "USD");
ForceOutBarTime = iTime(Symbol(),PERIOD_H1,0);
}
}
}
//+------------------------------------------------------------------+
//|Write Status |
//+------------------------------------------------------------------+
if (OrdersTotal() == 0)
{
if (Reset)
{
if (GlobalObj.Read_EASW() == 0) GlobalObj.Write_EASW(1);
}
}
return(true);
}
bool TimesStopConfig()
{
//+------------------------------------------------------------------+
//|Close All Trades Function Init |
//+------------------------------------------------------------------+
GlobalVariableSet(NextSW_str,0);
//if (!GlobalFileCheck()) Alert("CheckGlobalFile Error 0");
if (!GlobalFileCheck())
{
Alert("ReadGlobalFile Error");
GlobalObj.Write_EARunTime(TimeCurrent());
GlobalObj.Write_MaxEquity((AccountProfit() / AccountBalance()) * 100);
GlobalObj.Write_Start_P(TimeCurrent());
GlobalObj.Write_Start_Balance(AccountBalance());
GlobalObj.Write_EASW(1);
//GlobalVars.EARunTime = TimeCurrent();
//GlobalVars.MaxEquity = (AccountProfit() / AccountBalance()) * 100;
//GlobalVars.Start_P = TimeCurrent();
//GlobalVars.Start_Balance = AccountBalance();
//if (!GlobalFileWrite()) Alert("WriteGlobalFile Error 1");
}else
{
if (EqualZero(GlobalObj.Read_Start_Balance()))
{
GlobalObj.Write_Start_Balance(AccountBalance());
//if (!GlobalFileWrite()) Alert("WriteGlobalFile Error 2");
}
if (GlobalObj.Read_Start_P() == 0)
{
GlobalObj.Write_Start_P(TimeCurrent());
//GlobalVars.Start_P = TimeCurrent();
//if (!GlobalFileWrite()) Alert("WriteGlobalFile Error 3");
}
}
//if (!GlobalFileRead()) Alert("ReadGlobalFile Error");
Print("EARuntime: " + TimeToString(GlobalObj.Read_EARunTime(),TIME_DATE|TIME_MINUTES|TIME_SECONDS));
Print("MaxLossEquity: " + DoubleToString(GlobalObj.Read_MaxEquity(),2));
Print("Start_P: " + TimeToString(GlobalObj.Read_Start_P(),TIME_DATE|TIME_MINUTES|TIME_SECONDS));
Print("Start_Balance: " + DoubleToString(GlobalObj.Read_Start_Balance(),2));
return(true);
}
bool CloseAllTrades()
{
if (CompareDouble(GlobalVariableGet(NextSW_str),1))
{
iCloseOrders(OP_BUY);
iCloseOrders(OP_SELL);
iCloseOrders(OP_ALL);
if (OrdersTotal() == 0)
{
//if (TimeCurrent() >= GlobalVars.EARunTime)
//{
// GlobalVars.EARunTime = 0;
// if (!GlobalFileWrite()) Alert("WriteGlobalFile Error 4");
//}
return(true);
}else
{
Alert("水雷未掃除成功");
//GlobalVars.EARunTime = (datetime)(TimeCurrent() + NextTime * 60);
//if (!GlobalFileWrite()) Alert("WriteGlobalFile Error 5");
}
}
return(false);
}
void CheckTimeIn(const double TimesProfit)
{
datetime RunTime = (TimeCurrent() - GlobalObj.Read_Start_P()) / 60;
if (SmallLossWinSW && RunTime >= MaxTime && (MyOrderTotalAccount(OP_BUY) + MyOrderTotalAccount(OP_SELL)) >= MaxIn && TimesProfit >= MaxP)
{
//Close all Trades
GlobalVariableSet(NextSW_str,1);
GlobalObj.Write_EARunTime((datetime)(TimeCurrent() + NextTime * 60));
WriteLog(MODE_CHECKTIMEIN,"");
}
}
void Displayprofit(const double TimesProfit, const double TodayProfit)
{
string label_arr[8] =
{
"TimesProfitPer",
"Start_Balance",
"TimePast",
"Orders",
"TodayProfitPer",
"MaxLoss",
"NextInTime",
"EASW"
};
string label_arr1[8] =
{
"TimesProfitPer0",
"Start_Balance0",
"TimePast0",
"Orders0",
"TodayProfitPer0",
"MaxLoss0",
"NextInTime0",
"EASW0"
};
int Pos = 50;
string Label_Text = "";
string Label_Text1 = "";
if (ObjectFind(Run) < 0) ObjectCreate(0,Run,OBJ_LABEL,0,0,0);
ObjectSetInteger(0,Run, OBJPROP_CORNER, 1);
ObjectSetInteger(0,Run, OBJPROP_COLOR, clrGold);
ObjectSetInteger(0,Run, OBJPROP_XDISTANCE, 20);
ObjectSetInteger(0,Run, OBJPROP_YDISTANCE, Pos);
ObjectSetInteger(0,Run, OBJPROP_FONTSIZE, 10);
ObjectSetInteger(0,Run, OBJPROP_ANCHOR, ANCHOR_RIGHT_UPPER);
ObjectSetString(0,Run, OBJPROP_FONT, "微軟正黑體");
for (int i=0;i<ArraySize(label_arr);i++)
{
if(ObjectFind(label_arr[i]) < 0) ObjectCreate(0,label_arr[i],OBJ_LABEL,0,0,0);
ObjectSetInteger(0,label_arr[i],OBJPROP_CORNER,1);
ObjectSetInteger(0,label_arr[i],OBJPROP_COLOR,White);
ObjectSetInteger(0,label_arr[i],OBJPROP_XDISTANCE,120);
ObjectSetInteger(0,label_arr[i],OBJPROP_YDISTANCE,Pos + 30 + 20 * i);
ObjectSetInteger(0,label_arr[i],OBJPROP_ANCHOR,ANCHOR_RIGHT);
ObjectSetString(0,label_arr[i],OBJPROP_FONT,"微軟正黑體");
if(ObjectFind(label_arr1[i]) < 0) ObjectCreate(0,label_arr1[i],OBJ_LABEL,0,0,0);
ObjectSetInteger(0,label_arr1[i],OBJPROP_CORNER,1);
ObjectSetInteger(0,label_arr1[i],OBJPROP_COLOR,White);
ObjectSetInteger(0,label_arr1[i],OBJPROP_XDISTANCE,20);
ObjectSetInteger(0,label_arr1[i],OBJPROP_YDISTANCE,Pos + 30 + 20 * i);
ObjectSetInteger(0,label_arr1[i],OBJPROP_ANCHOR,ANCHOR_RIGHT);
ObjectSetString(0,label_arr1[i],OBJPROP_FONT,"微軟正黑體");
switch(i)
{
case 0:
Label_Text = "單次擄獲狂派戰俘: ";
Label_Text1 = DoubleToString(TimesProfit,2) + " %";
break;
case 1:
Label_Text = "進場起始兵力: ";
Label_Text1 = DoubleToString(GlobalObj.Read_Start_Balance(),2);
break;
case 2:
Label_Text = "進場經過時間: " ;
Label_Text1 = DoubleToString((TimeCurrent() - GlobalObj.Read_Start_P()) / 60,1) + " 分鐘";
break;
case 3:
Label_Text = "戰場兵力: ";
Label_Text1 = IntegerToString(OrdersTotal());
break;
case 4:
Label_Text = "今日擄獲狂派戰俘累積至: " ;
Label_Text1 = DoubleToString(TodayProfit,2);
break;
case 5:
Label_Text = "最大暫時被擄穫兵力: ";
Label_Text1 = DoubleToString(GlobalObj.Read_MaxEquity(),2)+" %";
break;
case 6:
Label_Text = "下次進場時間: ";
Label_Text1 = StringSubstr(TimeToString(GlobalObj.Read_EARunTime(),TIME_DATE|TIME_MINUTES|TIME_SECONDS),5,14);
break;
case 7:
Label_Text = "";
Label_Text1 = (GlobalObj.Read_EASW() == 0 ? "止損後不再出兵" : "");
break;
}
ObjectSetString(0,label_arr[i],OBJPROP_TEXT,Label_Text);
ObjectSetString(0,label_arr1[i],OBJPROP_TEXT,Label_Text1);
}
ObjectCreate(0,Margin,OBJ_LABEL,0,0,0);
ObjectSetInteger(0,Margin, OBJPROP_CORNER, 1);
ObjectSetInteger(0,Margin, OBJPROP_ANCHOR, ANCHOR_RIGHT_UPPER);
ObjectSetInteger(0,Margin, OBJPROP_COLOR, clrGold);
ObjectSetInteger(0,Margin, OBJPROP_XDISTANCE, 20);
ObjectSetInteger(0,Margin, OBJPROP_YDISTANCE, Pos+195);
ObjectSetInteger(0,Margin, OBJPROP_FONTSIZE, 10);
ObjectSetString(0,Margin, OBJPROP_FONT, "微軟正黑體");
ObjectSetString(0,Margin,OBJPROP_TEXT,"");
ObjectCreate(0,FloatLoss,OBJ_LABEL,0,0,0);
ObjectSetInteger(0,FloatLoss, OBJPROP_CORNER, 1);
ObjectSetInteger(0,FloatLoss, OBJPROP_ANCHOR, ANCHOR_RIGHT_UPPER);
ObjectSetInteger(0,FloatLoss, OBJPROP_COLOR, clrGold);
ObjectSetInteger(0,FloatLoss, OBJPROP_XDISTANCE, 20);
ObjectSetInteger(0,FloatLoss, OBJPROP_YDISTANCE, Pos+215);
ObjectSetInteger(0,FloatLoss, OBJPROP_FONTSIZE, 10);
ObjectSetString(0,FloatLoss, OBJPROP_FONT, "微軟正黑體");
ObjectSetString(0,FloatLoss,OBJPROP_TEXT,"");
if (ObjectFind(Light) < 0)
ObjectCreate(0,Light,OBJ_LABEL,0,0,0);
ObjectSetInteger(0,Light,OBJPROP_CORNER,1);
ObjectSetInteger(0,Light, OBJPROP_ANCHOR, ANCHOR_RIGHT_UPPER);
ObjectSetInteger(0,Light,OBJPROP_COLOR,clrGold);
ObjectSetInteger(0,Light, OBJPROP_FONTSIZE, 10);
ObjectSetInteger(0,Light,OBJPROP_XDISTANCE,20);
ObjectSetInteger(0,Light,OBJPROP_YDISTANCE,Pos+235);
ObjectSetString(0,Light, OBJPROP_FONT, "微軟正黑體");
ObjectSetString(0,Light,OBJPROP_TEXT,"");
}
double GetProfitPeriod(datetime today)
{
double profit=0;
int total =OrdersHistoryTotal();
for (int i=0; i<total; i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if (OrderType() == OP_BUY || OrderType() == OP_SELL)
{
if (today < OrderCloseTime())
profit += OrderProfit() + OrderCommission() + OrderSwap();
}
}
}
return (profit);
}
void WriteLog(const int Mode,const string in)
{
double TimesProfit = ((GetProfitPeriod(GlobalObj.Read_Start_P()) + AccountProfit()) / GlobalObj.Read_Start_Balance()) * 100;
string str = WindowExpertName() + "," + Symbol() + "," + TimeToString(TimeCurrent(),TIME_DATE|TIME_DATE|TIME_SECONDS) +
": " + LogText[Mode] + " , " + in +
"," + Start_Balance_str + ": " + DoubleToString(GlobalObj.Read_Start_Balance(),2) +
"," + Start_P_str + ": " + IntegerToString(GlobalObj.Read_Start_P()) +
",TimeProfit: " + DoubleToString(TimesProfit,2) +
"| Set: 餘:" + DoubleToString(iBalance,2) +
",次:" + DoubleToString(TakeProfitPercent,2) +
",次USD:" + DoubleToString(TakeProfitDollar,2) +
//",日:" + DoubleToString(TakeProfitPercentDay,2) +
",日USD:" + DoubleToString(TakeProfitDollarDay,2) +
",損:" + DoubleToStr(StopLossPercent ,2) +
",損USD:" + DoubleToStr(StopLossDollar ,2) +
",時:" + DoubleToString(MaxTime,2) +
",單:" + DoubleToString(MaxIn,2) +
",虧:" + DoubleToString(MaxP,2) +
"\n"
;
int h1 = FileOpen("Logs.txt",FILE_READ|FILE_WRITE|FILE_TXT);
if (h1 < 0) Print("Open Log Failed");
FileSeek(h1,0,SEEK_END);
uint byte = FileWriteString(h1,str,StringLen(str));
if (byte <= 0) Print("Write Log Failed");
FileClose(h1);
}
bool GlobalFileCheck()
{
string GlobalVars_EARunTime = "__G_EARunTime";
string GlobalVars_MaxEquity = "__G_MaxEquity";
string GlobalVars_Start_Balance = "__G_Start_Balance";
string GlobalVars_Start_P = "__G_Start_P";
string GlobalVars_EASW = "__G_EASW";
if (!GlobalVariableCheck(GlobalVars_EARunTime) ||
!GlobalVariableCheck(GlobalVars_MaxEquity) ||
!GlobalVariableCheck(GlobalVars_Start_Balance) ||
!GlobalVariableCheck(GlobalVars_Start_P) ||
!GlobalVariableCheck(GlobalVars_EASW))
{
return(false);
}
return(true);
}
//bool GlobalFileRead()
//{
// string GlobalVars_EARunTime = "__G_EARunTime";
// string GlobalVars_MaxEquity = "__G_MaxEquity";
// string GlobalVars_Start_Balance = "__G_Start_Balance";
// string GlobalVars_Start_P = "__G_Start_P";
//
// if (!GlobalVariableCheck(GlobalVars_EARunTime) ||
// !GlobalVariableCheck(GlobalVars_MaxEquity) ||
// !GlobalVariableCheck(GlobalVars_Start_Balance) ||
// !GlobalVariableCheck(GlobalVars_Start_P))
// {
// return(false);
// }
//
// double EARunTime_temp = 0.0;
// double Start_P_temp = 0.0;
//
// if (!GlobalVariableGet(GlobalVars_EARunTime,EARunTime_temp) ||
// !GlobalVariableGet(GlobalVars_Start_P,Start_P_temp) ||
// !GlobalVariableGet(GlobalVars_MaxEquity,GlobalVars.MaxEquity) ||
// !GlobalVariableGet(GlobalVars_Start_Balance,GlobalVars.Start_Balance))
// {
// return(false);
// }
//
// GlobalVars.EARunTime = (datetime)EARunTime_temp;
// GlobalVars.Start_P = (datetime)Start_P_temp;
//
// return(true);
//}
//bool GlobalFileWrite()
//{
// string GlobalVars_EARunTime = "__G_EARunTime";
// string GlobalVars_MaxEquity = "__G_MaxEquity";
// string GlobalVars_Start_Balance = "__G_Start_Balance";
// string GlobalVars_Start_P = "__G_Start_P";
//
// //if (!GlobalVariableCheck(GlobalVars_EARunTime) ||
// // !GlobalVariableCheck(GlobalVars_MaxEquity) ||
// // !GlobalVariableCheck(GlobalVars_Start_Balance) ||
// // !GlobalVariableCheck(GlobalVars_Start_P))
// //{
// // return(false);
// //}
//
// if (!GlobalVariableSet(GlobalVars_EARunTime,GlobalVars.EARunTime) ||
// !GlobalVariableSet(GlobalVars_Start_P,GlobalVars.Start_P) ||
// !GlobalVariableSet(GlobalVars_MaxEquity,GlobalVars.MaxEquity) ||
// !GlobalVariableSet(GlobalVars_Start_Balance,GlobalVars.Start_Balance))
// {
// return(false);
// }
//
// return(true);
//}
//bool GlobalFileRead()
//{
// int h1 = FileOpen(GlobalFile,FILE_SHARE_READ|FILE_BIN);
// if (h1 < 0)
// {
// return(false);
// }else
// {
// uint err = FileReadStruct(h1,GlobalVars);
// if (err == 0)
// {
// FileClose(h1);
// return(false);
// }
// FileClose(h1);
// }
// return(true);
//}
//
//bool GlobalFileWrite()
//{
// int h1 = FileOpen(GlobalFile,FILE_WRITE|FILE_BIN);
// if (h1 < 0)
// {
// return(false);
// }else
// {
// uint err = FileWriteStruct(h1,GlobalVars);
// if (err == 0)
// {
// Print("Write 0 Byte");
// FileClose(h1);
// return(false);
// }
// FileClose(h1);
// }
// return(true);
//}
void iCloseOrders(const int type)
{
int C0_cnt;
if (type == OP_SYMBOL)
{
for(C0_cnt=OrdersTotal()-1;C0_cnt>=0;C0_cnt--)
{
if (!OrderSelect(C0_cnt,SELECT_BY_POS,MODE_TRADES)) continue;
if (OrderSymbol() == Symbol())
{
if (OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP || OrderType() == OP_BUYLIMIT || OrderType() == OP_SELLLIMIT)
{
if (!OrderDelete(OrderTicket()))
{
ErrorCode = GetLastError();
if (ErrorCode != 4109)
Alert(ErrorDescription(ErrorCode));
}
}else {
if (!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),20,clrWhite))
{
ErrorCode = GetLastError();
if (ErrorCode != 4109)
Alert(ErrorDescription(ErrorCode));
}
}
}
}
}
if (type != OP_BUY && type != OP_SELL && type != OP_ALL)
{
for(C0_cnt=OrdersTotal()-1;C0_cnt>=0;C0_cnt--)
{
if (!OrderSelect(C0_cnt,SELECT_BY_POS,MODE_TRADES)) continue;
if (OrderSymbol()==Symbol()&&OrderType()==type){
if (!OrderDelete(OrderTicket()))
{
ErrorCode = GetLastError();
if (ErrorCode != 4109)
Alert(ErrorDescription(ErrorCode));
}
}
}
}
if (type == OP_BUY || type == OP_SELL)
{
for(C0_cnt=OrdersTotal()-1;C0_cnt>=0;C0_cnt--) //從最近一張單開始
{
if (!OrderSelect(C0_cnt,SELECT_BY_POS,MODE_TRADES)) continue;
if (OrderSymbol()==Symbol()&&OrderType()==type){
if (!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),20,clrWhite))
{
ErrorCode = GetLastError();
if (ErrorCode != 4109)
Alert(ErrorDescription(ErrorCode));
}
}
}
}
if (type == OP_ALL)
{
for(C0_cnt=OrdersTotal()-1;C0_cnt>=0;C0_cnt--)
{
if (!OrderSelect(C0_cnt,SELECT_BY_POS,MODE_TRADES)) continue;
if (OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP || OrderType() == OP_BUYLIMIT || OrderType() == OP_SELLLIMIT)
{
if (!OrderDelete(OrderTicket()))
{
ErrorCode = GetLastError();
if (ErrorCode != 4109)
Alert(ErrorDescription(ErrorCode));
}
}else {
if (!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),20,clrWhite))
{
ErrorCode = GetLastError();
if (ErrorCode != 4109)
Alert(ErrorDescription(ErrorCode));
}
}
}
}
}
void DeleteObjects()
{
string label_arr[8] =
{
"TimesProfitPer",
"Start_Balance",
"TimePast",
"Orders",
"TodayProfitPer",
"MaxLoss",
"NextInTime",
"EASW"
};
string label_arr1[8] =
{
"TimesProfitPer0",
"Start_Balance0",
"TimePast0",
"Orders0",
"TodayProfitPer0",
"MaxLoss0",
"NextInTime0",
"EASW0"
};
for (int i=ArraySize(label_arr)-1;i>=0;i--)
{
if(ObjectFind(label_arr[i]) >= 0) ObjectDelete(0,label_arr[i]);
if(ObjectFind(label_arr1[i]) >= 0) ObjectDelete(0,label_arr1[i]);
}
if(ObjectFind(Run) >= 0) ObjectDelete(0,Run);
//if (FileIsExist(EventFile)) FileDelete(EventFile);
}
void UpdateFiles(const int Mode)
{
if (Mode == MODE_INIT)
{
if (!GlobalVariableCheck("DNSW")) GlobalVariableSet("DNSW",0);
if (GlobalVariableSetOnCondition("DNSW",1,0))
{
if (UninitializeReason() != 3)
{
Sleep(1000);
}
}
}
if (Mode == MODE_TICK)
{
if (TimeHour(TimeLocal()) == DownloadHour && TimeMinute(TimeLocal()) == DownloadMin && H1BarTime != iTime(Symbol(),PERIOD_H1,0))
{
if (!GlobalVariableCheck("DNSW0")) GlobalVariableSet("DNSW0",0);
if (GlobalVariableSetOnCondition("DNSW0",1,0))
{
Sleep(1000);
GlobalVariableSet("DNSW0",0);
}
H1BarTime = iTime(Symbol(),PERIOD_H1,0);
}
}
}
int MyOrderTotalAccount(int Type)
{
int x=0;
for(int z=0;z<OrdersTotal();z++)
{
if (!OrderSelect(z,SELECT_BY_POS,MODE_TRADES)) continue;
if (OrderType() == Type)
{
x++;
}
}
return(x);
}
void ForceOutTime(int &ForceOutHour,int &ForceOutMin)
{
ForceOutHour = (int)StringToInteger(StringSubstr(ForceOut,0,StringFind(ForceOut,":",0)));
ForceOutMin = (int)StringToInteger(StringSubstr(ForceOut,StringFind(ForceOut,":",0)+1,StringLen(ForceOut) - (StringFind(ForceOut,":",0)+1)));
}
bool CheckSLTicket(const datetime StartTime)
{
for (int i=OrdersHistoryTotal()-1;i>=0;i--)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) continue;
if (OrderProfit() < 0 && StringFind(OrderComment(),"sl",0) >= 0 && OrderCloseTime() >= StartTime)
{
return(true);
}
}
return(false);
}
//+------------------------------------------------------------------+
//| SkyNet.mq4 |
//| APP Wargame-Hydra |
//| http://www.facebook.com/groups/moneywargame/ |
//+------------------------------------------------------------------+
#property copyright "APP Wargame-Hydra"
#property link "http://www.facebook.com/groups/moneywargame/"
#property version "1.00"
#property strict
#define SKYNET 1
#define NEW_WARGAMELIB 1
#define CURRVER "V01.09.00"
#include <WarGameLib.mqh>
#include <WinUser32.mqh>
#define NEW_A
//#define MODE_DEMO 1
#define MODE_AUTHOR 1
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
//input double Lots = 0.1; //手數
input double CPrice = 0; //中心線價格
bool AutoRepairSW = false; //自動判斷補單
int ARTF = 60; //自動判斷補單時區
input string a4 = "-------------------"; // 
input string DayStartTime = "00:00:00"; //開始時間,格式為HH:MM:SS
input string DayStopTime = "00:00:00"; //結束時間,格式為HH:MM:SS
input string WeekDay="123456"; //週一執行,鍵入1;週一週二鍵入12
input bool WeekStartOverSW = true; //一個禮拜頭尾不間斷
input string WeekStartTime = "08:00:00"; //第一天幾點開始,格式為HH:MM:SS
input string WeekStopTime = "17:00:00"; //最後一天幾點結束,格式為HH:MM:SS
input string a5 = "-------------------"; // 
input bool SkylineProtectSW = false; //天網保護裝置
input double FLots_Protect = 0.1; //第一張保護手數
input double LLots_Protect = 0.2; //最後一張保護手數
bool ChangeDir = false; //轉向開關
input double OrderRange_Protect = 5.0; //幾點外才補單
input string a6 = "-------------------"; // 
input bool ForceReset = false; //強制重啟新局
input string TXT0 = "-----------------------------"; // 
input double BuyUpLots = 0.01; //手數
input double BuyUpCPrice = 6; //Buy距中心線上方幾點
input int BuyUpOrders = 10; //中心線上方Buy單數
input double BuyUpStep = 20.0; //中心線上方Buy間格
input double BuyUpTP = 0.0; //中心線上方Buy獲利點數
input double BuyUpSL = 0.0; //中心線上方Buy停損點數
input double BuyUpLotsM = 1.0; //中心線上方Buy手數倍率
input bool BuyUpStopOrderSW = true; //中心線上方Buy Stop單開關
input bool BuyUpLimitOrderSW = true; //中心線上方Buy Limit單開關
input bool BuyUpSW = true; //出場後再補單開關
input double BuyUpOrderRange = 5.0; //幾點外才補單
input bool BuyUpFirstInSW = false; //初次下單是否受幾點外補單影響
input string TXT1 = "-----------------------------"; // 
input double SellUpLots = 0.01; //手數
input double SellUpCPrice = 6; //Sell距中心線上方幾點
input int SellUpOrders = 10; //中心線上方Sell單數
input double SellUpStep = 20.0; //中心線上方Sell間格
input double SellUpTP = 0.0; //中心線上方Sell獲利點數
input double SellUpSL = 0.0; //中心線上方Sell停損點數
input double SellUpLotsM = 1.0; //中心線上方Sell手數倍率
input bool SellUpStopOrderSW = true; //中心線上方Sell Stop單開關
input bool SellUpLimitOrderSW = true; //中心線上方Sell Limit單開關
input bool SellUpSW = true; //出場後再補單開關
input double SellUpOrderRange = 5.0; //幾點外才補單
input bool SellUpFirstInSW = false; //初次下單是否受幾點外補單影響
input string TXT2 = "-----------------------------"; //
input double BuyDownLots = 0.01; //手數 
input double BuyDownCPrice = 6; //Buy距中心線下方幾點
input int BuyDownOrders = 10; //中心線下方Buy單數
input double BuyDownStep = 20.0; //中心線下方Buy間格
input double BuyDownTP = 0.0; //中心線下方Buy獲利點數
input double BuyDownSL = 0.0; //中心線下方Buy停損點數
input double BuyDownLotsM = 1.0; //中心線下方Buy手數倍率
input bool BuyDownStopOrderSW = true; //中心線下方Buy Stop單開關
input bool BuyDownLimitOrderSW = true; //中心線下方Buy Limit單開關
input bool BuyDownSW = true; //出場後再補單開關
input double BuyDownOrderRange = 5.0; //幾點外才補單
input bool BuyDownFirstInSW = false;//初次下單是否受幾點外補單影響
input string TXT3 = "-----------------------------"; // 
input double SellDownLots = 0.01; //手數
input double SellDownCPrice = 6; //Sell距中心線下方幾點
input int SellDownOrders = 10; //中心線下方Sell單數
input double SellDownStep = 20.0; //中心線下方Sell間格
input double SellDownTP = 0.0; //中心線下方Sell獲利點數
input double SellDownSL = 0.0; //中心線下方Sell停損點數
input double SellDownLotsM = 1.0; //中心線下方Sell手數倍率
input bool SellDownStopOrderSW = true; //中心線下方Sell Stop單開關
input bool SellDownLimitOrderSW = true; //中心線下方Sell Limit單開關
input bool SellDownSW = true; //出場後再補單開關
input double SellDownOrderRange = 5.0; //幾點外才補單
input bool SellDownFirstInSW = false; //初次下單是否受幾點外補單影響
input string TXT4 = "-----------------------------"; // 
input bool ClearAllPend = false; //清除預掛單
input bool ClearAllArrow = false; //清除圖表箭頭
bool CommandDisplay = false;
struct ticket_struc
{
int order[];
double oprice[];
double lots[];
bool sw[];
datetime time[];
};
class GlobalFile_class
{
private:
string GlobalVars_EARunTime;
string GlobalVars_MaxEquity;
string GlobalVars_Start_Balance;
string GlobalVars_Start_P;
string GlobalVars_EASW;
public:
GlobalFile_class();
datetime Read_EARunTime();
double Read_MaxEquity();
double Read_Start_Balance();
datetime Read_Start_P();
int Read_EASW();
datetime Write_EARunTime(datetime);
datetime Write_MaxEquity(double);
datetime Write_Start_Balance(double);
datetime Write_Start_P(datetime);
datetime Write_EASW(int);
}GlobalObj;
void GlobalFile_class::GlobalFile_class()
{
GlobalVars_EARunTime = "__G_EARunTime";
GlobalVars_MaxEquity = "__G_MaxEquity";
GlobalVars_Start_Balance = "__G_Start_Balance";
GlobalVars_Start_P = "__G_Start_P";
GlobalVars_EASW = "__G_EASW";
}
datetime GlobalFile_class::Read_EARunTime()
{
return((datetime)GlobalVariableGet(GlobalVars_EARunTime));
}
double GlobalFile_class::Read_MaxEquity()
{
return(GlobalVariableGet(GlobalVars_MaxEquity));
}
double GlobalFile_class::Read_Start_Balance()
{
return(GlobalVariableGet(GlobalVars_Start_Balance));
}
datetime GlobalFile_class::Read_Start_P()
{
return((datetime)GlobalVariableGet(GlobalVars_Start_P));
}
int GlobalFile_class::Read_EASW()
{
return((int)GlobalVariableGet(GlobalVars_EASW));
}
datetime GlobalFile_class::Write_EARunTime(datetime inTime)
{
return(GlobalVariableSet(GlobalVars_EARunTime,inTime));
}
datetime GlobalFile_class::Write_MaxEquity(double inMaxEquity)
{
return(GlobalVariableSet(GlobalVars_MaxEquity,inMaxEquity));
}
datetime GlobalFile_class::Write_Start_Balance(double inStart_Balance)
{
return(GlobalVariableSet(GlobalVars_Start_Balance,inStart_Balance));
}
datetime GlobalFile_class::Write_Start_P(datetime inStart_P)
{
return(GlobalVariableSet(GlobalVars_Start_P,inStart_P));
}
datetime GlobalFile_class::Write_EASW(int inEASW)
{
return(GlobalVariableSet(GlobalVars_EASW,inEASW));
}
int id_1 = 83107121;
int id_2 = 83107122;
int Pend = 0;
int Market = 0;
bool InitSW = true;
bool GridSW = true;
bool OnceSW = true;
bool NewGetSW = false;
bool ClearSW = false;
//double UpBuyOrdersNum[][3] = {0};
//double DownBuyOrdersNum[][3] = {0};
//double UpSellOrdersNum[][3] = {0};
//double DownSellOrdersNum[][3] = {0};
ticket_struc UpBuyOrdersNum;
ticket_struc DownBuyOrdersNum;
ticket_struc UpSellOrdersNum;
ticket_struc DownSellOrdersNum;
int BuyUpSize = 0;
int BuyDownSize = 0;
int SellUpSize = 0;
int SellDownSize = 0;
string Comm_str = "";
//string NewsInfo[2] = {"NewsInfo0", "NewsInfo1"};
datetime BarTime = 0;
datetime StartTime = 0;
datetime MarketInTime = 0;
double iCPrice_temp = 0.0;
double temp = 0.0;
datetime temp_time = 0;
bool timerSwitch = true;
int newverMT4=1;
int accountMode=1;
string accountID="836685848547207712003728188444451105127785883063480237626581654545235641770673812083627580576101756005466171348506351718018477636640738024712447610326370743607336407840750431123515858787882858337116175315867043222431215716160410560707354632265722702582645";
string EndDate="078056226088564058147325163351668042665625580487527727070848364555136220168667182336200530684107467458184240761072013026064210412037270821623423154838710458724001833706723015346513187521281841184141761711068151412357157331260206615504132577761814210124420";
int OnInit()
{
//--- create timer
if (!CheckRemove(MODE_INIT)) return(-1);
point = PointConvert(point);
//StringInit(Comm_str);
InitCOrders();
StartTime = TimeCurrent();
if (!CheckInput())
{
Alert("Input Error");
return(-1);
}
MathSrand(GetTickCount());
DownloadMin = (uchar)(1 + ((59 * MathRand()) / 32768));
Print(DownloadMin);
//UpdateFiles(MODE_INIT);
int Timer_gap = 50 + ((199 * MathRand()) / 32768);
EventSetMillisecondTimer(Timer_gap);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- destroy timer
EventKillTimer();
WriteAllSets(0,temp,temp_time);
DeleteObjects();
GlobalVariableSet("DNSW",0);
GlobalVariableSet(IntegerToString(ChartID()),reason);
GlobalVariableSet("AutoOpenMutex",0);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTimer()
{
//---
if (!timerSwitch) return;
if (!CheckRemove(MODE_TICK)) return;
UpdateFiles(MODE_TICK);
if (!CheckFCR()) return;
//if (!GlobalFileRead()) Alert("SKY ERROR");
double TimesProfit = 0.0;
double TodayProfit = 0.0;
TimesStop(TimesProfit,TodayProfit);
Displayprofit(TimesProfit,TodayProfit);
DisplayCenter();
if (CommandDisplay)
{
Comm_str = "";
CommandDisplayF(UpBuyOrdersNum);
CommandDisplayF(DownBuyOrdersNum);
CommandDisplayF(UpSellOrdersNum);
CommandDisplayF(DownSellOrdersNum);
Comment(Comm_str);
}
if (ClearAllArrow)
{
for (int i=ObjectsTotal()-1;i>=0;i--)
{
string obj_str = ObjectName(i);
if (ObjectType(obj_str) == OBJ_ARROW && (StringFind(ObjectDescription(obj_str),"SkyNet") >= 0 || StringFind(obj_str,"modified") >= 0 ))
{
ObjectDelete(obj_str);
}
if (ObjectType(obj_str) == OBJ_TREND && (StringFind(ObjectDescription(obj_str),"LINE") >= 0))
{
ObjectDelete(obj_str);
}
}
}
if (ClearAllPend)
{
iCloseOrders(OP_SELLSTOP);
iCloseOrders(OP_SELLLIMIT);
iCloseOrders(OP_BUYSTOP);
iCloseOrders(OP_BUYLIMIT);
iCloseOrders(OP_SELLSTOP,id_2);
iCloseOrders(OP_SELLLIMIT,id_2);
iCloseOrders(OP_BUYSTOP,id_2);
iCloseOrders(OP_BUYLIMIT,id_2);
InitSW = true;
OnceSW = true;
return;
}
if (!EAControl()) return;
Timer();
if (MyOrderTotal(OP_ALL) == 0 && MyOrderTotal(OP_ALL,id_2) == 0)
{
InitSW = true;
OnceSW = true;
GridSW = true;
InitCOrders();
}
if (GridSW) GridSend();
WriteAllSets(0,temp,temp_time);
if (ChangeDir) CloseDirOrder();
//Comment("Buy: " + IntegerToString(Arrow(OP_BUY)) + "\n" + "Sell: " + IntegerToString(Arrow(OP_SELL)));
return;
}
//+------------------------------------------------------------------+
//| Timer function |
//+------------------------------------------------------------------+
void Timer()
{
CheckSlip(UpBuyOrdersNum,(AutoRepairSW ? Arrow(OP_BUY) : BuyUpSW),OP_BUY,BuyUpStopOrderSW,BuyUpLimitOrderSW,BuyUpFirstInSW);
CheckSlip(DownBuyOrdersNum,(AutoRepairSW ? Arrow(OP_BUY) : BuyDownSW),OP_BUY,BuyDownStopOrderSW,BuyDownLimitOrderSW,BuyDownFirstInSW);
CheckSlip(UpSellOrdersNum,(AutoRepairSW ? Arrow(OP_SELL) : SellUpSW),OP_SELL,SellUpStopOrderSW,SellUpLimitOrderSW,SellUpFirstInSW);
CheckSlip(DownSellOrdersNum,(AutoRepairSW ? Arrow(OP_SELL) : SellDownSW),OP_SELL,SellDownStopOrderSW,SellDownLimitOrderSW,SellDownFirstInSW);
CheckArray(UpBuyOrdersNum);
CheckArray(DownBuyOrdersNum);
CheckArray(UpSellOrdersNum);
CheckArray(DownSellOrdersNum);
}
//+------------------------------------------------------------------+
void InitCOrders()
{
double iCPrice = 0.0;
if (InitSW)
{
if (EqualZero(CPrice))
{
iCPrice = Bid;
}else
{
iCPrice = CPrice;
}
if (MyOrderTotal(OP_ALL) == 0 && MyOrderTotal(OP_ALL,id_2) == 0)
{
CreatePriceArray(UpBuyOrdersNum,1,iCPrice,BuyUpCPrice,BuyUpStep,BuyUpOrders,BuyUpSize,BuyUpLots,BuyUpLotsM,OP_BUY,(AutoRepairSW ? Arrow(OP_BUY) : BuyUpSW));
CreatePriceArray(DownBuyOrdersNum,-1,iCPrice,BuyDownCPrice,BuyDownStep,BuyDownOrders,BuyDownSize,BuyDownLots,BuyDownLotsM,OP_BUY,(AutoRepairSW ? Arrow(OP_BUY) : BuyDownSW));
CreatePriceArray(UpSellOrdersNum,1,iCPrice,SellUpCPrice,SellUpStep,SellUpOrders,SellUpSize,SellUpLots,SellUpLotsM,OP_SELL,(AutoRepairSW ? Arrow(OP_SELL) : SellUpSW));
CreatePriceArray(DownSellOrdersNum,-1,iCPrice,SellDownCPrice,SellDownStep,SellDownOrders,SellDownSize,SellDownLots,SellDownLotsM,OP_SELL,(AutoRepairSW ? Arrow(OP_SELL) : SellDownSW));
WriteAllSets(1,iCPrice,MarketInTime);
}else
{
if (
!CheckFileSize(Symbol() + "_10.bin") ||
!CheckFileSize(Symbol() + "_00.bin") ||
!CheckFileSize(Symbol() + "_11.bin") ||
!CheckFileSize(Symbol() + "_01.bin") ||
!CheckFileSize(Symbol() + "_Set.bin") ||
!FileIsExist(Symbol() + "_10.bin") ||
!FileIsExist(Symbol() + "_00.bin") ||
!FileIsExist(Symbol() + "_11.bin") ||
!FileIsExist(Symbol() + "_01.bin") ||
!FileIsExist(Symbol() + "_Set.bin") ||
ForceReset
)
{
int Ans = MessageBox("場上有單且偵測不到上次進場點,立刻強制重新開始?,請先確認場尚無預掛單才可重新開始。","確認",MB_YESNO);
if (Ans != IDYES)
{
GridSW = false;
return;
}
if (!ForceReset && FileIsExist(Symbol() + "_Set.bin")) ReadSet(Symbol() + "_Set.bin",iCPrice,MarketInTime);
CreatePriceArray(UpBuyOrdersNum,1,iCPrice,BuyUpCPrice,BuyUpStep,BuyUpOrders,BuyUpSize,BuyUpLots,BuyUpLotsM,OP_BUY,(AutoRepairSW ? Arrow(OP_BUY) : BuyUpSW));
CreatePriceArray(DownBuyOrdersNum,-1,iCPrice,BuyDownCPrice,BuyDownStep,BuyDownOrders,BuyDownSize,BuyDownLots,BuyDownLotsM,OP_BUY,(AutoRepairSW ? Arrow(OP_BUY) : BuyDownSW));
CreatePriceArray(UpSellOrdersNum,1,iCPrice,SellUpCPrice,SellUpStep,SellUpOrders,SellUpSize,SellUpLots,SellUpLotsM,OP_SELL,(AutoRepairSW ? Arrow(OP_SELL) : SellUpSW));
CreatePriceArray(DownSellOrdersNum,-1,iCPrice,SellDownCPrice,SellDownStep,SellDownOrders,SellDownSize,SellDownLots,SellDownLotsM,OP_SELL,(AutoRepairSW ? Arrow(OP_SELL) : SellDownSW));
WriteAllSets(1,iCPrice,MarketInTime);
}
ReadAllSets(1,iCPrice,MarketInTime);
//CheckAllArrayTotal(UpBuyOrdersNum,iCPrice,BuyUpCPrice,BuyUpStep,BuyUpOrders,BuyUpLotsM,(AutoRepairSW ? Arrow(OP_BUY) : BuyUpSW),Symbol() + "_10.bin");
//CheckAllArrayTotal(DownBuyOrdersNum,iCPrice,BuyDownCPrice,BuyDownStep,BuyDownOrders,BuyDownLotsM,(AutoRepairSW ? Arrow(OP_BUY) : BuyDownSW),Symbol() + "_00.bin");
//CheckAllArrayTotal(UpSellOrdersNum,iCPrice,SellUpCPrice,SellUpStep,SellUpOrders,SellUpLotsM,(AutoRepairSW ? Arrow(OP_SELL) : SellUpSW),Symbol() + "_11.bin");
//CheckAllArrayTotal(DownSellOrdersNum,iCPrice,SellDownCPrice,SellDownStep,SellDownOrders,SellDownLotsM,(AutoRepairSW ? Arrow(OP_SELL) : SellDownSW),Symbol() + "_01.bin");
//ReadAllSets(1,iCPrice,MarketInTime);
}
InitSW = false;
iCPrice_temp = iCPrice;
}
}
void GridSend()
{
if (OnceSW)
{
CreateSendArray(UpBuyOrdersNum,OP_BUY,BuyUpSL,BuyUpTP,BuyUpSize,(AutoRepairSW ? Arrow(OP_BUY) : true),1,BuyUpStopOrderSW,BuyUpLimitOrderSW,BuyUpFirstInSW,BuyUpOrderRange);
CreateSendArray(DownBuyOrdersNum,OP_BUY,BuyDownSL,BuyDownTP,BuyDownSize,(AutoRepairSW ? Arrow(OP_BUY) : true),-1,BuyDownStopOrderSW,BuyDownLimitOrderSW,BuyDownFirstInSW,BuyDownOrderRange);
CreateSendArray(UpSellOrdersNum,OP_SELL,SellUpSL,SellUpTP,SellUpSize,(AutoRepairSW ? Arrow(OP_SELL) : true),1,SellUpStopOrderSW,SellUpLimitOrderSW,SellUpFirstInSW,SellUpOrderRange);
CreateSendArray(DownSellOrdersNum,OP_SELL,SellDownSL,SellDownTP,SellDownSize,(AutoRepairSW ? Arrow(OP_SELL) : true),-1,SellDownStopOrderSW,SellDownLimitOrderSW,SellDownFirstInSW,SellDownOrderRange);
OnceSW = false;
}else
{
CreateSendArray(UpBuyOrdersNum,OP_BUY,BuyUpSL,BuyUpTP,BuyUpSize,(AutoRepairSW ? Arrow(OP_BUY) : BuyUpSW),1,BuyUpStopOrderSW,BuyUpLimitOrderSW,BuyUpFirstInSW,BuyUpOrderRange);
CreateSendArray(DownBuyOrdersNum,OP_BUY,BuyDownSL,BuyDownTP,BuyDownSize,(AutoRepairSW ? Arrow(OP_BUY) : BuyDownSW),-1,BuyDownStopOrderSW,BuyDownLimitOrderSW,BuyDownFirstInSW,BuyDownOrderRange);
CreateSendArray(UpSellOrdersNum,OP_SELL,SellUpSL,SellUpTP,SellUpSize,(AutoRepairSW ? Arrow(OP_SELL) : SellUpSW),1,SellUpStopOrderSW,SellUpLimitOrderSW,SellUpFirstInSW,SellUpOrderRange);
CreateSendArray(DownSellOrdersNum,OP_SELL,SellDownSL,SellDownTP,SellDownSize,(AutoRepairSW ? Arrow(OP_SELL) : SellDownSW),-1,SellDownStopOrderSW,SellDownLimitOrderSW,SellDownFirstInSW,SellDownOrderRange);
}
if (SkylineProtectSW)
{
SkylineProtect(UpSellOrdersNum,OP_BUY);
SkylineProtect(DownBuyOrdersNum,OP_SELL);
}
}
int SendOrders(const int Type ,const string iComment,const double Price,const double iLots,const double iSL,const double iTP)
{
double TP = 0.0;
double SL = 0.0;
double InPrice = 0.0;
switch (Type)
{
case OP_BUY:
InPrice = Ask;
break;
case OP_SELL:
InPrice = Bid;
break;
default:
InPrice = Price;
break;
}
if (Type == OP_BUYSTOP || Type == OP_BUYLIMIT)
{
if (MathAbs(Price - Ask) / Point <= SymbolInfoInteger(NULL,SYMBOL_TRADE_STOPS_LEVEL))
{
return(-2);
}
}
if (Type == OP_SELLSTOP || Type == OP_SELLLIMIT)
{
if (MathAbs(Price - Bid) / Point <= SymbolInfoInteger(NULL,SYMBOL_TRADE_STOPS_LEVEL))
{
return(-2);
}
}
SL = ((Type == OP_BUY || Type == OP_BUYSTOP || Type == OP_BUYLIMIT) ? (InPrice - iSL * point) : (InPrice + iSL * point));
TP = ((Type == OP_BUY || Type == OP_BUYSTOP || Type == OP_BUYLIMIT) ? (InPrice + iTP * point) : (InPrice - iTP * point));
if (EqualZero(iSL)) SL = 0;
if (EqualZero(iTP)) TP = 0;
int Ticket = OrderSend(Symbol(),Type,iLots,InPrice,(int)(2 * (point / Point)),SL,TP,iComment,id_1,0,((Type & 1) == 1) ? clrRed : clrLime);
if (Ticket < 0)
{
ErrorCode = GetLastError();
if (ErrorCode != 4109)
Alert("Send " + iComment + " Order Error: " + ErrorDescription(ErrorCode));
}
return(Ticket);
}
int SendOrders(const int Type ,const string iComment,const double Price,const double iLots,const double iSL,const double iTP,const int iID)
{
double TP = 0.0;
double SL = 0.0;
double InPrice = 0.0;
switch (Type)
{
case OP_BUY:
InPrice = Ask;
break;
case OP_SELL:
InPrice = Bid;
break;
default:
InPrice = Price;
break;
}
if (Type == OP_BUYSTOP || Type == OP_BUYLIMIT)
{
if (MathAbs(Price - Ask) / Point <= SymbolInfoInteger(NULL,SYMBOL_TRADE_STOPS_LEVEL))
{
return(-2);
}
}
if (Type == OP_SELLSTOP || Type == OP_SELLLIMIT)
{
if (MathAbs(Price - Bid) / Point <= SymbolInfoInteger(NULL,SYMBOL_TRADE_STOPS_LEVEL))
{
return(-2);
}
}
SL = ((Type == OP_BUY || Type == OP_BUYSTOP || Type == OP_BUYLIMIT) ? (InPrice - iSL * point) : (InPrice + iSL * point));
TP = ((Type == OP_BUY || Type == OP_BUYSTOP || Type == OP_BUYLIMIT) ? (InPrice + iTP * point) : (InPrice - iTP * point));
if (EqualZero(iSL)) SL = 0;
if (EqualZero(iTP)) TP = 0;
int Ticket = OrderSend(Symbol(),Type,iLots,InPrice,(int)(2 * (point / Point)),SL,TP,iComment,iID,0,((Type & 1) == 1) ? clrRed : clrLime);
if (Ticket < 0)
{
ErrorCode = GetLastError();
if (ErrorCode != 4109)
Alert("Send " + iComment + " Order Error: " + ErrorDescription(ErrorCode));
}
return(Ticket);
}
void Set_SL_TP(const int Mode,const int Type,double iSL,double iTP)
{
double SL = 0.0;
double TP = 0.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)
{
if (Mode == MODE_SLTP_BYPOINT)
{
if (Type == OP_BUY || Type == OP_BUYSTOP || Type == OP_BUYLIMIT)
{
TP = OrderOpenPrice() + iTP * point;
SL = OrderOpenPrice() - iSL * point;
}
if (Type == OP_SELL || Type == OP_SELLSTOP || Type == OP_SELLLIMIT)
{
TP = OrderOpenPrice() - iTP * point;
SL = OrderOpenPrice() + iSL * point;
}
if (EqualZero(iTP)) TP = 0;
if (EqualZero(iSL)) SL = 0;
}else
{
SL = iSL;
TP = iTP;
}
if (iTP < 0)
{
TP = OrderTakeProfit();
}
if (iSL < 0)
{
SL = OrderStopLoss();
}
if ((CompareDouble(OrderStopLoss(),NormalizeDouble(SL,Digits))) && (CompareDouble(OrderTakeProfit(),NormalizeDouble(TP,Digits))))
{
continue;
}
else
{
RefreshRates();
if (!OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP,0,White))
{
Alert("Set_SL_TP " + IntegerToString(OrderTicket()) + " Error: " + ErrorDescription(GetLastError()));
}
}
}
}
}
int OutOrderType(const double inPrice,const int Type)
{
if (Type == OP_BUY)
{
if (inPrice > Ask)
{
return(OP_BUYSTOP);
}else if (inPrice < Ask)
{
return(OP_BUYLIMIT);
}
}
if (Type == OP_SELL)
{
if (inPrice > Bid)
{
return(OP_SELLLIMIT);
}else if (inPrice < Bid)
{
return(OP_SELLSTOP);
}
}
return(-1);
}
bool OrderExist(const double iPrice,const int Type)
{
for (int i=0;i<OrdersTotal();i++)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if (Type == OP_BUY)
{
if (OrderMagicNumber() == id_1 && OrderSymbol() == Symbol() && (OrderType() == OP_BUYSTOP || OrderType() == OP_BUY || OrderType() == OP_BUYLIMIT))
{
if (CompareDouble(OrderOpenPrice(),iPrice))
{
return(false);
}
}
}
if (Type == OP_SELL)
{
if (OrderMagicNumber() == id_1 && OrderSymbol() == Symbol() && (OrderType() == OP_SELLSTOP || OrderType() == OP_SELL || OrderType() == OP_SELLLIMIT))
{
if (CompareDouble(OrderOpenPrice(),iPrice))
{
return(false);
}
}
}
}
/*if (
iPrice >= ((Type == OP_BUY) ? Ask : Bid) + ProtecServerRange * point ||
iPrice <= ((Type == OP_BUY) ? Ask : Bid) - ProtecServerRange * point
)
{
return(false);
}*/
return(true);
}
bool OrderExist(const double iPrice,const int Type,const int ID)
{
for (int i=0;i<OrdersTotal();i++)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if (Type == OP_BUY)
{
if (OrderMagicNumber() == ID && OrderSymbol() == Symbol() && (OrderType() == OP_BUYSTOP || OrderType() == OP_BUY || OrderType() == OP_BUYLIMIT))
{
if (CompareDouble(OrderOpenPrice(),iPrice))
{
return(false);
}
}
}
if (Type == OP_SELL)
{
if (OrderMagicNumber() == ID && OrderSymbol() == Symbol() && (OrderType() == OP_SELLSTOP || OrderType() == OP_SELL || OrderType() == OP_SELLLIMIT))
{
if (CompareDouble(OrderOpenPrice(),iPrice))
{
return(false);
}
}
}
}
return(true);
}
void iCloseOrders(const int type)
{
int C0_cnt;
if (type != OP_BUY && type != OP_SELL && type != OP_ALL)
{
for(C0_cnt=OrdersTotal()-1;C0_cnt>=0;C0_cnt--)
{
if (!OrderSelect(C0_cnt,SELECT_BY_POS,MODE_TRADES)) continue;
if (OrderSymbol()==Symbol()&&OrderType()==type && OrderMagicNumber()==id_1){
if (!OrderDelete(OrderTicket()))
{
ErrorCode = GetLastError();
if (ErrorCode != 4109)
Alert(ErrorDescription(ErrorCode));
}
}
}
}
if (type == OP_BUY || type == OP_SELL)
{
for(C0_cnt=OrdersTotal()-1;C0_cnt>=0;C0_cnt--) //從最近一張單開始
{
if (!OrderSelect(C0_cnt,SELECT_BY_POS,MODE_TRADES)) continue;
if (OrderSymbol()==Symbol()&&OrderType()==type && OrderMagicNumber()==id_1){
if (!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),clrLime))
{
ErrorCode = GetLastError();
if (ErrorCode != 4109)
Alert(ErrorDescription(ErrorCode));
}
}
}
}
if (type == OP_ALL)
{
for(C0_cnt=OrdersTotal()-1;C0_cnt>=0;C0_cnt--)
{
if (!OrderSelect(C0_cnt,SELECT_BY_POS,MODE_TRADES)) continue;
if (OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP || OrderType() == OP_BUYLIMIT || OrderType() == OP_SELLLIMIT)
{
if (!OrderDelete(OrderTicket()))
{
ErrorCode = GetLastError();
if (ErrorCode != 4109)
Alert(ErrorDescription(ErrorCode));
}
}else {
if (!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),clrRed))
{
ErrorCode = GetLastError();
if (ErrorCode != 4109)
Alert(ErrorDescription(ErrorCode));
}
}
}
}
}
void iCloseOrders(const int type,const int ID)
{
int C0_cnt;
if (type != OP_BUY && type != OP_SELL && type != OP_ALL)
{
for(C0_cnt=OrdersTotal()-1;C0_cnt>=0;C0_cnt--)
{
if (!OrderSelect(C0_cnt,SELECT_BY_POS,MODE_TRADES)) continue;
if (OrderSymbol()==Symbol()&&OrderType()==type && OrderMagicNumber()==ID){
if (!OrderDelete(OrderTicket()))
{
ErrorCode = GetLastError();
if (ErrorCode != 4109)
Alert(ErrorDescription(ErrorCode));
}
}
}
}
if (type == OP_BUY || type == OP_SELL)
{
for(C0_cnt=OrdersTotal()-1;C0_cnt>=0;C0_cnt--) //從最近一張單開始
{
if (!OrderSelect(C0_cnt,SELECT_BY_POS,MODE_TRADES)) continue;
if (OrderSymbol()==Symbol()&&OrderType()==type && OrderMagicNumber()==ID){
if (!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),clrLime))
{
ErrorCode = GetLastError();
if (ErrorCode != 4109)
Alert(ErrorDescription(ErrorCode));
}
}
}
}
if (type == OP_ALL)
{
for(C0_cnt=OrdersTotal()-1;C0_cnt>=0;C0_cnt--)
{
if (!OrderSelect(C0_cnt,SELECT_BY_POS,MODE_TRADES)) continue;
if (OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP || OrderType() == OP_BUYLIMIT || OrderType() == OP_SELLLIMIT)
{
if (!OrderDelete(OrderTicket()))
{
ErrorCode = GetLastError();
if (ErrorCode != 4109)
Alert(ErrorDescription(ErrorCode));
}
}else {
if (!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),clrRed))
{
ErrorCode = GetLastError();
if (ErrorCode != 4109)
Alert(ErrorDescription(ErrorCode));
}
}
}
}
}
int MyOrderTotal(const int Type)
{
int x=0;
for(int z=0;z<OrdersTotal();z++)
{
if (!OrderSelect(z,SELECT_BY_POS,MODE_TRADES)) continue;
if (Type == OP_ALL && OrderSymbol() == Symbol() && OrderMagicNumber() == id_1)
{
x++;
continue;
}
if (OrderSymbol() == Symbol() && OrderType() == Type && OrderMagicNumber() == id_1)
{
x++;
}
}
return(x);
}
int MyOrderTotal(const int Type,const int ID)
{
int x=0;
for(int z=0;z<OrdersTotal();z++)
{
if (!OrderSelect(z,SELECT_BY_POS,MODE_TRADES)) continue;
if (Type == OP_ALL && OrderSymbol() == Symbol() && OrderMagicNumber() == ID)
{
x++;
continue;
}
if (OrderSymbol() == Symbol() && OrderType() == Type && OrderMagicNumber() == ID)
{
x++;
}
}
return(x);
}
void CreatePriceArray(ticket_struc &arr,const int Dir,const double iCPrice,const double Range,const double Step,const int Orders,int &Size,const double Lots,const double iMultiple,const int Type,const bool SW)
{
if (Orders == 0) return;
Size = Orders;
InitsStruct(arr,Orders,SW);
int index = 0;
CreateteArrayStep(arr.oprice,iCPrice,Range,Step,Dir);
CreateteArrayLots(arr.lots,Lots,iMultiple);
// if (Dir == 1)
// {
// arr.oprice[index] = iCPrice + Range * point;
// arr.lots[index] = Lots;
// arr.lots[index] = OutPutLots(arr.lots[index]);
// for (int i=1;i<ArraySize(arr.order);i++)
// {
// arr.oprice[i] = arr.oprice[i-1] + Step * point;
// arr.lots[i] = NormalizeDouble(arr.lots[i-1] * iMultiple,2);
// arr.lots[i] = OutPutLots(arr.lots[i]);
// }
// }
//
// if (Dir == 1)
// {
// arr.oprice[0] = iCPrice - Range * point;
// arr.lots[0] = Lots;
// arr.lots[0] = OutPutLots(arr.lots[0]);
// for (int i=1;i<ArraySize(arr.order);i++)
// {
// arr.oprice[i] = arr.oprice[i-1] - Step * point;
// arr.lots[i] = NormalizeDouble(arr.lots[i-1] * iMultiple,2);
// arr.lots[i] = OutPutLots(arr.lots[i]);
// }
// }
CheckOldTicketsArray(arr,Type);
}
void ModifyPriceArray(ticket_struc &arr,const int Dir,const double Step,const int Orders,const double iMultiple,const int Type)
{
if (Orders == 0) return;
int OldSize = ArraySize(arr.order);
if (OldSize == 0) return;
ArrayResize(arr.order,Orders);
ArrayResize(arr.oprice,Orders);
ArrayResize(arr.lots,Orders);
ArrayResize(arr.sw,Orders);
ArrayResize(arr.time,Orders);
if (Dir == 1)
{
for (int i=OldSize;i<ArraySize(arr.order);i++)
{
if (!ArrayDebug(arr,i)) Alert("參數與上次進場不同,請重新設定或強制重新開始!");
arr.order[i] = 0;
arr.oprice[i] = arr.oprice[i-1] + Step * point;
arr.lots[i] = NormalizeDouble(arr.lots[i-1] * iMultiple,2);
arr.lots[i] = OutPutLots(arr.lots[i]);
arr.sw[i] = true;
}
}
if (Dir == -1)
{
for (int i=OldSize;i<ArraySize(arr.order);i++)
{
if (!ArrayDebug(arr,i)) Alert("參數與上次進場不同,請重新設定或強制重新開始!");
arr.order[i] = 0;
arr.oprice[i] = arr.oprice[i-1] - Step * point;
arr.lots[i] = NormalizeDouble(arr.lots[i-1] * iMultiple,2);
arr.lots[i] = OutPutLots(arr.lots[i]);
arr.sw[i] = true;
}
}
}
void CreateSendArray(ticket_struc &arr,const int Type,const double SL,const double TP,const int Orders,const bool SW,const int Dir,const bool StopSW,const bool LimitSW,const bool iFirstInSW,const double OrderRange)
{
if (Orders == 0) return;
int StartIndex = -1;
int BuyCnt = 0;
int SellCnt = 0;
int Ticket = 0;
double MarketPrice = (Type == OP_BUY ? Ask : Bid);
int Up[];
int Down[];
GetUpDownOrder(arr,Up,Down,MarketPrice,(Dir == 1 ? 1 : 0),iFirstInSW,OrderRange);
for(int i=0;i<ArraySize(Up);i++)
{
if (arr.sw[Up[i]] && SW)
{
if (OutOrderType(arr.oprice[Up[i]],Type) == -1) continue;
if (!StopSW && OutOrderType(arr.oprice[Up[i]],Type) == Type + 4) continue;
if (!LimitSW && OutOrderType(arr.oprice[Up[i]],Type) == Type + 2) continue;
arr.order[Up[i]] = SendOrders(OutOrderType(arr.oprice[Up[i]],Type),"SkyNet: " + IntegerToString(Type) + "|" + IntegerToString(Up[i]),arr.oprice[Up[i]],arr.lots[Up[i]],SL,TP);
if (arr.order[Up[i]] > 0)
{
arr.sw[Up[i]] = false;
if (OrderSelect(arr.order[Up[i]],SELECT_BY_TICKET,MODE_TRADES))
arr.time[Up[i]] = OrderOpenTime();
}
//Set_SL_TP(MODE_SLTP_BYPOINT,OutOrderType(arr.oprice[Up[i]],Type),SL,TP);
}
}
for(int i=0;i<ArraySize(Down);i++)
{
if (arr.sw[Down[i]] && SW)
{
if (OutOrderType(arr.oprice[Down[i]],Type) == -1) continue;
if (!StopSW && OutOrderType(arr.oprice[Down[i]],Type) == Type + 4) continue;
if (!LimitSW && OutOrderType(arr.oprice[Down[i]],Type) == Type + 2) continue;
arr.order[Down[i]] = SendOrders(OutOrderType(arr.oprice[Down[i]],Type),"SkyNet: " + IntegerToString(Type) + "|" + IntegerToString(Down[i]),arr.oprice[Down[i]],arr.lots[Down[i]],SL,TP);
if (arr.order[Down[i]] > 0)
{
arr.sw[Down[i]] = false;
if (OrderSelect(arr.order[Down[i]],SELECT_BY_TICKET,MODE_TRADES))
arr.time[Down[i]] = OrderOpenTime();
}
//et_SL_TP(MODE_SLTP_BYPOINT,OutOrderType(arr.oprice[Down[i]],Type),SL,TP);
}
}
}
double GetProfitPeriod(datetime today)
{
double profit=0;
int total =OrdersHistoryTotal();
for (int i=0; i<total; i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if (OrderType() == OP_BUY || OrderType() == OP_SELL)
{
if (today < OrderCloseTime())
profit += OrderProfit() + OrderCommission() + OrderSwap();
}
}
}
return (profit);
}
double OutPutLots(const double iLots)
{
if (iLots >= SymbolInfoDouble(NULL,SYMBOL_VOLUME_MAX)) return(SymbolInfoDouble(NULL,SYMBOL_VOLUME_MAX));
if (iLots <= SymbolInfoDouble(NULL,SYMBOL_VOLUME_MIN)) return(SymbolInfoDouble(NULL,SYMBOL_VOLUME_MIN));
return(iLots);
}
bool CheckInput()
{
if (
!CheckRange(BuyUpStep) ||
!CheckRange(SellUpStep) ||
!CheckRange(BuyDownStep) ||
!CheckRange(SellDownStep)
)
{
return(false);
}
return(true);
}
bool CheckRange(const double iRange)
{
if (iRange < 1.0)
{
return(false);
}
return(true);
}
void UpdateFiles(const int Mode)
{
if (Mode == MODE_INIT)
{
if (!GlobalVariableCheck("DNSW")) GlobalVariableSet("DNSW",0);
if (GlobalVariableSetOnCondition("DNSW",1,0))
{
#ifdef MODE_AREA51
RebuildNewsArray();
#endif
if (UninitializeReason() != 3)
{
#ifdef MODE_AREA51
if (ArraySize(AvoidTime) <= 1) NewGetSW = true;
else
{
if (TimeLocal() >= AvoidTime[ArraySize(AvoidTime)-1] + MinAfter)
{
NewGetSW = true;
}
}
#endif
Sleep(1000);
}
}
}
if (Mode == MODE_TICK)
{
if (
(TimeHour(TimeLocal()) == DownloadHour && TimeMinute(TimeLocal()) == DownloadMin && H1BarTime != iTime(Symbol(),PERIOD_H1,0)) ||
NewGetSW
)
{
if (!GlobalVariableCheck("DNSW0")) GlobalVariableSet("DNSW0",0);
if (GlobalVariableSetOnCondition("DNSW0",1,0))
{
if (!NewGetSW)
{
Sleep(1000);
}
Sleep(1000);
#ifdef MODE_AREA51
RebuildNewsArray();
#endif
GlobalVariableSet("DNSW0",0);
NewGetSW = false;
}
H1BarTime = iTime(Symbol(),PERIOD_H1,0);
}
}
}
//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);
//}
int iArrow_Signal(const int PTF)
{
double Arrow0 = 0.0;
double Arrow1 = 0.0;
for (int i=1;i<1024;i++)
{
Arrow0 = iCustom(Symbol(),PTF,"Arrow",false,0,i);
Arrow1 = iCustom(Symbol(),PTF,"Arrow",false,1,i);
if (Arrow1 == EMPTY_VALUE && Arrow0 != EMPTY_VALUE && Arrow0 > 0)
{
return(1);
}
if (Arrow0 == EMPTY_VALUE && Arrow1 != EMPTY_VALUE && Arrow1 > 0)
{
return(-1);
}
}
return(0);
}
bool Arrow(const int Type)
{
if (Type == OP_BUY)
{
if (iArrow_Signal(ARTF) == 1)
{
return(true);
}
}
if (Type == OP_SELL)
{
if (iArrow_Signal(ARTF) == -1)
{
return(true);
}
}
return(false);
}
void SkylineProtect(ticket_struc &arr,const int Type)
{
int LastOrder = ArraySize(arr.order) - 1;
if (LastOrder < 0) return;
SkylineProtect_(arr,Type,0,FLots_Protect);
SkylineProtect_(arr,Type,LastOrder,LLots_Protect);
}
void SkylineProtect_(ticket_struc &arr,const int Type,const int i,const double iLots)
{
if (EqualZero(iLots)) return;
int SendType = OutOrderType(arr.oprice[i],Type);
if (SendType == Type + 2) return;
double MarketPrice = (Type == OP_BUY ? Ask : Bid);
if (arr.oprice[i] < MarketPrice + OrderRange_Protect * point && arr.oprice[i] > MarketPrice - OrderRange_Protect * point) return;
if (OrderExist(arr.oprice[i],Type,id_2))
{
SendOrders(SendType,"SkyNet: " + IntegerToString(Type) + "|" + IntegerToString(i),arr.oprice[i],iLots,0.0,0.0,id_2);
}
}
bool iKBarColor(const int Type)
{
double Value1 =iCustom(Symbol(),ARTF,"BombRemovable1",Red,SkyBlue,Red,SkyBlue,1,0);
double Value2 =iCustom(Symbol(),ARTF,"BombRemovable1",Red,SkyBlue,Red,SkyBlue,3,0);
if (Type == OP_BUY)
{
if (Value1 > Value2)
{
return(true);
}
}
if (Type == OP_SELL)
{
if (Value1 < Value2)
{
return(true);
}
}
return(false);
}
void CloseDirOrder()
{
if (Arrow(OP_BUY))
{
iCloseOrders(OP_SELLSTOP);
iCloseOrders(OP_SELLLIMIT);
}
if (Arrow(OP_SELL))
{
iCloseOrders(OP_BUYSTOP);
iCloseOrders(OP_BUYLIMIT);
}
}
void DeleteObjects()
{
string label_arr[8] =
{
"TimesProfitPer",
"Start_Balance",
"TimePast",
"Orders",
"TodayProfitPer",
"MaxLoss",
"NextInTime",
"EASW"
};
string label_arr1[8] =
{
"TimesProfitPer0",
"Start_Balance0",
"TimePast0",
"Orders0",
"TodayProfitPer0",
"MaxLoss0",
"NextInTime0",
"EASW0"
};
for (int i=ArraySize(label_arr)-1;i>=0;i--)
{
if(ObjectFind(label_arr[i]) >= 0) ObjectDelete(0,label_arr[i]);
if(ObjectFind(label_arr1[i]) >= 0) ObjectDelete(0,label_arr1[i]);
}
for (int i=1;i>=0;i--)
{
if(ObjectFind(NewsInfo[i]) >= 0) ObjectDelete(0,NewsInfo[i]);
}
if(ObjectFind(Run) >= 0) ObjectDelete(0,Run);
//if (FileIsExist(EventFile)) FileDelete(EventFile);
if (ObjectFind("CenterLine") < 0) ObjectDelete(0,"CenterLine");
}
void WriteStruct(const string file,ticket_struc &arr,const int Size)
{
int h1 = FileOpen(file,FILE_WRITE|FILE_BIN);
if (h1 > 0)
{
FileWriteInteger(h1,Size,INT_VALUE);
FileWriteArray(h1,arr.order,0,Size);
FileWriteArray(h1,arr.oprice,0,Size);
FileWriteArray(h1,arr.lots,0,Size);
FileWriteArray(h1,arr.sw,0,Size);
FileWriteArray(h1,arr.time,0,Size);
}
FileClose(h1);
}
void ReadStruct(const string file,ticket_struc &arr,int &Size)
{
int h1 = FileOpen(file,FILE_READ|FILE_BIN);
if (h1 > 0)
{
Size = FileReadInteger(h1,INT_VALUE);
FileReadArray(h1,arr.order,0,Size);
FileReadArray(h1,arr.oprice,0,Size);
FileReadArray(h1,arr.lots,0,Size);
FileReadArray(h1,arr.sw,0,Size);
FileReadArray(h1,arr.time,0,Size);
}
FileClose(h1);
}
void WriteSet(const string file,const double Price,const datetime InTime)
{
int h1 = FileOpen(file,FILE_WRITE|FILE_BIN);
FileWriteDouble(h1,Price,DOUBLE_VALUE);
FileWriteInteger(h1,(int)InTime,INT_VALUE);
FileClose(h1);
}
void ReadSet(const string file,double &Price,datetime &InTime)
{
int h1 = FileOpen(file,FILE_READ|FILE_BIN);
Price = FileReadDouble(h1,DOUBLE_VALUE);
InTime = FileReadInteger(h1,INT_VALUE);
FileClose(h1);
}
void CheckAllArrayTotal(ticket_struc &arr,const double iCPrice,const double Range,const double Steps,const int Orders,const double iMultiple,const bool SW,const string file_name)
{
if (ArraySize(arr.order) != Orders)
{
ModifyPriceArray(arr,0,Steps,Orders,iMultiple,SW);
WriteStruct(file_name,arr,Orders);
//ReadStruct(file_name,arr);
}
}
void InitsStruct(ticket_struc &arr,const int size,const bool sw)
{
ArrayResize(arr.order,size);
ArrayResize(arr.oprice,size);
ArrayResize(arr.lots,size);
ArrayResize(arr.sw,size);
ArrayResize(arr.time,size);
if (size > 0)
{
ArrayFill(arr.order,0,size,0);
ArrayFill(arr.oprice,0,size,0.0);
ArrayFill(arr.lots,0,size,0.0);
ArrayFill(arr.sw,0,size,sw);
ArrayFill(arr.time,0,size,0);
}
}
void GetUpDownOrder(ticket_struc &arr,int &up[],int &down[],const double Price,const int Dir,const bool iFirstInSW,const double OrderRange)
{
//double arr_temp_oprice[];
double arr_temp[][2];
int arr_index_temp[];
ArrayResize(arr_temp,ArraySize(arr.oprice));
iArrayCopy(arr_temp,arr.oprice,0,0,ArraySize(arr.oprice));
iArrayCopy(arr_temp,arr.order,ArraySize(arr.oprice),0,ArraySize(arr.order));
//for (int i=0;i<ArrayRange(arr_temp,0);i++) Print(i + " | 0 ",arr_temp[i][0]);
//for (int i=0;i<ArrayRange(arr_temp,0);i++) Print(i + " | 1 ",arr_temp[i][1]);
//ArrayCopy(arr_temp,arr.order,ArraySize(arr.order),0,WHOLE_ARRAY);
if (!ArraySort(arr_temp,WHOLE_ARRAY,0,MODE_ASCEND)) Alert("參數與上次進場不同,請重新設定或強制重新開始!");
int Start = 0;
for (int i=0;i<ArrayRange(arr_temp,0);i++)
{
if (arr_temp[i][0] > Price && OutRangeSW((int)arr_temp[i][1],arr_temp[i][0],Price,iFirstInSW,OrderRange))
{
if (Start >= 3) break;
ArrayResize(up,Start+1);
up[Start] = (Dir == 1 ? i : (ArrayRange(arr_temp,0) - 1 - i));
Start++;
}
}
ArraySort(arr_temp,WHOLE_ARRAY,0,MODE_DESCEND);
Start = 0;
for (int i=0;i<ArrayRange(arr_temp,0);i++)
{
if (Price > arr_temp[i][0] && OutRangeSW((int)arr_temp[i][1],arr_temp[i][0],Price,iFirstInSW,OrderRange))
{
if (Start >= 3) break;
ArrayResize(down,Start+1);
down[Start] = (Dir == 1 ? (ArrayRange(arr_temp,0) - 1 - i) : i);
Start++;
}
}
//
// int Start = 0;
// for (int i=0;i<ArraySize(arr_temp_oprice);i++)
// {
// //if (arr_temp_oprice[i] > Price && TicketSW(arr,arr_temp_oprice[i]))
// if (arr_temp_oprice[i] > Price && OutRangeSW(arr_temp_oprice[i],Price,iFirstInSW))
// {
// if (Start >= 5) break;
// ArrayResize(up,Start+1);
// up[Start] = (Dir == 1 ? i : (ArraySize(arr_temp_oprice) - 1 - i));
// Start++;
// }
// }
//
// ArraySort(arr_temp_oprice,WHOLE_ARRAY,0,MODE_DESCEND);
// Start = 0;
// for (int i=0;i<ArraySize(arr_temp_oprice);i++)
// {
// //if (Price > arr_temp_oprice[i] && TicketSW(arr,arr_temp_oprice[i]))
// if (Price > arr_temp_oprice[i] && OutRangeSW(arr_temp_oprice[i],Price,iFirstInSW))
// {
// if (Start >= 5) break;
// ArrayResize(down,Start+1);
// down[Start] = (Dir == 1 ? (ArraySize(arr_temp_oprice) - 1 - i) : i);
// Start++;
// }
// }
}
void CheckSlip(ticket_struc &arr,const bool SW,const int Type,const bool StopSW,const bool LimitSW,const bool iFirstInSW)
{
if (!SW) return;
double Price = (Type == OP_BUY ? Ask : Bid);
for (int i=0;i<ArraySize(arr.order);i++)
{
if (!ArrayDebug(arr,i)) Alert("參數與上次進場不同,請重新設定或強制重新開始!");
if (!TickValid(arr.order[i]))
{
if (arr.order[i] != 0)
{
//if (MathAbs(Price - arr.oprice[i]) / point >= OrderRange)
//{
//Print(i);
arr.sw[i] = true;
//}
}
//if (arr.order[i] == 0 && iFirstInSW)
//{
// if (MathAbs(Price - arr.oprice[i]) / point <= OrderRange)
// {
// arr.sw[i] = false;
// }
// //else
// //{
// // arr.sw[i] = true;
// //}
//}
//if (!StopSW && OutOrderType(arr.oprice[i],Type) == Type + 4) arr.sw[i] = false;
//if (!LimitSW && OutOrderType(arr.oprice[i],Type) == Type + 2) arr.sw[i] = false;
if (MarketInTime > arr.time[i])
{
arr.order[i] = 0;
arr.sw[i] = true;
}
}
}
}
bool TickValid(const int Ticket)
{
for (int i=0;i<OrdersTotal();i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if (OrderTicket() == Ticket)
{
return(true);
}
}
}
return(false);
}
int PendOrders()
{
int Out = 0;
for (int i=0;i<OrdersTotal();i++)
{
if (OrderType() > 1)
{
Out++;
}
}
return(Out);
}
int MarketOrders()
{
int Out = 0;
for (int i=0;i<OrdersTotal();i++)
{
if (OrderType() < 2)
{
Out++;
}
}
return(Out);
}
void WriteAllSets(const int Mode,double &iCPrice,datetime &InTime)
{
if (Mode == 1) WriteSet(Symbol() + "_Set.bin",iCPrice,InTime);
WriteStruct(Symbol() + "_10.bin",UpBuyOrdersNum,BuyUpOrders);
WriteStruct(Symbol() + "_00.bin",DownBuyOrdersNum,BuyDownOrders);
WriteStruct(Symbol() + "_11.bin",UpSellOrdersNum,SellUpOrders);
WriteStruct(Symbol() + "_01.bin",DownSellOrdersNum,SellDownOrders);
}
void ReadAllSets(const int Mode,double &iCPrice,datetime &InTime)
{
if (Mode == 1) ReadSet(Symbol() + "_Set.bin",iCPrice,InTime);
ReadStruct(Symbol() + "_10.bin",UpBuyOrdersNum,BuyUpSize);
ReadStruct(Symbol() + "_00.bin",DownBuyOrdersNum,BuyDownSize);
ReadStruct(Symbol() + "_11.bin",UpSellOrdersNum,SellUpSize);
ReadStruct(Symbol() + "_01.bin",DownSellOrdersNum,SellDownSize);
}
void CommandDisplayF(ticket_struc &arr)
{
for (int i=0;i<ArraySize(arr.oprice);i++)
{
Comm_str += IntegerToString(arr.order[i]) + "," +
DoubleToStr(arr.oprice[i],Digits) + "," +
DoubleToStr(arr.lots[i],Digits) + "," +
(arr.sw[i] == 0 ? " false " : " true ") + "," +
(TickValid(arr.order[i]) ? "Trade" : "History") + "," +
TimeToString(arr.time[i],TIME_DATE|TIME_MINUTES) + "," +
" SELL : " + DoubleToStr(MathAbs(arr.oprice[i] - Bid) / point,Digits) + "," +
" BUY : " + DoubleToStr(MathAbs(arr.oprice[i] - Ask) / point,Digits) + "\n";
}
Comm_str += "-----------------------\n";
}
//bool GlobalFileRead()
//{
// string GlobalVars_EARunTime = "__G_EARunTime";
// string GlobalVars_MaxEquity = "__G_MaxEquity";
// string GlobalVars_Start_Balance = "__G_Start_Balance";
// string GlobalVars_Start_P = "__G_Start_P";
//
// if (!GlobalVariableCheck(GlobalVars_EARunTime) ||
// !GlobalVariableCheck(GlobalVars_MaxEquity) ||
// !GlobalVariableCheck(GlobalVars_Start_Balance) ||
// !GlobalVariableCheck(GlobalVars_Start_P))
// {
// return(false);
// }
//
// double EARunTime_temp = 0.0;
// double Start_P_temp = 0.0;
//
// if (!GlobalVariableGet(GlobalVars_EARunTime,EARunTime_temp) ||
// !GlobalVariableGet(GlobalVars_Start_P,Start_P_temp) ||
// !GlobalVariableGet(GlobalVars_MaxEquity,GlobalVars.MaxEquity) ||
// !GlobalVariableGet(GlobalVars_Start_Balance,GlobalVars.Start_Balance))
// {
// return(false);
// }
//
// GlobalVars.EARunTime = (datetime)EARunTime_temp;
// GlobalVars.Start_P = (datetime)Start_P_temp;
//
// return(true);
//}
//bool GlobalFileRead()
//{
// int h1 = FileOpen(GlobalFile,FILE_SHARE_READ|FILE_BIN);
// if (h1 < 0)
// {
// return(false);
// }else
// {
// uint err = FileReadStruct(h1,GlobalVars);
// if (err == 0)
// {
// FileClose(h1);
// return(false);
// }
// FileClose(h1);
// }
// return(true);
//}
void Displayprofit(const double TimesProfit, const double TodayProfit)
{
string label_arr[8] =
{
"TimesProfitPer",
"Start_Balance",
"TimePast",
"Orders",
"TodayProfitPer",
"MaxLoss",
"NextInTime",
"EASW"
};
string label_arr1[8] =
{
"TimesProfitPer0",
"Start_Balance0",
"TimePast0",
"Orders0",
"TodayProfitPer0",
"MaxLoss0",
"NextInTime0",
"EASW0"
};
int Pos = 50;
string Label_Text = "";
string Label_Text1 = "";
if (ObjectFind(Run) < 0) ObjectCreate(0,Run,OBJ_LABEL,0,0,0);
ObjectSetInteger(0,Run, OBJPROP_CORNER, 1);
ObjectSetInteger(0,Run, OBJPROP_COLOR, clrGold);
ObjectSetInteger(0,Run, OBJPROP_XDISTANCE, 20);
ObjectSetInteger(0,Run, OBJPROP_YDISTANCE, Pos);
ObjectSetInteger(0,Run, OBJPROP_FONTSIZE, 10);
ObjectSetInteger(0,Run, OBJPROP_ANCHOR, ANCHOR_RIGHT_UPPER);
ObjectSetString(0,Run, OBJPROP_FONT, "微軟正黑體");
for (int i=0;i<ArraySize(NewsInfo);i++)
{
if (ObjectFind(NewsInfo[i]) < 0) ObjectCreate(0,NewsInfo[i],OBJ_LABEL,0,0,0);
ObjectSetInteger(0,NewsInfo[i], OBJPROP_CORNER, 1);
ObjectSetInteger(0,NewsInfo[i], OBJPROP_COLOR, clrGold);
ObjectSetInteger(0,NewsInfo[i], OBJPROP_XDISTANCE, 20);
ObjectSetInteger(0,NewsInfo[i], OBJPROP_ANCHOR, ANCHOR_RIGHT_UPPER);
ObjectSetInteger(0,NewsInfo[i], OBJPROP_YDISTANCE, Pos + 180 + i * 20);
ObjectSetInteger(0,NewsInfo[i], OBJPROP_FONTSIZE, 10);
ObjectSetString(0,NewsInfo[i], OBJPROP_FONT, "微軟正黑體");
}
for (int i=0;i<ArraySize(label_arr);i++)
{
if(ObjectFind(label_arr[i]) < 0) ObjectCreate(0,label_arr[i],OBJ_LABEL,0,0,0);
ObjectSetInteger(0,label_arr[i],OBJPROP_CORNER,1);
ObjectSetInteger(0,label_arr[i],OBJPROP_COLOR,White);
ObjectSetInteger(0,label_arr[i],OBJPROP_XDISTANCE,120);
ObjectSetInteger(0,label_arr[i],OBJPROP_YDISTANCE,Pos + 30 + 20 * i);
ObjectSetInteger(0,label_arr[i],OBJPROP_ANCHOR,ANCHOR_RIGHT);
ObjectSetString(0,label_arr[i],OBJPROP_FONT,"微軟正黑體");
if(ObjectFind(label_arr1[i]) < 0) ObjectCreate(0,label_arr1[i],OBJ_LABEL,0,0,0);
ObjectSetInteger(0,label_arr1[i],OBJPROP_CORNER,1);
ObjectSetInteger(0,label_arr1[i],OBJPROP_COLOR,White);
ObjectSetInteger(0,label_arr1[i],OBJPROP_XDISTANCE,20);
ObjectSetInteger(0,label_arr1[i],OBJPROP_YDISTANCE,Pos + 30 + 20 * i);
ObjectSetInteger(0,label_arr1[i],OBJPROP_ANCHOR,ANCHOR_RIGHT);
ObjectSetString(0,label_arr1[i],OBJPROP_FONT,"微軟正黑體");
switch(i)
{
case 0:
Label_Text = "單次擄獲狂派戰俘: ";
Label_Text1 = DoubleToString(TimesProfit,2) + " %";
break;
case 1:
Label_Text = "進場起始兵力: ";
Label_Text1 = DoubleToString(GlobalObj.Read_Start_Balance(),2);
break;
case 2:
Label_Text = "進場經過時間: " ;
Label_Text1 = DoubleToString((TimeCurrent() - GlobalObj.Read_Start_P()) / 60,1) + " 分鐘";
break;
case 3:
Label_Text = "戰場兵力: ";
Label_Text1 = IntegerToString(OrdersTotal());
break;
case 4:
Label_Text = "今日擄獲狂派戰俘累積至: " ;
Label_Text1 = DoubleToString(TodayProfit,2);
break;
case 5:
Label_Text = "最大暫時被擄穫兵力: ";
Label_Text1 = DoubleToString(GlobalObj.Read_MaxEquity(),2)+" %";
break;
case 6:
Label_Text = "下次進場時間: ";
Label_Text1 = StringSubstr(TimeToString(GlobalObj.Read_EARunTime(),TIME_DATE|TIME_MINUTES|TIME_SECONDS),5,14);
break;
case 7:
Label_Text = "";
Label_Text1 = (GlobalObj.Read_EASW() == 0 ? "止損後不再出兵" : "");
break;
}
ObjectSetString(0,label_arr[i],OBJPROP_TEXT,Label_Text);
ObjectSetString(0,label_arr1[i],OBJPROP_TEXT,Label_Text1);
}
}
bool TimesStop(double &TimesProfit, double &TodayProfit)
{
TimesProfit = ((GetProfitPeriod(GlobalObj.Read_Start_P()) + AccountProfit()) / GlobalObj.Read_Start_Balance()) * 100;
TodayProfit = ((GetProfitPeriod(StrToTime(TimeToStr(TimeCurrent(),TIME_DATE))) + AccountProfit()) / GlobalObj.Read_Start_Balance())* 100;
return(true);
}
void DisplayCenter()
{
ObjectSetString(0,NewsInfo[0],OBJPROP_TEXT,"中心線價位: " + DoubleToString(iCPrice_temp,Digits));
ObjectSetString(0,NewsInfo[1],OBJPROP_TEXT," ");
if (ObjectFind("CenterLine") < 0) ObjectCreate(0,"CenterLine",OBJ_HLINE,0,0,0);
else
{
ObjectSetInteger(0,"CenterLine",OBJPROP_COLOR,clrGold);
ObjectSetDouble(0,"CenterLine",OBJPROP_PRICE,iCPrice_temp);
ObjectSetInteger(0,"CenterLine",OBJPROP_WIDTH,2);
ObjectSetInteger(0,"CenterLine",OBJPROP_STYLE,STYLE_DOT);
}
}
void CheckOldTicketsArray(ticket_struc &arr,const int Type)
{
int index = 0;
for (int i=0;i<OrdersTotal();i++)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if (OrderMagicNumber() == id_1 && OrderType() == Type)
{
if (SearchArray(arr,OrderOpenPrice(),index))
{
arr.order[index] = OrderTicket();
arr.sw[index] = false;
arr.time[index] = OrderOpenTime();
}
}
}
}
bool SearchArray(ticket_struc &arr,const double iPrice,int &index)
{
for (int i=0;i<ArraySize(arr.oprice);i++)
{
if (CompareDouble(iPrice,arr.oprice[i]))
{
index = i;
return(true);
}
}
return(false);
}
void CreateteArrayStep(double &arr[],const double iCPrice,const double Range,const double Step,const int Direction)
{
for (int i=0;i<ArraySize(arr);i++)
{
if (i == 0)
{
arr[0] = iCPrice + Range * Direction * point;
continue;
}
arr[i] = arr[i-1] + Step * Direction * point;
}
}
void CreateteArrayLots(double &arr[],const double Lots,const double iMultiple)
{
for (int i=0;i<ArraySize(arr);i++)
{
arr[i] = NormalizeDouble(Lots * MathPow(iMultiple,i),2);
arr[i] = OutPutLots(arr[i]);
}
}
bool OutRangeSW(const int Ticket,const double TicketPrice,const double Price,const bool iFirstInSW,const double OrderRange)
{
if (iFirstInSW)
{
if (TicketPrice > Price + OrderRange * point || TicketPrice < Price - OrderRange * point)
{
return(true);
}
}else
{
if (Ticket == 0 || TickValid(Ticket))
{
return(true);
}else
{
if (TicketPrice > Price + OrderRange * point || TicketPrice < Price - OrderRange * point)
{
return(true);
}
}
}
return(false);
}
template<typename T1, typename T2>
void iArrayCopy(T1 &dst_arr[][],T2 &src_arr[],const int dst_start,const int src_start,const int count)
{
int cnt = 0;
int j = dst_start;
int k = 0;
for (int i=src_start;i<ArraySize(src_arr)&& ((count == WHOLE_ARRAY) ? true : (cnt<count));i++)
{
if (j >= ArrayRange(dst_arr,0))
{
k++;
j = 0;
}
dst_arr[j][k] = src_arr[i];
j++;
cnt++;
}
}
bool EAControl()
{
bool Out = true;
int EAOrders = MyOrderTotal(OP_BUY) + MyOrderTotal(OP_SELL) + MyOrderTotal(OP_BUY,id_2) + MyOrderTotal(OP_SELL,id_2);
if (!WeekStartOver() && EAOrders == 0)
{
if (MyOrderTotal(OP_BUYSTOP) > 0) iCloseOrders(OP_BUYSTOP);
if (MyOrderTotal(OP_SELLSTOP) > 0) iCloseOrders(OP_SELLSTOP);
if (MyOrderTotal(OP_BUYLIMIT) > 0) iCloseOrders(OP_BUYLIMIT);
if (MyOrderTotal(OP_SELLLIMIT) > 0) iCloseOrders(OP_SELLLIMIT);
if (MyOrderTotal(OP_BUYSTOP,id_2) > 0) iCloseOrders(OP_BUYSTOP,id_2);
if (MyOrderTotal(OP_SELLSTOP,id_2) > 0) iCloseOrders(OP_SELLSTOP,id_2);
if (MyOrderTotal(OP_BUYLIMIT,id_2) > 0) iCloseOrders(OP_BUYLIMIT,id_2);
if (MyOrderTotal(OP_SELLLIMIT,id_2) > 0) iCloseOrders(OP_SELLLIMIT,id_2);
Out = false;
}
if (TimeCurrent() <= GlobalObj.Read_EARunTime())
{
Out = false;
}
if (CompareDouble(GlobalVariableGet(NextSW_str),1)) Out = false;
if (GlobalObj.Read_EASW() == 0) Out = false;
return(Out);
}
bool WeekStartOver()
{
bool EA_Valid = false;
int Dayweek = TimeDayOfWeek(TimeLocal());
datetime in_StartTime;
datetime in_StopTime;
if (StringFind(WeekDay,IntegerToString(Dayweek),0) >= 0)
{
if (Dayweek > StrToInteger(StringSubstr(WeekDay,0,1)) && Dayweek < StrToInteger(StringSubstr(WeekDay,StringLen(WeekDay)-1,1)))
{
EA_Valid = (WeekStartOverSW ? true : iTimeControl());
}else if (Dayweek == StrToInteger(StringSubstr(WeekDay,0,1)))
{
in_StartTime = StringToTime(StringSubstr(TimeToString(TimeLocal(),TIME_DATE|TIME_MINUTES|TIME_SECONDS),0,10) + " " + WeekStartTime);
EA_Valid = iTimeControl(in_StartTime,0,true,false);
}else if (Dayweek == StrToInteger(StringSubstr(WeekDay,StringLen(WeekDay)-1,1)))
{
in_StopTime = StringToTime(StringSubstr(TimeToString(TimeLocal(),TIME_DATE|TIME_MINUTES|TIME_SECONDS),0,10) + " " + WeekStopTime);
EA_Valid = iTimeControl(0,in_StopTime,false,true);
}
}
if (!EA_Valid)
{
ObjectSetString(0,Run,OBJPROP_TEXT,"未在設定時區內,即將離開戰場");
return(false);
}
else
{
ObjectSetString(0,Run,OBJPROP_TEXT,"已進入作戰時區內,全面啟動執行...");
return(true);
}
}
bool iTimeControl(datetime in_StartTime=0,datetime in_StopTime=0,const bool Start=false,const bool End=false)
{
bool EA_Valid = false;
if (in_StartTime == 0) in_StartTime = StringToTime(StringSubstr(TimeToString(TimeLocal(),TIME_DATE|TIME_MINUTES|TIME_SECONDS),0,10) + " " + DayStartTime);
if (in_StopTime == 0) in_StopTime = StringToTime(StringSubstr(TimeToString(TimeLocal(),TIME_DATE|TIME_MINUTES|TIME_SECONDS),0,10) + " " + DayStopTime);
if (in_StopTime == in_StartTime && in_StopTime == in_StartTime) EA_Valid = true;
if (in_StopTime < in_StartTime)
{
//in_StartTime -= 86400;
//if (StringFind(WeekDay,IntegerToString(TimeDayOfWeek(in_StartTime)),0) < 0) in_StartTime = StringToTime(TimeToString(in_StartTime + 86400,TIME_DATE));
if (TimeLocal() >= in_StartTime || TimeLocal() < in_StopTime)
{
EA_Valid = true;
}
}
if (TimeLocal() >= in_StartTime && TimeLocal() < in_StopTime)
{
EA_Valid = true;
}
if (Start && TimeLocal() < in_StartTime)
{
EA_Valid = false;
}
if (End && TimeLocal() >= in_StopTime)
{
EA_Valid = false;
}
return(EA_Valid);
}
void AutoOpen()
{
long open_id = 0;
if (!GlobalVariableCheck("AutoOpenMutex")) GlobalVariableSet("AutoOpenMutex",0);
if (GlobalVariableSetOnCondition("AutoOpenMutex",1,0))
{
if (UninitializeReason() != 3)
{
if (!GlobalVariableCheck("AutoOpenChart")) GlobalVariableSet("AutoOpenChart",0);
if (EqualZero(GlobalVariableGet("AutoOpenChart")))
{
Alert("F.C.R. 模組未開啟");
//open_id = ChartOpen(SymbolName(SymbolsTotal(true)-1,true),PERIOD_D1);
//if (!FileIsExist("AutoOpen.tpl"))
//{
// int h1 = FileOpen("AutoOpen.tpl",FILE_WRITE|FILE_TXT);
// FileWrite(h1,"<chart>\n<expert>\nname=FireControlRadar\nflags=343\nwindow_num=0\n</expert>\n</chart>");
// FileClose(h1);
//}
//if (ChartApplyTemplate(open_id,"\\Files\\AutoOpen.tpl"))
//{
// GlobalVariableSet("AutoOpenChart",open_id);
//}
}
}
}
}
bool ArrayDebug(ticket_struc &arr,const int i)
{
bool Out = true;
if (i >= ArraySize(arr.order) || i < 0) {Print("order"); Out = false;}
if (i >= ArraySize(arr.oprice) || i < 0) {Print("oprice"); Out = false;}
if (i >= ArraySize(arr.lots) || i < 0) {Print("lots"); Out = false;}
if (i >= ArraySize(arr.sw) || i < 0) {Print("sw"); Out = false;}
if (i >= ArraySize(arr.time) || i < 0) {Print("time"); Out = false;}
return(Out);
}
bool CheckArray(ticket_struc &arr)
{
if (ArraySize(arr.order) != ArraySize(arr.oprice) ||
ArraySize(arr.oprice) != ArraySize(arr.lots) ||
ArraySize(arr.lots) != ArraySize(arr.sw) ||
ArraySize(arr.sw) != ArraySize(arr.time))
{
Alert("數據檔案損毀,請強制重新開始");
return(false);
}
return(true);
}
bool CheckFCR()
{
if (EqualZero(GlobalVariableGet("AutoOpenChart")))
{
Alert("F.C.R. 模組未開啟,戰艦不會出航");
return(false);
}
return(true);
}
bool CheckFileSize(const string file_name)
{
int h1 = FileOpen(file_name,FILE_READ);
if (FileSize(h1) == 0 || h1 < 0)
{
FileClose(h1);
return(false);
}
FileClose(h1);
return(true);
}
//+------------------------------------------------------------------+
//| 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);
int GetSystemMetrics(int nIndex);
#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 CHT
//#define ENG
#define MAX 128
#define OP_ALL 101
#define MODE_AGET 0
#define MODE_FGET 1
#define MODE_INIT 3
#define MODE_TICK 4
#define MODE_SLTP_BYPOINT 102
#define MODE_SLTP_BYPRICE 103
#define TOLERANCE 0.000001
#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.
double Price = 0.0;
double Lots = 0.0;
double TPPrice = 0.0;
double SLPrice = 0.0;
double TPPips = 0.0;
double SLPips = 0.0;
double RangeBuy = 0.0;
double RangeSell = 0.0;
string ProfitOutSW = "";
string ProfitOutLossSW = "";
double TPsPrice = 0.0;
double SLsPrice = 0.0;
double TPsPips = 0.0;
double SLsPips = 0.0;
int id_1 = 0;
int InitXDis = 10;
int InitXDisSlave = 10;
int InitYDis = 100;
int InitYDisSlave = 10;
int LabelFontSize = 10;
int Space = 30;
int ErrorCode = 0;
int width;
int DownloadHour = 6;
int DownloadMin = 0;
datetime H1BarTime = 0;
bool ProfitOut = false;
bool ProfitOutLoss = false;
double point = 0.0;
double FontDPI=96;
double DPIratio = 0.8;
double BuyCloseData[MAX][2] = {0};
double SellCloseData[MAX][2] = {0};
double TrailStop = 0.0;
#ifdef CHT
string AllFont = "標楷體";
#endif
#ifdef ENG
string AllFont = "Impact";
#endif
string AllFontENG = "Impact";
string VisiSW[3] = {"SW0","SW1","SW2"};
string check_on = "\Images\check_on.bmp";
string check_off = "\Images\check_off.bmp";
string CheckBox[8] = {"CheckBox0", "CheckBox1", "CheckBox2", "CheckBox3", "CheckBox4", "CheckBox5", "CheckBox6" ,"CheckBox7"};
string CheckBoxs[4] = {"CheckBoxs0", "CheckBoxs1", "ChecksBox2", "ChecksBox3"};
string BGID[2] = {"BG","BG1"};
string logoID[2] = {"logo",""};
string BGIDslave[1] = {"BGs0"};
string buttonID[11] = {"Button0", "Button1", "Button2", "Button3", "Button4" ,"Button5", "Button6", "Button7", "Button8" , "Button9","Button10"};
string buttonsID[2] = {"Buttons0", "Buttons1"};
string labelID[37] = {"label0", "label1", "label2", "label3", "label4" , "label5" ,"label6" ,"label7" ,"label8" ,"label9" ,"label10","label11","label12","label13","label14","label15","label16","label17","label18","label19","label20","label21","label22","label23","label24","label25","label26","label27","label28","label29","label30","label31","label32","label33","label34","label35","label36"};
string labelsID[10] = {"labels0","labels1","labels2","labels3","labels4","labels5","labels6","labels7","labels8","labels9"};
#ifdef CHT
string buttonsText[2] = {"修改買單","修改賣單"};
string buttonText[11] = {"進場買", "進場賣", "神鬼掛單","平倉買單", "水雷", "平倉賣單" ,"刪除買單", "刪除掛單","刪除賣單", "重設","修改選單"};
string labelText[37] = {"市場價", "手數", "獲利(點)", "停損(點)", "獲利(價)", "停損(價)" ,"買","賣", "只平獲利", "追蹤止損", "保護","開始點","MagicNumber", "預付款設定%", "達比率點數: " ,"" ,"達比率價格: " ,"","買: ","0","手: ","0","賣: ","0","手: ","0","只平虧損","盈虧:","0","盈虧: ","0","全: " ,"0","手: ","0","盈虧: ","0"};
string labelsText[10] = {"買單盈虧","賣單盈虧","價位","價位","獲利(點)","停損(點)","獲利(價)","停損(價)","全部盈虧","價位"};
#endif
#ifdef ENG
string buttonsText[2] = {"Modify Buy","Modify Sell"};
string buttonText[11] = {"Buy Order", "Sell Order", "Two Way Order","Close Buy", "Close All", "Close Sell" ,"Delete Buy", "Delete All","Delete Sell", "Reset","Advanced"};
string labelText[37] = {"Price", "Lots", "TP(Pips)", "SL(Pips)", "TP(Price)", "SL(Price)" ,"Buy","Sell", "Close Profit Only", "Trail Stop", "B. E.","Start LV","MagicNumber", "Margin Level", "Margin Call Pips: " ,"" ,"Margin Call Price: " ,"","Buy: ","0","Lot: ","0","Sell: ","0","Lot: ","0","Close Loss Only","P/L: ","0","P/L: ","0","ALL: ","0","Lot: ","0","P/L: ","0"};
string labelsText[10] = {"Buy P/L","Sell P/L","Price","Price","TP(Pips)","SL(Pips)","TP(Price)","SL(Price)","ALL P/L","Price"};
#endif
string editID[13] = {"edit0", "edit1", "edit2", "edit3", "edit4","edit5", "edit6" ,"edit7", "edit8", "edit9", "edit10", "edit11","edit12"};
string editsID[10] = {"edits0", "edits1", "edits2", "edits3", "edits4","edits5","edits6","edits7","edits8","edits9"};
string editText[13] = {"0","0.01","10","10","","","10","10","5","5","5","","30"};
string editsText[10] = {"0","0","10","10","0","0","0","0","0","0"};
struct systemtime
{
ushort wYear;
ushort wMonth;
ushort wDayOfWeek;
ushort wDay;
ushort wHour;
ushort wMinute;
ushort wSecond;
ushort wMilliseconds;
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OnInit()
{
if (UninitializeReason() != 3)
{
if (!CheckValid()) return(-1);
}
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)之系統將無法保證交易能正常執行!");
}
int dc=GetDC(0);
FontDPI=GetDeviceCaps(dc,88);
if (FontDPI==0) FontDPI=96;
ReleaseDC(0,dc);
DPIratio = FontDPI / 120;
int YSCREEN = GetSystemMetrics(1);
if (YSCREEN <= 1024) Alert("建議解析度在 1280 * 1024 以上");
if (IsTesting()==true)
{
return(0);
}
MathSrand(GetTickCount());
DownloadMin = 1 + ((59 * MathRand()) / 32768);
//+------------------------------------------------------------------+
if (Digits==5 || Digits==3)
{
point=Point*10;
}
else
{
point=Point;
}
bgCreate();
bgsCreate(1);
CheckBoxCreate(1);
CheckBoxsCreate(1);
editCreate();
editsCreate(1);
editClear();
LoadPrevious();
CreateSW(1);
ButtonsCreate(1);
labelsCreate(1);
InitXDisSlave = (int)(ObjectGetInteger(0,BGID[0],OBJPROP_XSIZE) / DPIratio) + 20;
EventSetMillisecondTimer(100);
//+------------------------------------------------------------------+
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//----
EventKillTimer();
SaveParameter();
DeleteObj();
//----
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTimer()
{
if (GlobalVariableGet("RUNEA")==1) //EA控制器
{
Alert("EA is not working");
return;
}
//+------------------------------------------------Author End----------------------------------------------------------------------------+
bgCreate();
bgsCreate(0);
ButtonCreate();
logoCreate();
CheckBoxCreate(0);
CheckBoxsCreate(0);
labelCreate();
labelsCreate(0);
editCreate();
editsCreate(0);
GetValue();
ButtonsCreate(0);
bgsCreate(0);
string str_temp = ObjectGetString(0,CheckBox[5],OBJPROP_BMPFILE);
if (str_temp == check_on)
{
double MoveSL = StringToDouble(ObjectGetString(0,editID[8],OBJPROP_TEXT,0));
iMoveStopLoss(MoveSL);
}
str_temp = ObjectGetString(0,CheckBox[6],OBJPROP_BMPFILE);
if (str_temp == check_on)
{
double BE = StringToDouble(ObjectGetString(0,editID[9],OBJPROP_TEXT,0));
double LV = StringToDouble(ObjectGetString(0,editID[10],OBJPROP_TEXT,0));
iBE(BE,LV);
}
//width = (int)ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0);
//InitXDis = width - (int)ObjectGetInteger(0,BGID[0],OBJPROP_XSIZE);
//InitXDisSlave = InitXDis /*- (int)ObjectGetInteger(0,BGIDslave[0],OBJPROP_XSIZE)*/ - (int)ObjectGetInteger(0,BGID[0],OBJPROP_XSIZE) - 10;
MarginCall();
CreateSW(0);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double NormPoint(double inF)
{
return(inF * point);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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);
}
int SearchArray(double& in[][],int match)
{
for (int i=0;i<MAX;i++)
{
if ((double)match == in[i][0]) return(i);
}
return(-1);
}
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 CheckBoxCreate(const int Mode)
{
int i = 0;
for (;i<ArraySize(CheckBox);i++)
{
if (ObjectFind(0,CheckBox[i]) < 0) ObjectCreate(0,CheckBox[i],OBJ_BITMAP_LABEL,0,100,100);
if (Mode == 1)
{
ObjectSetString(0,CheckBox[i],OBJPROP_BMPFILE,(i <= 1 ? check_on :check_off));
}else
{
ObjectSetInteger(0,CheckBox[i],OBJPROP_XDISTANCE,(int)(CheckBoxX(i) * DPIratio));
ObjectSetInteger(0,CheckBox[i],OBJPROP_YDISTANCE,(int)(CheckBoxY(i) * DPIratio));
//ObjectSetInteger(0,CheckBox[i],OBJPROP_ZORDER,1)
}
}
}
void CheckBoxsCreate(const int Mode)
{
int i = 0;
for (;i<ArraySize(CheckBoxs);i++)
{
if (ObjectFind(0,CheckBoxs[i]) < 0) ObjectCreate(0,CheckBoxs[i],OBJ_BITMAP_LABEL,0,100,100);
if (Mode == 1)
{
ObjectSetString(0,CheckBoxs[i],OBJPROP_BMPFILE,(i <= 1 ? check_on :check_off));
ObjectSetInteger(0,CheckBoxs[i],OBJPROP_TIMEFRAMES,EMPTY);
}else
{
ObjectSetInteger(0,CheckBoxs[i],OBJPROP_XDISTANCE,(int)(CheckBoxsX(i) * DPIratio));
ObjectSetInteger(0,CheckBoxs[i],OBJPROP_YDISTANCE,(int)(CheckBoxsY(i) * DPIratio));
}
}
}
int CheckBoxsX(const int in)
{
int Out = 0;
switch (in)
{
case 0:
case 2:
Out = (InitXDisSlave + 75);
break;
case 1:
case 3:
Out = (InitXDisSlave + 255);
break;
}
return(Out);
}
int CheckBoxX(const int in)
{
int Out = 0;
switch (in)
{
case 0:
case 2:
Out = (InitXDis + 75);
break;
case 1:
case 3:
Out = (InitXDis + 255);
break;
case 4:
case 5:
Out = (InitXDis);
break;
case 7:
case 6:
Out = (InitXDis + 140);
break;
}
return(Out);
}
int CheckBoxsY(const int in)
{
int Out = 0;
switch (in)
{
case 0:
case 1:
Out = (InitYDisSlave + (LabelFontSize / 2) + Space * 3);
break;
case 2:
case 3:
Out = (InitYDisSlave + (LabelFontSize / 2) + Space * 4);
break;
}
return(Out);
}
int CheckBoxY(const int in)
{
int Out = 0;
switch (in)
{
case 0:
case 1:
Out = (InitYDis + (LabelFontSize / 2) + Space);
break;
case 2:
case 3:
Out = (InitYDis + (LabelFontSize / 2) + Space * 2);
break;
case 4:
case 7:
Out = (InitYDis + (Space * 5) + (LabelFontSize));
break;
case 5:
case 6:
Out = (InitYDis + (Space * 8) + (LabelFontSize));
break;
}
return(Out);
}
void logoCreate()
{
int i = 0;
for (;i<ArraySize(logoID);i++)
{
if (ObjectFind(0,logoID[i]) < 0) ObjectCreate(0,logoID[i],OBJ_LABEL,0,100,100);
ObjectSetInteger(0,logoID[i],OBJPROP_COLOR,clrGold);
ObjectSetInteger(0,logoID[i],OBJPROP_XDISTANCE,(int)((InitXDis + 20) * DPIratio));
ObjectSetInteger(0,logoID[i],OBJPROP_YDISTANCE,(int)(16 * DPIratio));
ObjectSetInteger(0,logoID[i],OBJPROP_CORNER,0);
ObjectSetString(0,logoID[i],OBJPROP_TEXT,"XBomb Tool Kit");
ObjectSetString(0,logoID[i],OBJPROP_FONT,"Impact");
ObjectSetInteger(0,logoID[i],OBJPROP_FONTSIZE,30);
ObjectSetInteger(0,logoID[i],OBJPROP_SELECTABLE,0);
}
}
void bgCreate()
{
int i = 0;
for (;i<ArraySize(BGID);i++)
{
if (ObjectFind(0,BGID[i]) < 0) ObjectCreate(0,BGID[i],OBJ_RECTANGLE_LABEL,0,100,100);
ObjectSetInteger(0,BGID[i],OBJPROP_BORDER_COLOR,i == 0 ? C'25,35,45' : clrGold);
ObjectSetInteger(0,BGID[i],OBJPROP_BORDER_TYPE,i == 0 ? BORDER_FLAT : BORDER_RAISED);
ObjectSetInteger(0,BGID[i],OBJPROP_BGCOLOR,(i == 0 ? C'25,35,45' : C'139,102,16'));
ObjectSetInteger(0,BGID[i],OBJPROP_COLOR,(i == 0 ? C'25,35,45' : C'139,102,16'));
ObjectSetInteger(0,BGID[i],OBJPROP_XDISTANCE,(int)(( i == 0 ? InitXDis - 10 : InitXDis + 5) * DPIratio));
ObjectSetInteger(0,BGID[i],OBJPROP_YDISTANCE,(int)(( i == 0 ? 0 : 15) * DPIratio));
ObjectSetInteger(0,BGID[i],OBJPROP_XSIZE,(int)(( i == 0 ? 362 : 330) * DPIratio));
ObjectSetInteger(0,BGID[i],OBJPROP_YSIZE,(int)(( i == 0 ? 620 : 60) * DPIratio));
ObjectSetInteger(0,BGID[i],OBJPROP_CORNER,0);
}
}
void bgsCreate(const int Mode)
{
int i = 0;
for (;i<ArraySize(BGIDslave);i++)
{
if (ObjectFind(0,BGIDslave[i]) < 0) ObjectCreate(0,BGIDslave[i],OBJ_RECTANGLE_LABEL,0,100,100);
ObjectSetInteger(0,BGIDslave[i],OBJPROP_BORDER_COLOR,C'25,35,45');
ObjectSetInteger(0,BGIDslave[i],OBJPROP_BORDER_TYPE,BORDER_FLAT);
ObjectSetInteger(0,BGIDslave[i],OBJPROP_BGCOLOR,C'25,35,45');
ObjectSetInteger(0,BGIDslave[i],OBJPROP_COLOR,C'25,35,45');
ObjectSetInteger(0,BGIDslave[i],OBJPROP_XDISTANCE,(int)((InitXDisSlave - 10) * DPIratio));
ObjectSetInteger(0,BGIDslave[i],OBJPROP_YDISTANCE,0);
ObjectSetInteger(0,BGIDslave[i],OBJPROP_XSIZE,(int)(362 * DPIratio));
ObjectSetInteger(0,BGIDslave[i],OBJPROP_YSIZE,(int)(310 * DPIratio));
ObjectSetInteger(0,BGIDslave[i],OBJPROP_CORNER,0);
if (Mode == 1) ObjectSetInteger(0,BGIDslave[i],OBJPROP_TIMEFRAMES,EMPTY);
}
}
void editCreate()
{
int i = 0;
for (;i<ArraySize(editID);i++)
{
if (ObjectFind(0,editID[i]) < 0) ObjectCreate(0,editID[i],OBJ_EDIT,0,100,100);
ObjectSetInteger(0,editID[i],OBJPROP_COLOR,clrBlack);
ObjectSetInteger(0,editID[i],OBJPROP_BGCOLOR,clrSilver);
ObjectSetInteger(0,editID[i],OBJPROP_BORDER_COLOR,C'153,163,174');
ObjectSetInteger(0,editID[i],OBJPROP_XDISTANCE,(int)(editX(i) * DPIratio));
ObjectSetInteger(0,editID[i],OBJPROP_YDISTANCE,(int)(editY(i) * DPIratio));
ObjectSetInteger(0,editID[i],OBJPROP_XSIZE,(int)(sizeXEdit(i) * DPIratio));
ObjectSetInteger(0,editID[i],OBJPROP_YSIZE,(int)(25 * DPIratio));
ObjectSetInteger(0,editID[i],OBJPROP_CORNER,0);
ObjectSetString(0,editID[i],OBJPROP_FONT,AllFontENG);
ObjectSetInteger(0,editID[i],OBJPROP_FONTSIZE,(int)(10 * DPIratio));
ObjectSetInteger(0,editID[i],OBJPROP_SELECTABLE,0);
ObjectSetInteger(0,editID[i],OBJPROP_ALIGN,ALIGN_CENTER);
}
}
void editsCreate(const int Mode)
{
int i = 0;
for (;i<ArraySize(editsID);i++)
{
if (ObjectFind(0,editsID[i]) < 0) ObjectCreate(0,editsID[i],OBJ_EDIT,0,100,100);
ObjectSetInteger(0,editsID[i],OBJPROP_COLOR,clrBlack);
ObjectSetInteger(0,editsID[i],OBJPROP_BGCOLOR,clrSilver);
ObjectSetInteger(0,editsID[i],OBJPROP_BORDER_COLOR,C'153,163,174');
ObjectSetInteger(0,editsID[i],OBJPROP_XDISTANCE,(int)(editsX(i) * DPIratio));
ObjectSetInteger(0,editsID[i],OBJPROP_YDISTANCE,(int)(editsY(i) * DPIratio));
ObjectSetInteger(0,editsID[i],OBJPROP_XSIZE,(int)(sizeXEdits(i) * DPIratio));
ObjectSetInteger(0,editsID[i],OBJPROP_YSIZE,(int)(25 * DPIratio));
ObjectSetInteger(0,editsID[i],OBJPROP_CORNER,0);
ObjectSetString(0,editsID[i],OBJPROP_FONT,AllFontENG);
ObjectSetInteger(0,editsID[i],OBJPROP_FONTSIZE,(int)(10 * DPIratio));
ObjectSetInteger(0,editsID[i],OBJPROP_SELECTABLE,0);
ObjectSetInteger(0,editsID[i],OBJPROP_ALIGN,ALIGN_CENTER);
if (Mode == 1) ObjectSetInteger(0,editsID[i],OBJPROP_TIMEFRAMES,EMPTY);
}
}
int sizeXEdits(const int in)
{
int Out = 0;
switch (in)
{
case 2:
case 3:
case 4:
case 5:
Out = (65);
break;
default:
Out = (85);
break;
}
return(Out);
}
int sizeXEdit(const int in)
{
int Out = 0;
switch (in)
{
case 2:
case 3:
case 4:
case 5:
Out = (65);
break;
case 6:
case 7:
Out = (25);
break;
case 8:
case 9:
case 10:
Out = (40);
break;
default:
Out = (85);
break;
}
return(Out);
}
void editClear()
{
int i = 0;
for (;i<ArraySize(editID);i++)
{
if (ObjectFind(0,editID[i]) < 0) ObjectCreate(0,editID[i],OBJ_EDIT,0,100,100);
ObjectSetString(0,editID[i],OBJPROP_TEXT,editText[i]);
}
for (i=0;i<ArraySize(editsID);i++)
{
if (ObjectFind(0,editsID[i]) < 0) ObjectCreate(0,editsID[i],OBJ_EDIT,0,100,100);
ObjectSetString(0,editsID[i],OBJPROP_TEXT,editsText[i]);
}
}
int editsX(const int in)
{
int Out = 0;
switch (in)
{
case 0:
case 1:
case 8:
Out = (InitXDisSlave + 75);
break;
case 6:
case 7:
case 9:
Out = (InitXDisSlave + 255);
break;
case 2:
case 4:
Out = (InitXDisSlave + 95);
break;
case 3:
case 5:
Out = (InitXDisSlave + 275);
break;
}
return(Out);
}
int editX(const int in)
{
int Out = 0;
switch (in)
{
case 0:
Out = (InitXDis + 75);
break;
case 1:
Out = (InitXDis + 255);
break;
case 2:
case 4:
Out = (InitXDis + 95);
break;
case 3:
case 5:
Out = (InitXDis + 275);
break;
case 6:
Out = (InitXDis + 205);
break;
case 7:
Out = (InitXDis + 270);
break;
case 8:
Out = (InitXDis + 90);
break;
case 9:
Out = (InitXDis + 200);
break;
case 10:
Out = (InitXDis + 300);
break;
case 11:
case 12:
Out = (InitXDis + 110);
break;
}
return(Out);
}
int editsY(const int in)
{
int Out = 0;
switch (in)
{
case 0:
case 6:
Out = (InitYDisSlave);
break;
case 1:
case 7:
Out = (InitYDisSlave + Space);
break;
case 8:
case 9:
Out = (InitYDisSlave + Space * 2);
break;
case 2:
case 3:
Out = (InitYDisSlave + Space * 3);
break;
case 4:
case 5:
Out = (InitYDisSlave + Space * 4);
break;
}
return(Out);
}
int editY(const int in)
{
int Out = 0;
switch (in)
{
case 0:
case 1:
Out = (InitYDis);
break;
case 2:
case 3:
Out = (InitYDis + Space);
break;
case 4:
case 5:
Out = (InitYDis + Space * 2);
break;
case 6:
case 7:
Out = (InitYDis + Space * 4);
break;
case 8:
case 9:
case 10:
Out = (InitYDis + (Space * 8) + (LabelFontSize));
break;
case 11:
Out = (InitYDis + (Space * 9) + (LabelFontSize));
break;
case 12:
Out = (InitYDis + (Space * 10) + (LabelFontSize));
break;
}
return(Out);
}
void labelCreate()
{
int i = 0;
for (;i<ArraySize(labelID);i++)
{
if (ObjectFind(0,labelID[i]) < 0) ObjectCreate(0,labelID[i],OBJ_LABEL,0,100,100);
ObjectSetInteger(0,labelID[i],OBJPROP_COLOR,colorLabel(i));
//ObjectSetInteger(0,labelID[i],OBJPROP_BGCOLOR,clrDimGray);
ObjectSetInteger(0,labelID[i],OBJPROP_XDISTANCE,(int)(LabelX(i) * DPIratio));
ObjectSetInteger(0,labelID[i],OBJPROP_YDISTANCE,(int)(LabelY(i) * DPIratio));
ObjectSetInteger(0,labelID[i],OBJPROP_CORNER,0);
ObjectSetString(0,labelID[i],OBJPROP_FONT,fontLabel(i));
ObjectSetString(0,labelID[i],OBJPROP_TEXT,labelText[i]);
ObjectSetInteger(0,labelID[i],OBJPROP_FONTSIZE,(int)(LabelFontSize));
ObjectSetInteger(0,labelID[i],OBJPROP_SELECTABLE,0);
ObjectSetInteger(0,labelID[i],OBJPROP_ANCHOR,(i == 30 || i== 28 || i== 36 ? ANCHOR_RIGHT_UPPER : ANCHOR_LEFT_UPPER));
}
}
void labelsCreate(const int Mode)
{
int i = 0;
for (;i<ArraySize(labelsID);i++)
{
if (ObjectFind(0,labelsID[i]) < 0) ObjectCreate(0,labelsID[i],OBJ_LABEL,0,100,100);
ObjectSetInteger(0,labelsID[i],OBJPROP_COLOR,colorLabels(i));
ObjectSetInteger(0,labelsID[i],OBJPROP_XDISTANCE,(int)(LabelsX(i) * DPIratio));
ObjectSetInteger(0,labelsID[i],OBJPROP_YDISTANCE,(int)(LabelsY(i) * DPIratio));
ObjectSetInteger(0,labelsID[i],OBJPROP_CORNER,0);
ObjectSetString(0,labelsID[i],OBJPROP_FONT,fontLabels(i));
ObjectSetString(0,labelsID[i],OBJPROP_TEXT,labelsText[i]);
ObjectSetInteger(0,labelsID[i],OBJPROP_FONTSIZE,(int)(LabelFontSize));
ObjectSetInteger(0,labelsID[i],OBJPROP_SELECTABLE,0);
if (Mode == 1) ObjectSetInteger(0,labelsID[i],OBJPROP_TIMEFRAMES,EMPTY);
}
}
string fontLabels(const int in)
{
return(AllFont);
}
string fontLabel(const int in)
{
if (in == 12) return(AllFontENG);
if (in == 17 || in == 15) return(AllFontENG);
if (in == 19 || in == 21 || in == 23 || in == 25 || in == 28 || in == 30 || in == 32 || in == 34 || in == 36) return(AllFontENG);
return(AllFont);
}
int colorLabels(const int in)
{
int Out = 0;
switch (in)
{
case 5:
case 7:
Out = C'173,93,71';
break;
case 4:
case 6:
Out = C'105,125,83';
break;
case 14:
case 16:
Out = C'162,144,83';
break;
default:
Out = (clrSilver);
break;
}
return(Out);
}
int colorLabel(const int in)
{
int Out = 0;
switch (in)
{
case 3:
case 5:
Out = C'173,93,71';
break;
case 2:
case 4:
Out = C'105,125,83';
break;
case 14:
case 16:
Out = C'162,144,83';
break;
case 19:
case 21:
case 28:
Out = clrLime;
break;
case 30:
case 23:
case 25:
Out = clrRed;
break;
default:
Out = (clrSilver);
break;
}
if (in == 32 || in == 34 || in == 36) Out = clrGold;
return(Out);
}
int LabelsX(const int in)
{
int Out = 0;
switch (in)
{
case 0:
case 1:
case 4:
case 6:
case 8:
Out = (InitXDisSlave);
break;
case 2:
case 3:
case 5:
case 7:
case 9:
Out = (InitXDisSlave + 175);
break;
}
return(Out);
}
int LabelX(const int in)
{
int Out = 0;
switch (in)
{
case 0:
case 2:
case 4:
case 12:
case 13:
case 14:
case 16:
case 18:
case 22:
case 31:
Out = (InitXDis);
break;
case 1:
case 3:
case 5:
case 6:
Out = (InitXDis + 175);
break;
case 7:
Out = (InitXDis + 235);
break;
case 8:
case 9:
Out = (InitXDis + 20);
break;
case 10:
Out = (InitXDis + 160);
break;
case 11:
Out = (InitXDis + 245);
break;
case 15:
case 17:
Out = (InitXDis + 130);
break;
case 19:
case 23:
case 32:
Out = (InitXDis + 40);
break;
case 20:
case 24:
case 33:
Out = (InitXDis + 60);
break;
case 21:
case 25:
case 34:
Out = (InitXDis + 90);
break;
case 26:
Out = (InitXDis + 160);
break;
case 27:
case 29:
case 35:
Out = (InitXDis + 140);
break;
case 28:
case 30:
case 36:
Out = (InitXDis + 280);
break;
}
return(Out);
}
int LabelsY(const int in)
{
int Out = 0;
switch (in)
{
case 0:
case 2:
Out = (InitYDisSlave);
break;
case 1:
case 3:
Out = (InitYDisSlave + Space);
break;
case 8:
case 9:
Out = (InitYDisSlave + Space * 2);
break;
case 4:
case 5:
Out = (InitYDisSlave + Space * 3);
break;
case 6:
case 7:
Out = (InitYDisSlave + Space * 4);
break;
}
return(Out);
}
int LabelY(const int in)
{
int Out = 0;
switch (in)
{
case 0:
case 1:
Out = (InitYDis);
break;
case 2:
case 3:
Out = (InitYDis + Space);
break;
case 4:
case 5:
Out = (InitYDis + Space * 2);
break;
case 6:
case 7:
Out = (InitYDis + Space * 4);
break;
case 8:
Out = (InitYDis + Space * 5 + LabelFontSize);
break;
case 9:
case 10:
case 11:
Out = (InitYDis + (Space * 8) + (LabelFontSize));
break;
case 12:
Out = (InitYDis + (Space * 9) + (LabelFontSize));
break;
case 13:
Out = (InitYDis + (Space * 10) + (LabelFontSize));
break;
case 14:
case 15:
Out = (InitYDis + (Space * 11) + (LabelFontSize));
break;
case 16:
case 17:
Out = (InitYDis + (Space * 12) + (LabelFontSize));
break;
case 18:
case 19:
case 20:
case 21:
case 27:
case 28:
Out = (InitYDis + (Space * 13) + (LabelFontSize));
break;
case 22:
case 23:
case 24:
case 25:
case 29:
case 30:
Out = (InitYDis + (Space * 14) + (LabelFontSize));
break;
case 26:
Out = (InitYDis + (Space * 5) + (LabelFontSize));
break;
}
if (in >= 31 && in <= 36) Out = (InitYDis + (Space * 15) + (LabelFontSize));
return(Out);
}
void ButtonCreate()
{
for (int i=0;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,clrSilver);
//ObjectSetInteger(0,buttonID[i],OBJPROP_BGCOLOR,C'220,231,242');
ObjectSetInteger(0,buttonID[i],OBJPROP_BGCOLOR,colorButton(i));
//ObjectSetInteger(0,buttonID[i],OBJPROP_BORDER_COLOR,C'153,163,174');
ObjectSetInteger(0,buttonID[i],OBJPROP_XDISTANCE,(int)(ButtonX(i) * DPIratio));
ObjectSetInteger(0,buttonID[i],OBJPROP_XSIZE,(int)(sizeXButton(i) * DPIratio));
ObjectSetInteger(0,buttonID[i],OBJPROP_YDISTANCE,(int)(ButtonY(i) * DPIratio));
ObjectSetInteger(0,buttonID[i],OBJPROP_YSIZE,(int)(25 * DPIratio));
ObjectSetInteger(0,buttonID[i],OBJPROP_CORNER,0);
ObjectSetString(0,buttonID[i],OBJPROP_FONT,AllFont);
ObjectSetString(0,buttonID[i],OBJPROP_TEXT,buttonText[i]);
ObjectSetInteger(0,buttonID[i],OBJPROP_FONTSIZE,10);
ObjectSetInteger(0,buttonID[i],OBJPROP_SELECTABLE,0);
}
}
void ButtonsCreate(const int Mode)
{
for (int i=0;i<ArraySize(buttonsID);i++)
{
if (ObjectFind(0,buttonsID[i]) < 0) ObjectCreate(0,buttonsID[i],OBJ_BUTTON,0,100,100);
ObjectSetInteger(0,buttonsID[i],OBJPROP_COLOR,clrSilver);
//ObjectSetInteger(0,buttonsID[i],OBJPROP_BGCOLOR,C'220,231,242');
ObjectSetInteger(0,buttonsID[i],OBJPROP_BGCOLOR,colorButtons(i));
//ObjectSetInteger(0,buttonsID[i],OBJPROP_BORDER_COLOR,C'153,163,174');
ObjectSetInteger(0,buttonsID[i],OBJPROP_XDISTANCE,(int)(ButtonsX(i) * DPIratio));
ObjectSetInteger(0,buttonsID[i],OBJPROP_XSIZE,(int)(sizeXButtons(i) * DPIratio));
ObjectSetInteger(0,buttonsID[i],OBJPROP_YDISTANCE,(int)(ButtonsY(i) * DPIratio));
ObjectSetInteger(0,buttonsID[i],OBJPROP_YSIZE,(int)(25 * DPIratio));
ObjectSetInteger(0,buttonsID[i],OBJPROP_CORNER,0);
ObjectSetString(0,buttonsID[i],OBJPROP_FONT,AllFont);
ObjectSetString(0,buttonsID[i],OBJPROP_TEXT,buttonsText[i]);
ObjectSetInteger(0,buttonsID[i],OBJPROP_FONTSIZE,10);
ObjectSetInteger(0,buttonsID[i],OBJPROP_SELECTABLE,0);
if (Mode == 1) ObjectSetInteger(0,buttonsID[i],OBJPROP_TIMEFRAMES,EMPTY);
}
}
int sizeXButton(const int in)
{
int Out = 0;
switch (in)
{
case 0:
case 1:
case 2:
Out = (170);
break;
default:
Out = (110);
break;
}
return(Out);
}
int sizeXButtons(const int in)
{
int Out = 0;
switch (in)
{
case 0:
case 1:
Out = (170);
break;
default:
Out = (110);
break;
}
return(Out);
}
int colorButtons(const int in)
{
int Out = 0;
switch (in)
{
case 0:
Out = (C'25,56,95');
break;
case 1:
Out = (C'94,25,25');
break;
}
return(Out);
}
int colorButton(const int in)
{
int Out = 0;
switch (in)
{
case 0:
Out = (C'25,56,95');
break;
case 1:
Out = (C'94,25,25');
break;
case 2:
case 3:
Out = (C'94,26,91');
break;
case 4:
Out = (C'51,94,25');
break;
case 5:
Out = (C'128,0,0');
break;
case 6:
Out = (C'62,17,60');
break;
case 7:
Out = (C'35,65,17');
break;
case 8:
Out = (C'64,0,0');
break;
case 9:
Out = (C'94,93,25');
break;
}
return(Out);
}
int ButtonsX(const int in)
{
int iX = 20;
int Out = 0;
switch (in)
{
case 0:
Out = InitXDisSlave - 2;
break;
case 1:
Out = (InitXDisSlave + 174);
break;
}
return(Out);
}
int ButtonX(const int in)
{
int iX = 20;
int Out = 0;
switch (in)
{
case 0:
case 2:
case 3:
case 6:
Out = InitXDis - 2;
break;
case 1:
Out = (InitXDis + 174);
break;
case 4:
case 7:
case 10:
Out = (117 + InitXDis);
break;
case 5:
case 8:
case 9:
Out = (InitXDis + 236);
break;
}
return(Out);
}
int ButtonsY(const int in)
{
int Out = 0;
switch (in)
{
case 0:
case 1:
Out = (InitYDisSlave + Space * 5);
break;
}
return(Out);
}
int ButtonY(const int in)
{
int Out = 0;
switch (in)
{
case 0:
case 1:
Out = (InitYDis + Space * 3);
break;
case 2:
Out = (InitYDis + (Space * 4));
break;
case 3:
case 4:
case 5:
Out = (InitYDis + (Space * 5) + (LabelFontSize * 3));
break;
case 6:
case 7:
case 8:
Out = (InitYDis + (Space * 6) + (LabelFontSize * 3));
break;
case 9:
case 10:
Out = (595);
break;
}
return(Out);
}
void GetValue()
{
Price = StringToDouble(ObjectGetString(0,editID[0],OBJPROP_TEXT,0));
Lots = StringToDouble(ObjectGetString(0,editID[1],OBJPROP_TEXT,0));
TPPrice = StringToDouble(ObjectGetString(0,editID[4],OBJPROP_TEXT,0));
SLPrice = StringToDouble(ObjectGetString(0,editID[5],OBJPROP_TEXT,0));
TPPips = StringToDouble(ObjectGetString(0,editID[2],OBJPROP_TEXT,0));
SLPips = StringToDouble(ObjectGetString(0,editID[3],OBJPROP_TEXT,0));
RangeBuy = StringToDouble(ObjectGetString(0,editID[6],OBJPROP_TEXT,0));
RangeSell = StringToDouble(ObjectGetString(0,editID[7],OBJPROP_TEXT,0));
ProfitOutSW = ObjectGetString(0,CheckBox[4],OBJPROP_BMPFILE);
ProfitOutLossSW = ObjectGetString(0,CheckBox[7],OBJPROP_BMPFILE);
TPsPrice = StringToDouble(ObjectGetString(0,editsID[4],OBJPROP_TEXT,0));
SLsPrice = StringToDouble(ObjectGetString(0,editsID[5],OBJPROP_TEXT,0));
TPsPips = StringToDouble(ObjectGetString(0,editsID[2],OBJPROP_TEXT,0));
SLsPips = StringToDouble(ObjectGetString(0,editsID[3],OBJPROP_TEXT,0));
}
void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam)
{
if (ProfitOutSW == check_on)
{
ProfitOut = true;
}else
{
ProfitOut = false;
}
if (ProfitOutLossSW == check_on)
{
ProfitOutLoss = true;
}else
{
ProfitOutLoss = false;
}
id_1 = (int)StringToInteger(ObjectGetString(0,editID[11],OBJPROP_TEXT,0));
if (id == CHARTEVENT_OBJECT_ENDEDIT)
{
CheckAlledit();
string endEditChartObject=sparam;
if(endEditChartObject==editsID[0] || endEditChartObject==editsID[1] || endEditChartObject==editsID[8])
{
double CalProfitBuy = StringToDouble(ObjectGetString(0,editsID[0],OBJPROP_TEXT));
double CalProfitSell = StringToDouble(ObjectGetString(0,editsID[1],OBJPROP_TEXT));
double CalProfitAll = StringToDouble(ObjectGetString(0,editsID[8],OBJPROP_TEXT));
ObjectSetString(0,editsID[6],OBJPROP_TEXT,DoubleToString(Cal_TP(OP_BUY,0,CalProfitBuy),Digits));
ObjectSetString(0,editsID[7],OBJPROP_TEXT,DoubleToString(Cal_TP(OP_SELL,0,CalProfitSell),Digits));
ObjectSetString(0,editsID[9],OBJPROP_TEXT,DoubleToString(Cal_TP(OP_ALL,0,CalProfitAll),Digits));
}
if(endEditChartObject==editsID[6] || endEditChartObject==editsID[7] || endEditChartObject==editsID[9])
{
double CalPriceBuy = StringToDouble(ObjectGetString(0,editsID[6],OBJPROP_TEXT));
double CalPriceSell = StringToDouble(ObjectGetString(0,editsID[7],OBJPROP_TEXT));
double CalPriceAll = StringToDouble(ObjectGetString(0,editsID[9],OBJPROP_TEXT));
ObjectSetString(0,editsID[0],OBJPROP_TEXT,DoubleToString(Cal_Profit(OP_BUY,CalPriceBuy),2));
ObjectSetString(0,editsID[1],OBJPROP_TEXT,DoubleToString(Cal_Profit(OP_SELL,CalPriceSell),2));
ObjectSetString(0,editsID[8],OBJPROP_TEXT,DoubleToString(Cal_Profit(OP_ALL,CalPriceAll),Digits));
}
}
if(id==CHARTEVENT_OBJECT_CLICK)
{
string clickedChartObject=sparam;
if(clickedChartObject==VisiSW[0])
{
string str_temp = ObjectGetString(0,VisiSW[0],OBJPROP_TEXT);
bool selected = ObjectGetInteger(0,buttonID[10],OBJPROP_STATE);
if (str_temp == "5")
{
ObjectSetString(0,VisiSW[0],OBJPROP_TEXT,"6");
VisiObjs(false);
if (selected)
{
VisiObjsSlave(false);
}
}
if (str_temp == "6")
{
ObjectSetString(0,VisiSW[0],OBJPROP_TEXT,"5");
VisiObjs(true);
if (selected)
{
VisiObjsSlave(true);
}
}
}
if(clickedChartObject==VisiSW[1])
{
bool selected = ObjectGetInteger(0,VisiSW[1],OBJPROP_STATE);
if (selected)
{
InitXDis = 10;
InitXDisSlave = InitXDis + (int)(ObjectGetInteger(0,BGID[0],OBJPROP_XSIZE) / DPIratio) + 10;
ObjectSetInteger(0,VisiSW[1],OBJPROP_STATE,0);
}
}
if(clickedChartObject==VisiSW[2])
{
bool selected = ObjectGetInteger(0,VisiSW[2],OBJPROP_STATE);
if (selected)
{
width = (int)ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0);
InitXDis = (int)((width - ObjectGetInteger(0,BGID[0],OBJPROP_XSIZE)) / DPIratio);
InitXDisSlave = InitXDis /*- (int)ObjectGetInteger(0,BGIDslave[0],OBJPROP_XSIZE)*/ - (int)(ObjectGetInteger(0,BGID[0],OBJPROP_XSIZE) / DPIratio) - 10;
ObjectSetInteger(0,VisiSW[2],OBJPROP_STATE,0);
}
}
if(clickedChartObject==CheckBoxs[0])
{
string str_temp = ObjectGetString(0,CheckBoxs[0],OBJPROP_BMPFILE);
if (str_temp == check_off)
{
ObjectSetString(0,CheckBoxs[0],OBJPROP_BMPFILE,check_on);
ObjectSetString(0,CheckBoxs[2],OBJPROP_BMPFILE,check_off);
}
if (str_temp == check_on)
{
ObjectSetString(0,CheckBoxs[0],OBJPROP_BMPFILE,check_off);
ObjectSetString(0,CheckBoxs[2],OBJPROP_BMPFILE,check_on);
}
}
if(clickedChartObject==CheckBoxs[1])
{
string str_temp = ObjectGetString(0,CheckBoxs[1],OBJPROP_BMPFILE);
if (str_temp == check_off)
{
ObjectSetString(0,CheckBoxs[1],OBJPROP_BMPFILE,check_on);
ObjectSetString(0,CheckBoxs[3],OBJPROP_BMPFILE,check_off);
}
if (str_temp == check_on)
{
ObjectSetString(0,CheckBoxs[1],OBJPROP_BMPFILE,check_off);
ObjectSetString(0,CheckBoxs[3],OBJPROP_BMPFILE,check_on);
}
}
if(clickedChartObject==CheckBox[0])
{
string str_temp = ObjectGetString(0,CheckBox[0],OBJPROP_BMPFILE);
if (str_temp == check_off)
{
ObjectSetString(0,CheckBox[0],OBJPROP_BMPFILE,check_on);
ObjectSetString(0,CheckBox[2],OBJPROP_BMPFILE,check_off);
}
if (str_temp == check_on)
{
ObjectSetString(0,CheckBox[0],OBJPROP_BMPFILE,check_off);
ObjectSetString(0,CheckBox[2],OBJPROP_BMPFILE,check_on);
}
}
if(clickedChartObject==CheckBox[1])
{
string str_temp = ObjectGetString(0,CheckBox[1],OBJPROP_BMPFILE);
if (str_temp == check_off)
{
ObjectSetString(0,CheckBox[1],OBJPROP_BMPFILE,check_on);
ObjectSetString(0,CheckBox[3],OBJPROP_BMPFILE,check_off);
}
if (str_temp == check_on)
{
ObjectSetString(0,CheckBox[1],OBJPROP_BMPFILE,check_off);
ObjectSetString(0,CheckBox[3],OBJPROP_BMPFILE,check_on);
}
}
if(clickedChartObject==CheckBoxs[2])
{
string str_temp = ObjectGetString(0,CheckBoxs[2],OBJPROP_BMPFILE);
if (str_temp == check_off)
{
ObjectSetString(0,CheckBoxs[2],OBJPROP_BMPFILE,check_on);
ObjectSetString(0,CheckBoxs[0],OBJPROP_BMPFILE,check_off);
}
if (str_temp == check_on)
{
ObjectSetString(0,CheckBoxs[2],OBJPROP_BMPFILE,check_off);
ObjectSetString(0,CheckBoxs[0],OBJPROP_BMPFILE,check_on);
}
}
if(clickedChartObject==CheckBoxs[3])
{
string str_temp = ObjectGetString(0,CheckBoxs[3],OBJPROP_BMPFILE);
if (str_temp == check_off)
{
ObjectSetString(0,CheckBoxs[3],OBJPROP_BMPFILE,check_on);
ObjectSetString(0,CheckBoxs[1],OBJPROP_BMPFILE,check_off);
}
if (str_temp == check_on)
{
ObjectSetString(0,CheckBoxs[3],OBJPROP_BMPFILE,check_off);
ObjectSetString(0,CheckBoxs[1],OBJPROP_BMPFILE,check_on);
}
}
if(clickedChartObject==CheckBox[2])
{
string str_temp = ObjectGetString(0,CheckBox[2],OBJPROP_BMPFILE);
if (str_temp == check_off)
{
ObjectSetString(0,CheckBox[2],OBJPROP_BMPFILE,check_on);
ObjectSetString(0,CheckBox[0],OBJPROP_BMPFILE,check_off);
}
if (str_temp == check_on)
{
ObjectSetString(0,CheckBox[2],OBJPROP_BMPFILE,check_off);
ObjectSetString(0,CheckBox[0],OBJPROP_BMPFILE,check_on);
}
}
if(clickedChartObject==CheckBox[3])
{
string str_temp = ObjectGetString(0,CheckBox[3],OBJPROP_BMPFILE);
if (str_temp == check_off)
{
ObjectSetString(0,CheckBox[3],OBJPROP_BMPFILE,check_on);
ObjectSetString(0,CheckBox[1],OBJPROP_BMPFILE,check_off);
}
if (str_temp == check_on)
{
ObjectSetString(0,CheckBox[3],OBJPROP_BMPFILE,check_off);
ObjectSetString(0,CheckBox[1],OBJPROP_BMPFILE,check_on);
}
}
if(clickedChartObject==CheckBox[4])
{
string str_temp = ObjectGetString(0,CheckBox[4],OBJPROP_BMPFILE);
if (str_temp == check_off)
{
ObjectSetString(0,CheckBox[4],OBJPROP_BMPFILE,check_on);
ObjectSetString(0,CheckBox[7],OBJPROP_BMPFILE,check_off);
}
if (str_temp == check_on)
{
ObjectSetString(0,CheckBox[4],OBJPROP_BMPFILE,check_off);
}
}
if(clickedChartObject==CheckBox[5])
{
string str_temp = ObjectGetString(0,CheckBox[5],OBJPROP_BMPFILE);
if (str_temp == check_off)
{
ObjectSetString(0,CheckBox[5],OBJPROP_BMPFILE,check_on);
ObjectSetString(0,CheckBox[6],OBJPROP_BMPFILE,check_off);
}
if (str_temp == check_on)
{
ObjectSetString(0,CheckBox[5],OBJPROP_BMPFILE,check_off);
}
}
if(clickedChartObject==CheckBox[6])
{
string str_temp = ObjectGetString(0,CheckBox[6],OBJPROP_BMPFILE);
if (str_temp == check_off)
{
ObjectSetString(0,CheckBox[6],OBJPROP_BMPFILE,check_on);
ObjectSetString(0,CheckBox[5],OBJPROP_BMPFILE,check_off);
}
if (str_temp == check_on)
{
ObjectSetString(0,CheckBox[6],OBJPROP_BMPFILE,check_off);
}
}
if(clickedChartObject==CheckBox[7])
{
string str_temp = ObjectGetString(0,CheckBox[7],OBJPROP_BMPFILE);
if (str_temp == check_off)
{
ObjectSetString(0,CheckBox[7],OBJPROP_BMPFILE,check_on);
ObjectSetString(0,CheckBox[4],OBJPROP_BMPFILE,check_off);
}
if (str_temp == check_on)
{
ObjectSetString(0,CheckBox[7],OBJPROP_BMPFILE,check_off);
}
}
if(clickedChartObject==buttonsID[0])
{
bool selected = ObjectGetInteger(0,buttonsID[0],OBJPROP_STATE);
string TPSW = ObjectGetString(0,CheckBoxs[0],OBJPROP_BMPFILE);
string SLSW = ObjectGetString(0,CheckBoxs[1],OBJPROP_BMPFILE);
if (selected)
{
double SL,TP;
if (TPSW == check_on)
{
TP = TPsPips;
Set_SL_TP(MODE_SLTP_BYPOINT,OP_BUY,-1,TP);
}else
{
TP = TPsPrice;
Set_SL_TP(MODE_SLTP_BYPRICE,OP_BUY,-1,TP);
}
Print(TP);
if (SLSW == check_on)
{
SL = SLsPips;
Set_SL_TP(MODE_SLTP_BYPOINT,OP_BUY,SL,-1);
}else
{
SL = SLsPrice;
Set_SL_TP(MODE_SLTP_BYPRICE,OP_BUY,SL,-1);
}
Sleep(200);
ObjectSetInteger(0,buttonsID[0],OBJPROP_STATE,false);
}
}
if(clickedChartObject==buttonsID[1])
{
bool selected = ObjectGetInteger(0,buttonsID[1],OBJPROP_STATE);
string TPSW = ObjectGetString(0,CheckBoxs[0],OBJPROP_BMPFILE);
string SLSW = ObjectGetString(0,CheckBoxs[1],OBJPROP_BMPFILE);
if (selected)
{
double SL,TP;
if (TPSW == check_on)
{
TP = TPsPips;
Set_SL_TP(MODE_SLTP_BYPOINT,OP_SELL,-1,TP);
}else
{
TP = TPsPrice;
Set_SL_TP(MODE_SLTP_BYPRICE,OP_SELL,-1,TP);
}
if (SLSW == check_on)
{
SL = SLsPips;
Set_SL_TP(MODE_SLTP_BYPOINT,OP_SELL,SL,-1);
}else
{
SL = SLsPrice;
Set_SL_TP(MODE_SLTP_BYPRICE,OP_SELL,SL,-1);
}
Sleep(200);
ObjectSetInteger(0,buttonsID[1],OBJPROP_STATE,false);
}
}
if(clickedChartObject==buttonID[0])
{
bool selected = ObjectGetInteger(0,buttonID[0],OBJPROP_STATE);
string TPSW = ObjectGetString(0,CheckBox[0],OBJPROP_BMPFILE);
string SLSW = ObjectGetString(0,CheckBox[1],OBJPROP_BMPFILE);
if (selected)
{
double iPrice = Price;
double SL,TP;
int Type = -1;
if (EqualZero(iPrice))
{
iPrice = Ask;
Type = OP_BUY;
if (TPSW == check_on)
{
if (EqualZero(TPPips))
TP = 0;
else
TP = Ask + TPPips * point;
}else
{
TP = TPPrice;
}
if (SLSW == check_on)
{
if (EqualZero(SLPips))
SL = 0;
else
SL = Ask - SLPips * point;
}else
{
SL = SLPrice;
}
}else
{
Type = OutOrderType(iPrice,0);
if (TPSW == check_on)
{
if (EqualZero(TPPips))
TP = 0;
else
TP = iPrice + TPPips * point;
}else
{
TP = TPPrice;
}
if (SLSW == check_on)
{
if (EqualZero(SLPips))
SL = 0;
else
SL = iPrice - SLPips * point;
}else
{
SL = SLPrice;
}
}
SendOrders(Type,"Savior_" + IntegerToString(OP_BUY),iPrice,Lots,SL,TP);
Sleep(200);
ObjectSetInteger(0,buttonID[0],OBJPROP_STATE,false);
}
}
if(clickedChartObject==buttonID[1])
{
bool selected = ObjectGetInteger(0,buttonID[1],OBJPROP_STATE);
string TPSW = ObjectGetString(0,CheckBox[0],OBJPROP_BMPFILE);
string SLSW = ObjectGetString(0,CheckBox[1],OBJPROP_BMPFILE);
if (selected)
{
double iPrice = Price;
double SL,TP;
int Type = -1;
if (EqualZero(iPrice))
{
iPrice = Bid;
Type = OP_SELL;
if (TPSW == check_on)
{
if (EqualZero(TPPips))
TP = 0;
else
TP = Bid - TPPips * point;
}else
{
TP = TPPrice;
}
if (SLSW == check_on)
{
if (EqualZero(SLPips))
SL = 0;
else
SL = Bid + SLPips * point;
}else
{
SL = SLPrice;
}
}else
{
Type = OutOrderType(iPrice,1);
if (TPSW == check_on)
{
if (EqualZero(TPPips))
TP = 0;
else
TP = iPrice - TPPips * point;
}else
{
TP = TPPrice;
}
if (SLSW == check_on)
{
if (EqualZero(SLPips))
SL = 0;
else
SL = iPrice + SLPips * point;
}else
{
SL = SLPrice;
}
}
SendOrders(Type,"Savior_" + IntegerToString(OP_SELL),iPrice,Lots,SL,TP);
Sleep(200);
ObjectSetInteger(0,buttonID[1],OBJPROP_STATE,false);
}
}
if(clickedChartObject == buttonID[2])
{
bool selected = ObjectGetInteger(0,buttonID[2],OBJPROP_STATE);
if (selected)
{
SendOrders(OutOrderType(Ask + RangeBuy * point,OP_BUY),"Savior_" + IntegerToString(OP_BUY),
Ask + RangeBuy * point,Lots,
(EqualZero(SLPips) ? 0.0 : (Ask + (RangeBuy - SLPips) * point)),
(EqualZero(TPPips) ? 0.0 : (Ask + (RangeBuy + TPPips) * point)));
SendOrders(OutOrderType(Bid - RangeSell * point,OP_SELL),"Savior_" + IntegerToString(OP_SELL),
Bid - RangeSell * point,Lots,
(EqualZero(SLPips) ? 0.0 : (Bid - (RangeSell - SLPips) * point)),
(EqualZero(TPPips) ? 0.0 : (Bid - (RangeSell + TPPips) * point)));
Sleep(200);
ObjectSetInteger(0,buttonID[2],OBJPROP_STATE,false);
}
}
if(clickedChartObject == buttonID[3])
{
bool selected = ObjectGetInteger(0,buttonID[3],OBJPROP_STATE);
if (selected)
{
Sleep(200);
iCloseOrders(OP_BUY);
ObjectSetInteger(0,buttonID[3],OBJPROP_STATE,false);
}
}
if(clickedChartObject == buttonID[4])
{
bool selected = ObjectGetInteger(0,buttonID[4],OBJPROP_STATE);
if (selected)
{
Sleep(200);
int ans_bomb = MessageBox("確認是否掃除水雷?","確認命令",MB_YESNO|MB_ICONQUESTION);
if (ans_bomb == 6) iCloseOrders(OP_ALL);
ObjectSetInteger(0,buttonID[4],OBJPROP_STATE,false);
}
}
if(clickedChartObject == buttonID[5])
{
bool selected = ObjectGetInteger(0,buttonID[5],OBJPROP_STATE);
if (selected)
{
Sleep(200);
iCloseOrders(OP_SELL);
ObjectSetInteger(0,buttonID[5],OBJPROP_STATE,false);
}
}
if(clickedChartObject == buttonID[6])
{
bool selected = ObjectGetInteger(0,buttonID[6],OBJPROP_STATE);
if (selected)
{
Sleep(200);
iCloseOrders(OP_BUYSTOP);
iCloseOrders(OP_BUYLIMIT);
ObjectSetInteger(0,buttonID[6],OBJPROP_STATE,false);
}
}
if(clickedChartObject == buttonID[7])
{
bool selected = ObjectGetInteger(0,buttonID[7],OBJPROP_STATE);
if (selected)
{
Sleep(200);
iCloseOrders(OP_BUYSTOP);
iCloseOrders(OP_BUYLIMIT);
iCloseOrders(OP_SELLSTOP);
iCloseOrders(OP_SELLLIMIT);
ObjectSetInteger(0,buttonID[7],OBJPROP_STATE,false);
}
}
if(clickedChartObject == buttonID[8])
{
bool selected = ObjectGetInteger(0,buttonID[8],OBJPROP_STATE);
if (selected)
{
Sleep(200);
iCloseOrders(OP_SELLSTOP);
iCloseOrders(OP_SELLLIMIT);
ObjectSetInteger(0,buttonID[8],OBJPROP_STATE,false);
}
}
if(clickedChartObject == buttonID[9])
{
bool selected = ObjectGetInteger(0,buttonID[9],OBJPROP_STATE);
if (selected)
{
editClear();
CheckBoxCreate(1);
Sleep(200);
ObjectSetInteger(0,buttonID[9],OBJPROP_STATE,false);
}
}
if(clickedChartObject == buttonID[10])
{
bool selected = ObjectGetInteger(0,buttonID[10],OBJPROP_STATE);
if (selected)
{
VisiObjsSlave(true);
}else
{
VisiObjsSlave(false);
}
}
}
}
void CheckNewVersion(string match_Type,string match_Version)
{
int hInternet = 0;
int iResult = 0;
int lReturn[]={1};
uchar sBuffer[1024];
int bytes = 0;
string strUrl = "http://wargame.shinehope.com/wp-content/uploads/ew-xml/Update.csv";
string strWebPage = "";
hInternet=InternetOpenUrlW(hSession(false),strUrl,"",0,
INTERNET_FLAG_NO_CACHE_WRITE|
INTERNET_FLAG_PRAGMA_NOCACHE|
INTERNET_FLAG_RELOAD,0);
if(hInternet==0)
{
Alert("Check New Version Failed");
return;
}
int h1=FileOpen("Update.csv",FILE_CSV|FILE_SHARE_WRITE|FILE_SHARE_READ,',');
while(lReturn[0]!=0)
{
iResult=InternetReadFile(hInternet,sBuffer,BUFFER_LEN,lReturn);
if(lReturn[0]==0)
break;
bytes += lReturn[0];
strWebPage += CharArrayToString(sBuffer,0,lReturn[0],CP_ACP);
FileWriteString(h1, CharArrayToString(sBuffer,0,lReturn[0],CP_ACP), lReturn[0]);
}
FileSeek(h1,0,SEEK_SET);
string Buffer = "";
while(!FileIsEnding(h1))
{
Buffer = FileReadString(h1);
if (StringFind(Buffer,match_Type) >= 0)
{
Buffer = FileReadString(h1);
break;
}
}
FileClose(h1);
iResult=InternetCloseHandle(hInternet);
if(iResult==0)
{
Alert("Check New Version Failed");
return;
}
printf("EA Version: %s, New Version: %s",match_Version,Buffer);
if (Buffer != match_Version && Buffer != "")
{
Alert("已有新版封包,請向上級長官索取");
}
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;
}
void DeleteObj()
{
for (int i=0;i<40;i++)
{
if (i < ArraySize(BGID) && ObjectFind(0,BGID[i]) >= 0) ObjectDelete(BGID[i]);
if (i < ArraySize(logoID) && ObjectFind(0,logoID[i]) >= 0) ObjectDelete(logoID[i]);
if (i < ArraySize(buttonID) && ObjectFind(0,buttonID[i]) >= 0) ObjectDelete(buttonID[i]);
if (i < ArraySize(editID) && ObjectFind(0,editID[i]) >= 0) ObjectDelete(editID[i]);
if (i < ArraySize(labelID) && ObjectFind(0,labelID[i]) >= 0) ObjectDelete(labelID[i]);
if (i < ArraySize(CheckBox) && ObjectFind(0,CheckBox[i]) >= 0) ObjectDelete(CheckBox[i]);
if (i < ArraySize(VisiSW) && ObjectFind(0,VisiSW[i]) >= 0) ObjectDelete(VisiSW[i]);
if (i < ArraySize(buttonsID) && ObjectFind(0,buttonsID[i]) >= 0) ObjectDelete(buttonsID[i]);
if (i < ArraySize(labelsID) && ObjectFind(0,labelsID[i]) >= 0) ObjectDelete(labelsID[i]);
if (i < ArraySize(BGIDslave) && ObjectFind(0,BGIDslave[i]) >= 0) ObjectDelete(BGIDslave[i]);
if (i < ArraySize(editsID) && ObjectFind(0,editsID[i]) >= 0) ObjectDelete(editsID[i]);
if (i < ArraySize(CheckBoxs) && ObjectFind(0,CheckBoxs[i]) >= 0) ObjectDelete(CheckBoxs[i]);
}
}
void Set_SL_TP(const int Mode,const int Type,double iSL,double iTP)
{
double SL = 0.0;
double TP = 0.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)
{
if (Mode == MODE_SLTP_BYPOINT)
{
if (Type == OP_BUY || Type == OP_BUYSTOP || Type == OP_BUYLIMIT)
{
TP = OrderOpenPrice() + iTP * point;
SL = OrderOpenPrice() - iSL * point;
}
if (Type == OP_SELL || Type == OP_SELLSTOP || Type == OP_SELLLIMIT)
{
TP = OrderOpenPrice() - iTP * point;
SL = OrderOpenPrice() + iSL * point;
}
if (EqualZero(iTP)) TP = 0;
if (EqualZero(iSL)) SL = 0;
}else
{
SL = iSL;
TP = iTP;
}
if (iTP < 0)
{
TP = OrderTakeProfit();
}
if (iSL < 0)
{
SL = OrderStopLoss();
}
if ((CompareDouble(OrderStopLoss(),NormalizeDouble(SL,Digits))) && (CompareDouble(OrderTakeProfit(),NormalizeDouble(TP,Digits))))
{
continue;
}
else
{
RefreshRates();
if (!OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP,0,White))
{
Alert("Set_SL_TP " + IntegerToString(OrderTicket()) + " Error: " + ErrorDescription(GetLastError()));
}
}
}
}
}
int SendOrders(const int Type ,const string iComment,const double iPrice,const double iLots,const double iSL,const double iTP)
{
double InPrice = 0.0;
switch (Type)
{
case OP_BUY:
InPrice = Ask;
break;
case OP_SELL:
InPrice = Bid;
break;
default:
InPrice = iPrice;
break;
}
if (Type == OP_BUYSTOP || Type == OP_BUYLIMIT)
{
if (MathAbs(iPrice - Ask) / Point <= SymbolInfoInteger(NULL,SYMBOL_TRADE_STOPS_LEVEL))
{
return(-2);
}
}
if (Type == OP_SELLSTOP || Type == OP_SELLLIMIT)
{
if (MathAbs(iPrice - Bid) / Point <= SymbolInfoInteger(NULL,SYMBOL_TRADE_STOPS_LEVEL))
{
return(-2);
}
}
int Ticket = OrderSend(Symbol(),Type,iLots,InPrice,(int)(2 * (point / Point)),iSL,iTP,iComment,id_1,0,((Type & 1) == 1) ? clrRed : clrLime);
if (Ticket < 0)
{
ErrorCode = GetLastError();
if (ErrorCode != 4109)
Alert("Send " + iComment + " Order Error: " + ErrorDescription(ErrorCode));
}
return(Ticket);
}
bool CompareDouble(const double A,const double B)
{
if (MathAbs(A - B) <= TOLERANCE) return(true);
return(false);
}
bool EqualZero(const double A)
{
if (A <= TOLERANCE && A >= -TOLERANCE) return(true);
return(false);
}
void SaveParameter()
{
int h1 = FileOpen("Var.bin",FILE_CSV|FILE_WRITE);
if (h1 > 0)
{
for(int i=0;i<ArraySize(editID);i++)
{
FileWrite(h1,ObjectGetString(0,editID[i],OBJPROP_TEXT));
}
FileClose(h1);
}
}
void LoadPrevious()
{
int h1 = FileOpen("Var.bin",FILE_CSV|FILE_READ);
if (h1 > 0)
{
for(int i=0;i<ArraySize(editID);i++)
{
ObjectSetString(0,editID[i],OBJPROP_TEXT,FileReadString(h1));
}
FileClose(h1);
}
}
void iCloseOrders(const int type)
{
int C0_cnt;
if (type != OP_BUY && type != OP_SELL && type != OP_ALL)
{
for(C0_cnt=OrdersTotal()-1;C0_cnt>=0;C0_cnt--)
{
if (!OrderSelect(C0_cnt,SELECT_BY_POS,MODE_TRADES)) continue;
if (OrderSymbol()==Symbol()&&OrderType()==type && OrderMagicNumber()==id_1){
if (!OrderDelete(OrderTicket()))
{
ErrorCode = GetLastError();
if (ErrorCode != 4109)
Alert(ErrorDescription(ErrorCode));
}
}
}
}
if (type == OP_BUY || type == OP_SELL)
{
for(C0_cnt=OrdersTotal()-1;C0_cnt>=0;C0_cnt--) //從最近一張單開始
{
if (!OrderSelect(C0_cnt,SELECT_BY_POS,MODE_TRADES)) continue;
if (OrderSymbol()==Symbol()&&OrderType()==type && OrderMagicNumber()==id_1 && (ProfitOut ? (OrderProfit() > 0) : (ProfitOutLoss ? (OrderProfit() < 0) : true)))
{
if (!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),20,clrWhite))
{
ErrorCode = GetLastError();
if (ErrorCode != 4109)
{
Print("BS");
Alert(ErrorDescription(ErrorCode));
}
}
}
}
}
if (type == OP_ALL)
{
for(C0_cnt=OrdersTotal()-1;C0_cnt>=0;C0_cnt--)
{
if (!OrderSelect(C0_cnt,SELECT_BY_POS,MODE_TRADES)) continue;
if (OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP || OrderType() == OP_BUYLIMIT || OrderType() == OP_SELLLIMIT)
{
if (!OrderDelete(OrderTicket()))
{
ErrorCode = GetLastError();
if (ErrorCode != 4109)
{
Print("ALL Delete");
Alert(ErrorDescription(ErrorCode));
}
}
}else {
if ((ProfitOut ? (OrderProfit() > 0) : (ProfitOutLoss ? (OrderProfit() < 0) : true)))
{
if (!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),20,clrWhite))
{
ErrorCode = GetLastError();
if (ErrorCode != 4109)
{
Print("ALL Close");
Alert(ErrorDescription(ErrorCode));
}
}
}
}
}
}
}
int OutOrderType(const double inPrice,const int Type)
{
if (Type == OP_BUY)
{
if (inPrice > Ask)
{
return(OP_BUYSTOP);
}else if (inPrice < Ask)
{
return(OP_BUYLIMIT);
}
}
if (Type == OP_SELL)
{
if (inPrice > Bid)
{
return(OP_SELLLIMIT);
}else if (inPrice < Bid)
{
return(OP_SELLSTOP);
}
}
return(-1);
}
void iMoveStopLoss(const double SL)
{
int Cnt = 0;
for (int i=OrdersTotal()-1;i>=0;i--)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if (OrderMagicNumber() == id_1 && OrderSymbol() == Symbol())
{
if (OrderType() == OP_BUY && OrderProfit() > 0 && MathAbs(OrderClosePrice() - OrderOpenPrice()) / point >= SL)
{
if ((OrderClosePrice() - SL * point) > OrderStopLoss())
{
if (!CompareDouble(OrderStopLoss(),NormalizeDouble(OrderClosePrice() - SL * point,Digits)))
{
if (!OrderModify(OrderTicket(),OrderOpenPrice(),OrderClosePrice() - SL * point,OrderTakeProfit(),0,clrWhite))
{
Print("Trail Stop " + IntegerToString(OrderTicket()) + "Error: "+ ErrorDescription(GetLastError()));
}
}
}
}
if (OrderType() == OP_SELL && OrderProfit() > 0 && MathAbs(OrderClosePrice() - OrderOpenPrice()) / point >= SL)
{
if ((OrderClosePrice() + SL * point) < OrderStopLoss() || EqualZero(OrderStopLoss()))
{
if (!CompareDouble(OrderStopLoss(),NormalizeDouble(OrderClosePrice() + SL * point,Digits)))
{
if (!OrderModify(OrderTicket(),OrderOpenPrice(),OrderClosePrice() + SL * point,OrderTakeProfit(),0,clrWhite))
{
Print("Trail Stop " + IntegerToString(OrderTicket()) + "Error: "+ ErrorDescription(GetLastError()));
}
}
}
}
}
}
}
void iBE(const double BE,const double LV)
{
int Cnt = 0;
for (int i=OrdersTotal()-1;i>=0;i--)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if (OrderMagicNumber() == id_1 && OrderSymbol() == Symbol())
{
if (OrderType() == OP_BUY && OrderProfit() > 0 && MathAbs(OrderClosePrice() - OrderOpenPrice()) / point >= LV)
{
if (!(CompareDouble(OrderStopLoss(),NormalizeDouble(OrderOpenPrice() + BE * point,Digits))))
{
if (!OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice() + BE * point,OrderTakeProfit(),0,clrWhite))
{
Print("BE " + IntegerToString(OrderTicket()) + "Error: "+ ErrorDescription(GetLastError()));
}
}
}
if (OrderType() == OP_SELL && OrderProfit() > 0 && MathAbs(OrderClosePrice() - OrderOpenPrice()) / point >= LV)
{
if (!(CompareDouble(OrderStopLoss(),NormalizeDouble(OrderOpenPrice() - BE * point,Digits))))
{
if (!OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice() - BE * point,OrderTakeProfit(),0,clrWhite))
{
Print("BE " + IntegerToString(OrderTicket()) + "Error: "+ ErrorDescription(GetLastError()));
}
}
}
}
}
}
void CreateSW(const int Mode)
{
for (int i=0;i<ArraySize(VisiSW);i++)
{
if (ObjectFind(0,VisiSW[i]) < 0) ObjectCreate(0,VisiSW[i],OBJ_BUTTON,0,100,100);
ObjectSetInteger(0,VisiSW[i],OBJPROP_BGCOLOR,C'229,228,183');
ObjectSetInteger(0,VisiSW[i],OBJPROP_XSIZE,(int)(14 * DPIratio));
ObjectSetInteger(0,VisiSW[i],OBJPROP_YSIZE,(int)(14 * DPIratio));
ObjectSetInteger(0,VisiSW[i],OBJPROP_XDISTANCE,(int)(SWX(i) * DPIratio));
ObjectSetInteger(0,VisiSW[i],OBJPROP_YDISTANCE,(int)(0 * DPIratio));
ObjectSetInteger(0,VisiSW[i],OBJPROP_CORNER,0);
ObjectSetString(0,VisiSW[i],OBJPROP_FONT,"Webdings");
if (Mode == 1) ObjectSetString(0,VisiSW[i],OBJPROP_TEXT,SWstring(i));
//ObjectSetInteger(0,VisiSW[i],OBJPROP_FONTSIZE,15);
ObjectSetInteger(0,VisiSW[i],OBJPROP_SELECTABLE,0);
ObjectSetInteger(0,VisiSW[i],OBJPROP_ZORDER,10);
}
}
int SWX(const int in)
{
int Out = 0;
switch(in)
{
case 0:
Out = InitXDis + 340;
break;
case 1:
Out = InitXDis;
break;
case 2:
Out = InitXDis + 15;
break;
}
return(Out);
}
string SWstring(const int in)
{
string Out = "";
switch(in)
{
case 1:
Out = "3";
break;
case 2:
Out = "4";
break;
case 0:
Out = "5";
}
return(Out);
}
void VisiObjs(const bool SW)
{
for (int i=0;i<40;i++)
{
if (i < ArraySize(BGID) && ObjectFind(0,BGID[i]) >= 0) ObjectSetInteger(0,BGID[i],OBJPROP_TIMEFRAMES,(SW ? OBJ_ALL_PERIODS : EMPTY));
if (i < ArraySize(logoID) && ObjectFind(0,logoID[i]) >= 0) ObjectSetInteger(0,logoID[i],OBJPROP_TIMEFRAMES,(SW ? OBJ_ALL_PERIODS : EMPTY));
if (i < ArraySize(buttonID) && ObjectFind(0,buttonID[i]) >= 0) ObjectSetInteger(0,buttonID[i],OBJPROP_TIMEFRAMES,(SW ? OBJ_ALL_PERIODS : EMPTY));
if (i < ArraySize(editID) && ObjectFind(0,editID[i]) >= 0) ObjectSetInteger(0,editID[i],OBJPROP_TIMEFRAMES,(SW ? OBJ_ALL_PERIODS : EMPTY));
if (i < ArraySize(labelID) && ObjectFind(0,labelID[i]) >= 0) ObjectSetInteger(0,labelID[i],OBJPROP_TIMEFRAMES,(SW ? OBJ_ALL_PERIODS : EMPTY));
if (i < ArraySize(CheckBox) && ObjectFind(0,CheckBox[i]) >= 0) ObjectSetInteger(0,CheckBox[i],OBJPROP_TIMEFRAMES,(SW ? OBJ_ALL_PERIODS : EMPTY));
}
}
void VisiObjsSlave(const bool SW)
{
for (int i=0;i<40;i++)
{
if (i < ArraySize(BGIDslave) && ObjectFind(0,BGIDslave[i]) >= 0) ObjectSetInteger(0,BGIDslave[i],OBJPROP_TIMEFRAMES,(SW ? OBJ_ALL_PERIODS : EMPTY));
if (i < ArraySize(buttonsID) && ObjectFind(0,buttonsID[i]) >= 0) ObjectSetInteger(0,buttonsID[i],OBJPROP_TIMEFRAMES,(SW ? OBJ_ALL_PERIODS : EMPTY));
if (i < ArraySize(labelsID) && ObjectFind(0,labelsID[i]) >= 0) ObjectSetInteger(0,labelsID[i],OBJPROP_TIMEFRAMES,(SW ? OBJ_ALL_PERIODS : EMPTY));
if (i < ArraySize(editsID) && ObjectFind(0,editsID[i]) >= 0) ObjectSetInteger(0,editsID[i],OBJPROP_TIMEFRAMES,(SW ? OBJ_ALL_PERIODS : EMPTY));
if (i < ArraySize(CheckBoxs) && ObjectFind(0,CheckBoxs[i]) >= 0) ObjectSetInteger(0,CheckBoxs[i],OBJPROP_TIMEFRAMES,(SW ? OBJ_ALL_PERIODS : EMPTY));
}
}
void MarginCall()
{
double LotsB = 0.0;
double LotsS = 0.0;
double ProfitB = 0.0;
double ProfitS = 0.0;
int Buy = 0;
int Sell = 0;
for (int i=0;i<OrdersTotal();i++)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if (OrderSymbol() == Symbol())
{
if (OrderType() == OP_BUY)
{
LotsB += OrderLots();
ProfitB += OrderProfit() + OrderSwap() + OrderCommission();
Buy++;
}
if (OrderType() == OP_SELL)
{
LotsS += OrderLots();
ProfitS += OrderProfit() + OrderSwap() + OrderCommission();
Sell++;
}
}
}
double MarginLv = StringToDouble(ObjectGetString(0,editID[12],OBJPROP_TEXT)) * 0.01;
double MarginPips = 0.0;
double MarginPrice = 0.0;
if (EqualZero(LotsB - LotsS))
{
MarginPips = 0;
MarginPrice = 0;
}else
{
MarginPips = (((MarginLv * AccountMargin()) - AccountEquity()) / (LotsB - LotsS)) / 10;
MarginPrice = Bid + MarginPips * point;
}
ObjectSetString(0,labelID[15],OBJPROP_TEXT,DoubleToString(MarginPips,2));
ObjectSetString(0,labelID[17],OBJPROP_TEXT,DoubleToString(MarginPrice,Digits));
ObjectSetString(0,labelID[19],OBJPROP_TEXT,IntegerToString(Buy));
ObjectSetString(0,labelID[21],OBJPROP_TEXT,DoubleToString(LotsB,2));
ObjectSetString(0,labelID[23],OBJPROP_TEXT,IntegerToString(Sell));
ObjectSetString(0,labelID[25],OBJPROP_TEXT,DoubleToString(LotsS,2));
ObjectSetString(0,labelID[28],OBJPROP_TEXT,DoubleToString(ProfitB,2) + " USD");
ObjectSetString(0,labelID[30],OBJPROP_TEXT,DoubleToString(ProfitS,2) + " USD");
ObjectSetString(0,labelID[32],OBJPROP_TEXT,IntegerToString(OrdersTotal()));
ObjectSetString(0,labelID[34],OBJPROP_TEXT,DoubleToString(LotsB + LotsS,2));
ObjectSetString(0,labelID[36],OBJPROP_TEXT,DoubleToString(AccountProfit(),2) + " USD");
}
bool CheckAlledit()
{
int i = 0;
string str_temp = "";
for (;i<ArraySize(editID);i++)
{
str_temp = ObjectGetString(0,editID[i],OBJPROP_TEXT);
if ((i == 10 ? !CheckString(str_temp,0) : !CheckString(str_temp,1)))
{
Alert("不合法的參數,欄位 " + (i >= 7 ? labelText[i+1] : labelText[i]));
return(false);
}
}
for (i=0;i<ArraySize(editsID);i++)
{
str_temp = ObjectGetString(0,editsID[i],OBJPROP_TEXT);
if ((i == 10 ? !CheckString(str_temp,0) : !CheckString(str_temp,1)))
{
Alert("不合法的參數,欄位 " + (i >= 2 ? labelsText[i+2] : labelsText[i]));
return(false);
}
}
return(true);
}
bool CheckString(const string in,const int Mode)
{
for(int i=0;i<StringLen(in);i++)
{
if (!CheckChar(StringGetCharacter(in,i),Mode))
{
return(false);
}
}
return(true);
}
bool CheckChar(const ushort in,const int Mode)
{
if (Mode == 0)
{
if (in != '-' && in != '0' && in != '1' && in != '2' && in != '3' && in != '4' && in != '5' && in != '6' && in != '7' && in != '8' && in != '9' && in != '\0')
{
return(false);
}
}
if (Mode == 1)
{
if (in != '-' && in != '0' && in != '1' && in != '2' && in != '3' && in != '4' && in != '5' && in != '6' && in != '7' && in != '8' && in != '9' && in != '.' && in != '\0')
{
return(false);
}
}
return(true);
}
double Cal_TP(int Type,double iPrice,double Profit)
{
double TotalLots=0.0;
double TotalDisProduct=0.0;
double TP_Goal;
for (int i=0;i<OrdersTotal();i++)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if (OrderMagicNumber() == id_1 && OrderSymbol() == Symbol())
{
if (OrderType() == Type)
{
TotalLots += OrderLots();
if (Type == OP_SELL)
{
TotalDisProduct += (iPrice - OrderOpenPrice()) / point * OrderLots();
}
if (Type == OP_BUY)
{
TotalDisProduct += (OrderOpenPrice() - iPrice) / point * OrderLots();
}
}
if (Type == OP_ALL)
{
if (OrderType() == OP_SELL)
{
//Profit += ((OrderOpenPrice() - iPrice) / point * OrderLots()) * 10;
TotalLots += OrderLots();
TotalDisProduct += (iPrice - OrderOpenPrice()) / point * OrderLots();
}
if (OrderType() == OP_BUY)
{
//Profit += ((iPrice - OrderOpenPrice()) / point * OrderLots()) * 10;
TotalLots -= OrderLots();
TotalDisProduct += (OrderOpenPrice() - iPrice) / point * OrderLots();
}
}
}
}
if (EqualZero(TotalLots)) return(0.0);
TP_Goal = (((Profit) / 10) + TotalDisProduct) / TotalLots;
if (Type == OP_SELL)
return(iPrice - (TP_Goal * point));
if (Type == OP_BUY)
return(iPrice + (TP_Goal * point));
if (Type == OP_ALL)
{
return(TP_Goal > 0 ? (iPrice + (TP_Goal * point)) : (iPrice - (TP_Goal * point)));
}
return(0.0);
}
double Cal_Profit(int Type,double iPrice)
{
double Profit = 0.0;
for (int i=0;i<OrdersTotal();i++)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if (OrderMagicNumber() == id_1 && OrderSymbol() == Symbol())
{
if (OrderType() == Type)
{
if (Type == OP_SELL)
{
Profit += ((OrderOpenPrice() - iPrice) / point * OrderLots()) * 10;
}
if (Type == OP_BUY)
{
Profit += ((iPrice - OrderOpenPrice()) / point * OrderLots()) * 10;
}
}
if (Type == OP_ALL)
{
if (OrderType() == OP_SELL)
{
Profit += ((OrderOpenPrice() - iPrice) / point * OrderLots()) * 10;
}
if (OrderType() == OP_BUY)
{
Profit += ((iPrice - OrderOpenPrice()) / point * OrderLots()) * 10;
}
}
}
}
return(Profit);
}
bool CheckValid()
{
uchar temp[256] = {0};
int SW = 0;
if (!IsDemo())
{
SW = CheckList(AccountNumber(),2,temp);
string str_temp = CharArrayToString(temp,0,WHOLE_ARRAY,CP_UTF8);
StringReplace(str_temp,"\r\n","");
if (SW < 0 || str_temp == "1")
{
return(false);
}
}
return(true);
}
void UpdateFiles(const int Mode)
{
if (Mode == MODE_INIT)
{
if (!GlobalVariableCheck("DNSW")) GlobalVariableSet("DNSW",0);
if (GlobalVariableSetOnCondition("DNSW",1,0))
{
if (UninitializeReason() != 3)
{
Sleep(1000);
}
}
}
if (Mode == MODE_TICK)
{
if (TimeHour(TimeLocal()) == DownloadHour && TimeMinute(TimeLocal()) == DownloadMin && H1BarTime != iTime(Symbol(),PERIOD_H1,0))
{
if (!GlobalVariableCheck("DNSW0")) GlobalVariableSet("DNSW0",0);
if (GlobalVariableSetOnCondition("DNSW0",1,0))
{
Sleep(1000);
GlobalVariableSet("DNSW0",0);
}
H1BarTime = iTime(Symbol(),PERIOD_H1,0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment