update EA
This commit is contained in:
@@ -98,6 +98,7 @@ input int InpTrailingStepPoints = 50;
|
||||
input bool InpUseSoftStopLoss = true;
|
||||
input bool InpUseAutoRecovery = true;
|
||||
input bool InpEnableDashboard = true;
|
||||
input int InpCSVReloadInterval = 60;
|
||||
|
||||
CTrade Trade;
|
||||
CSymbolInfo SymbolInfo;
|
||||
@@ -199,6 +200,7 @@ double LastPrice = 0.0;
|
||||
double CachedFuturePrice = -1;
|
||||
string LoadedCSVPath = "";
|
||||
bool CSVLoadLogged = false;
|
||||
datetime LastCSVReloadTime = 0;
|
||||
|
||||
int OnInit() {
|
||||
Trade.SetExpertMagicNumber(InpMagicNumber);
|
||||
@@ -301,13 +303,22 @@ void OnTick() {
|
||||
}
|
||||
|
||||
void OnTimer() {
|
||||
if(InpEnableDashboard && TimeCurrent() - LastDashboardUpdate >= 1) {
|
||||
UpdateDashboard();
|
||||
UpdateControlPanel();
|
||||
LastDashboardUpdate = TimeCurrent();
|
||||
}
|
||||
|
||||
CheckDailyReset();
|
||||
if(InpEnableDashboard && TimeCurrent() - LastDashboardUpdate >= 1) {
|
||||
UpdateDashboard();
|
||||
UpdateControlPanel();
|
||||
LastDashboardUpdate = TimeCurrent();
|
||||
}
|
||||
|
||||
CheckDailyReset();
|
||||
|
||||
if(InpOISource == OI_SOURCE_CSV_FILE && InpCSVReloadInterval > 0) {
|
||||
if(TimeCurrent() - LastCSVReloadTime >= InpCSVReloadInterval * 60) {
|
||||
Print("CSV Reload: Scheduled reload triggered");
|
||||
LastCSVReloadTime = TimeCurrent();
|
||||
CachedFuturePrice = -1;
|
||||
LoadOIFromCSV();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) {
|
||||
@@ -1007,111 +1018,71 @@ bool InitializeIndicators() {
|
||||
|
||||
void LoadOIFromCSV()
|
||||
{
|
||||
string paths[];
|
||||
int pathCount = 0;
|
||||
|
||||
ArrayResize(paths, 5);
|
||||
paths[pathCount++] = InpOICsvPath;
|
||||
paths[pathCount++] = "oi_data.csv";
|
||||
paths[pathCount++] = "\\Files\\oi_data.csv";
|
||||
paths[pathCount++] = "..\\oi_scraper\\oi_data.csv";
|
||||
paths[pathCount++] = "../oi_scraper/oi_data.csv";
|
||||
|
||||
int filehandle = INVALID_HANDLE;
|
||||
string foundPath = "";
|
||||
|
||||
for(int i = 0; i < pathCount; i++) {
|
||||
if(!CSVLoadLogged) {
|
||||
Print("Trying CSV path: ", paths[i]);
|
||||
}
|
||||
filehandle = FileOpen(paths[i], FILE_READ | FILE_CSV | FILE_ANSI, ',');
|
||||
if(filehandle != INVALID_HANDLE) {
|
||||
foundPath = paths[i];
|
||||
if(!CSVLoadLogged) {
|
||||
Print("Found CSV file at: ", foundPath);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(filehandle == INVALID_HANDLE) {
|
||||
if(!CSVLoadLogged) {
|
||||
Print("CSV ERROR: File not found. Searched paths:");
|
||||
for(int i = 0; i < pathCount; i++) {
|
||||
Print(" - ", paths[i]);
|
||||
}
|
||||
CSVLoadLogged = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int callIndex = 0;
|
||||
int putIndex = 0;
|
||||
double futurePrice = 0.0;
|
||||
|
||||
while(!FileIsEnding(filehandle) && (callIndex < 3 || putIndex < 3))
|
||||
{
|
||||
string row = FileReadString(filehandle);
|
||||
string data[];
|
||||
int count = StringSplit(row, ',', data);
|
||||
|
||||
if(count >= 3)
|
||||
{
|
||||
string type = data[0];
|
||||
double strike = StringToDouble(data[1]);
|
||||
int oi = (int)StringToInteger(data[2]);
|
||||
|
||||
if(StringFind(type, "Future") >= 0)
|
||||
{
|
||||
futurePrice = strike;
|
||||
if(!CSVLoadLogged) {
|
||||
Print("DEBUG: Parsed Future price: ", futurePrice);
|
||||
}
|
||||
}
|
||||
else if(type == "CALL" && callIndex < 3)
|
||||
{
|
||||
CallLevels[callIndex] = strike;
|
||||
CallOI[callIndex] = oi;
|
||||
callIndex++;
|
||||
}
|
||||
else if(type == "PUT" && putIndex < 3)
|
||||
{
|
||||
PutLevels[putIndex] = strike;
|
||||
PutOI[putIndex] = oi;
|
||||
putIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FileClose(filehandle);
|
||||
|
||||
for(int i = callIndex; i < 3; i++)
|
||||
{
|
||||
CallLevels[i] = 0;
|
||||
CallOI[i] = 0;
|
||||
}
|
||||
|
||||
for(int i = putIndex; i < 3; i++)
|
||||
{
|
||||
PutLevels[i] = 0;
|
||||
PutOI[i] = 0;
|
||||
}
|
||||
|
||||
if(futurePrice > 0) {
|
||||
CachedFuturePrice = futurePrice;
|
||||
DynamicFuturePrice = futurePrice;
|
||||
LoadedCSVPath = foundPath;
|
||||
CSVLoadLogged = true;
|
||||
Print("CSV SUCCESS: FuturePrice=", futurePrice, ", CALL=[", CallLevels[0], ",", CallLevels[1], ",", CallLevels[2], "], PUT=[", PutLevels[0], ",", PutLevels[1], ",", PutLevels[2], "] loaded from ", foundPath);
|
||||
} else {
|
||||
if(!CSVLoadLogged) {
|
||||
Print("CSV ERROR: No valid price found in ", foundPath);
|
||||
CSVLoadLogged = true;
|
||||
}
|
||||
CachedFuturePrice = 0;
|
||||
}
|
||||
|
||||
InitializeKeyLevels();
|
||||
int filehandle = FileOpen(InpOICsvPath, FILE_READ | FILE_CSV | FILE_ANSI, ',');
|
||||
|
||||
if(filehandle == INVALID_HANDLE)
|
||||
{
|
||||
Print("CSV ERROR: Cannot open ", InpOICsvPath);
|
||||
return;
|
||||
}
|
||||
|
||||
int callIndex = 0;
|
||||
int putIndex = 0;
|
||||
double futurePrice = 0.0;
|
||||
bool isFirstLine = true;
|
||||
|
||||
while(!FileIsEnding(filehandle) && (callIndex < 3 || putIndex < 3))
|
||||
{
|
||||
string row = FileReadString(filehandle);
|
||||
|
||||
if(isFirstLine) {
|
||||
isFirstLine = false;
|
||||
if(StringFind(row, "Type") >= 0 || StringFind(row, "Strike") >= 0 || StringFind(row, "OI") >= 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
string data[];
|
||||
int count = StringSplit(row, ',', data);
|
||||
|
||||
if(count >= 3)
|
||||
{
|
||||
string type = data[0];
|
||||
double strike = StringToDouble(data[1]);
|
||||
int oi = (int)StringToInteger(data[2]);
|
||||
|
||||
if(StringFind(type, "Future") >= 0)
|
||||
{
|
||||
futurePrice = strike;
|
||||
}
|
||||
else if(type == "CALL" && callIndex < 3)
|
||||
{
|
||||
CallLevels[callIndex] = strike;
|
||||
CallOI[callIndex] = oi;
|
||||
callIndex++;
|
||||
}
|
||||
else if(type == "PUT" && putIndex < 3)
|
||||
{
|
||||
PutLevels[putIndex] = strike;
|
||||
PutOI[putIndex] = oi;
|
||||
putIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FileClose(filehandle);
|
||||
|
||||
for(int i = callIndex; i < 3; i++) { CallLevels[i] = 0; CallOI[i] = 0; }
|
||||
for(int i = putIndex; i < 3; i++) { PutLevels[i] = 0; PutOI[i] = 0; }
|
||||
|
||||
if(futurePrice > 0) {
|
||||
CachedFuturePrice = futurePrice;
|
||||
DynamicFuturePrice = futurePrice;
|
||||
FuturePrice = futurePrice;
|
||||
Print("CSV SUCCESS: FuturePrice=", futurePrice);
|
||||
}
|
||||
|
||||
InitializeKeyLevels();
|
||||
}
|
||||
|
||||
void CheckExistingPositions() {
|
||||
@@ -1355,34 +1326,6 @@ void UpdateInputValues() {
|
||||
DynamicFuturePrice = StringToDouble(value);
|
||||
}
|
||||
|
||||
if(ObjectGetString(chart_id, "CP_CallStrike1", OBJPROP_TEXT, 0, value)) {
|
||||
DynamicCallStrike1 = StringToDouble(value);
|
||||
}
|
||||
if(ObjectGetString(chart_id, "CP_CallStrike2", OBJPROP_TEXT, 0, value)) {
|
||||
DynamicCallStrike2 = StringToDouble(value);
|
||||
}
|
||||
if(ObjectGetString(chart_id, "CP_CallStrike3", OBJPROP_TEXT, 0, value)) {
|
||||
DynamicCallStrike3 = StringToDouble(value);
|
||||
}
|
||||
if(ObjectGetString(chart_id, "CP_PutStrike1", OBJPROP_TEXT, 0, value)) {
|
||||
DynamicPutStrike1 = StringToDouble(value);
|
||||
}
|
||||
if(ObjectGetString(chart_id, "CP_PutStrike2", OBJPROP_TEXT, 0, value)) {
|
||||
DynamicPutStrike2 = StringToDouble(value);
|
||||
}
|
||||
if(ObjectGetString(chart_id, "CP_PutStrike3", OBJPROP_TEXT, 0, value)) {
|
||||
DynamicPutStrike3 = StringToDouble(value);
|
||||
}
|
||||
|
||||
InitializeOILevels();
|
||||
InitializeKeyLevels();
|
||||
|
||||
if(InpOISource == OI_SOURCE_CSV_FILE) {
|
||||
CachedFuturePrice = -1;
|
||||
LoadOIFromCSV();
|
||||
}
|
||||
}
|
||||
|
||||
if(ObjectGetString(chart_id, "CP_CallStrike1", OBJPROP_TEXT, 0, value)) {
|
||||
DynamicCallStrike1 = StringToDouble(value);
|
||||
}
|
||||
@@ -1403,9 +1346,10 @@ void UpdateInputValues() {
|
||||
}
|
||||
|
||||
InitializeOILevels();
|
||||
InitializeKeyLevels();
|
||||
|
||||
if(InpOISource == OI_SOURCE_CSV_FILE) {
|
||||
LoadOIFromCSV();
|
||||
}
|
||||
}
|
||||
InitializeKeyLevels();
|
||||
|
||||
if(InpOISource == OI_SOURCE_CSV_FILE) {
|
||||
CachedFuturePrice = -1;
|
||||
LoadOIFromCSV();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user