|
@@ -216,7 +216,7 @@ void OnTimer()
|
|
|
read_history_file();
|
|
read_history_file();
|
|
|
|
|
|
|
|
readData();
|
|
readData();
|
|
|
-//writeDataClientCof();
|
|
|
|
|
|
|
+ writeDataClientCof();
|
|
|
}
|
|
}
|
|
|
//+------------------------------------------------------------------+
|
|
//+------------------------------------------------------------------+
|
|
|
//| |
|
|
//| |
|
|
@@ -260,19 +260,22 @@ void writeDataClientCof()
|
|
|
//if(((useMinimumLot && (PositionGetDouble(POSITION_VOLUME) > minimumLot)) || !useMinimumLot) &&
|
|
//if(((useMinimumLot && (PositionGetDouble(POSITION_VOLUME) > minimumLot)) || !useMinimumLot) &&
|
|
|
// ((useMaximumLot && (PositionGetDouble(POSITION_VOLUME) < maximumLot)) || !useMaximumLot))
|
|
// ((useMaximumLot && (PositionGetDouble(POSITION_VOLUME) < maximumLot)) || !useMaximumLot))
|
|
|
{
|
|
{
|
|
|
- string time = TimeToString(PositionGetInteger(POSITION_TIME)-gmtDifference, TIME_DATE|TIME_SECONDS);
|
|
|
|
|
|
|
+ string time = TimeToString(PositionGetInteger(POSITION_TIME)-gmtDifference,TIME_DATE|TIME_SECONDS);
|
|
|
string symbol = PositionGetString(POSITION_SYMBOL);
|
|
string symbol = PositionGetString(POSITION_SYMBOL);
|
|
|
- double digits = getDoubleSymbolInfo(symbol,"digits");
|
|
|
|
|
|
|
+ double digits=getDoubleSymbolInfo(symbol,"digits");
|
|
|
|
|
+
|
|
|
|
|
+ int symbolContractSize=(int)getDoubleSymbolInfo(symbol,"contract");
|
|
|
|
|
+
|
|
|
|
|
+ ulong tempTicket = PositionGetInteger(POSITION_TICKET);
|
|
|
|
|
|
|
|
if(suffix != "")
|
|
if(suffix != "")
|
|
|
symbol = StringSubstr(symbol, 0, StringFind(symbol, suffix, 0));
|
|
symbol = StringSubstr(symbol, 0, StringFind(symbol, suffix, 0));
|
|
|
if(prefix != "")
|
|
if(prefix != "")
|
|
|
StringReplace(symbol, prefix, "");
|
|
StringReplace(symbol, prefix, "");
|
|
|
|
|
|
|
|
- long orderType = PositionGetInteger(POSITION_TYPE);
|
|
|
|
|
- double takeProfit = PositionGetDouble(POSITION_TP);
|
|
|
|
|
- double stopLoss = PositionGetDouble(POSITION_SL);
|
|
|
|
|
|
|
|
|
|
|
|
+ long orderType = PositionGetInteger(POSITION_TYPE);
|
|
|
|
|
+ double takeProfit = PositionGetDouble(POSITION_TP), stopLoss = PositionGetDouble(POSITION_SL);
|
|
|
if(doReversal)
|
|
if(doReversal)
|
|
|
{
|
|
{
|
|
|
if(orderType == POSITION_TYPE_BUY)
|
|
if(orderType == POSITION_TYPE_BUY)
|
|
@@ -282,24 +285,23 @@ void writeDataClientCof()
|
|
|
orderType = POSITION_TYPE_BUY;
|
|
orderType = POSITION_TYPE_BUY;
|
|
|
|
|
|
|
|
takeProfit = PositionGetDouble(POSITION_SL);
|
|
takeProfit = PositionGetDouble(POSITION_SL);
|
|
|
- stopLoss = PositionGetDouble(POSITION_TP);
|
|
|
|
|
|
|
+ stopLoss = PositionGetDouble(POSITION_TP);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- string OrderToWrite =
|
|
|
|
|
- time + "," +
|
|
|
|
|
- symbol + "," +
|
|
|
|
|
- IntegerToString(orderType) + "," +
|
|
|
|
|
- DoubleToString(PositionGetDouble(POSITION_PRICE_OPEN),(int)digits) + "," +
|
|
|
|
|
- DoubleToString(PositionGetDouble(POSITION_VOLUME),2) + "," +
|
|
|
|
|
- DoubleToString(stopLoss,(int)digits) + "," +
|
|
|
|
|
- DoubleToString(takeProfit,(int)digits) + "," +
|
|
|
|
|
- IntegerToString(PositionGetInteger(POSITION_TICKET)) + "," +
|
|
|
|
|
- IntegerToString(PositionGetInteger(POSITION_MAGIC)) + "," +
|
|
|
|
|
- (string)AccountInfoDouble(ACCOUNT_BALANCE) + "," +
|
|
|
|
|
- (string)SymbolInfoDouble(PositionGetString(POSITION_SYMBOL), SYMBOL_TRADE_CONTRACT_SIZE) +
|
|
|
|
|
- PositionGetString(POSITION_COMMENT) + "\r\n";
|
|
|
|
|
|
|
+ double sumOfClosed = dealOutLotsCheck(0, PositionGetInteger(POSITION_TICKET));
|
|
|
|
|
+ double currentLot = PositionGetDouble(POSITION_VOLUME);
|
|
|
|
|
|
|
|
- FileWrite(fileHandleClientCof, OrderToWrite);
|
|
|
|
|
|
|
+ double totalLot = sumOfClosed + currentLot;
|
|
|
|
|
+ double closedPercentage = 0.0;
|
|
|
|
|
+
|
|
|
|
|
+ if(totalLot > 0.0)
|
|
|
|
|
+ closedPercentage = (sumOfClosed / totalLot) * 100.0;
|
|
|
|
|
+
|
|
|
|
|
+ Print(" Client Closed % = ", closedPercentage);
|
|
|
|
|
+
|
|
|
|
|
+ string OrderToWrite = time+","+symbol+","+IntegerToString(orderType)+","+DoubleToString(PositionGetDouble(POSITION_PRICE_OPEN), (int)digits)+","+DoubleToString(PositionGetDouble(POSITION_VOLUME),2)+","+DoubleToString(stopLoss,(int) digits)+","+DoubleToString(takeProfit, (int) digits)+","+IntegerToString(PositionGetInteger(POSITION_TICKET))+","+IntegerToString(PositionGetInteger(POSITION_MAGIC))+","+(string)AccountInfoDouble(ACCOUNT_BALANCE)+","+DoubleToString(closedPercentage)+","+(string)SymbolInfoDouble(PositionGetString(POSITION_SYMBOL),SYMBOL_TRADE_CONTRACT_SIZE)+PositionGetString(POSITION_COMMENT)+"\r\n";
|
|
|
|
|
+
|
|
|
|
|
+ FileWrite(filehandle,OrderToWrite);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -342,7 +344,7 @@ void writeDataClientCof()
|
|
|
takeProfit = OrderGetDouble(ORDER_SL);
|
|
takeProfit = OrderGetDouble(ORDER_SL);
|
|
|
stopLoss = OrderGetDouble(ORDER_TP);
|
|
stopLoss = OrderGetDouble(ORDER_TP);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ double closedPercentage = 0;
|
|
|
string OrderToWrite =
|
|
string OrderToWrite =
|
|
|
time + "," +
|
|
time + "," +
|
|
|
symbol + "," +
|
|
symbol + "," +
|
|
@@ -354,6 +356,7 @@ void writeDataClientCof()
|
|
|
IntegerToString(OrderGetInteger(ORDER_TICKET)) + "," +
|
|
IntegerToString(OrderGetInteger(ORDER_TICKET)) + "," +
|
|
|
IntegerToString(OrderGetInteger(ORDER_MAGIC)) + "," +
|
|
IntegerToString(OrderGetInteger(ORDER_MAGIC)) + "," +
|
|
|
(string)AccountInfoDouble(ACCOUNT_BALANCE) + "," +
|
|
(string)AccountInfoDouble(ACCOUNT_BALANCE) + "," +
|
|
|
|
|
+ DoubleToString(closedPercentage) +","+
|
|
|
(string)SymbolInfoDouble(OrderGetString(ORDER_SYMBOL), SYMBOL_TRADE_CONTRACT_SIZE) +
|
|
(string)SymbolInfoDouble(OrderGetString(ORDER_SYMBOL), SYMBOL_TRADE_CONTRACT_SIZE) +
|
|
|
OrderGetString(ORDER_COMMENT) + "\r\n";
|
|
OrderGetString(ORDER_COMMENT) + "\r\n";
|
|
|
|
|
|
|
@@ -827,29 +830,6 @@ void readData()
|
|
|
if(partialCloseOrderPosition!=-1)
|
|
if(partialCloseOrderPosition!=-1)
|
|
|
{
|
|
{
|
|
|
bool isOrderClose=false;
|
|
bool isOrderClose=false;
|
|
|
- //if(cod[partialCloseOrderPosition].masterLot <= 0)
|
|
|
|
|
- // {
|
|
|
|
|
- // Print("Error: Invalid masterLot for partial close");
|
|
|
|
|
- // continue;
|
|
|
|
|
- // }
|
|
|
|
|
- //if(OrderSelect(partialCloseOrderPosition,SELECT_BY_TICKET))
|
|
|
|
|
- {
|
|
|
|
|
- //Print("Master lot: ",order_array[i].lots," last save lot: ",cod[partialCloseOrderPosition].masterLot);
|
|
|
|
|
- //double lotClosePer = NormalizeDouble(100 - (order_array[i].lots/cod[partialCloseOrderPosition].masterLot*100),2);
|
|
|
|
|
- //Print("Order in master is closed in percentage: ",lotClosePer," last client lot: ",cod[partialCloseOrderPosition].lots);
|
|
|
|
|
- //double closeLot=NormalizeDouble(lotClosePer/100 *cod[partialCloseOrderPosition].lots,2);
|
|
|
|
|
- //Print("Close lot in client: ",closeLot);
|
|
|
|
|
- //if(!trade.PositionClosePartial(cod[partialCloseOrderPosition].ticket,closeLot))
|
|
|
|
|
- // {
|
|
|
|
|
- // Print("Partial order did not close:",cod[partialCloseOrderPosition].ticket);
|
|
|
|
|
- // }
|
|
|
|
|
- //else
|
|
|
|
|
- // {
|
|
|
|
|
- // isOrderClose=true;
|
|
|
|
|
- // cod[partialCloseOrderPosition].lots=cod[partialCloseOrderPosition].lots-closeLot; //PositionGetDouble(POSITION_VOLUME);
|
|
|
|
|
- // cod[partialCloseOrderPosition].masterLot = order_array[i].lots;
|
|
|
|
|
- // }
|
|
|
|
|
- }
|
|
|
|
|
double lotClosePer = NormalizeDouble((totalLot * percentageToClose) / 100,2);
|
|
double lotClosePer = NormalizeDouble((totalLot * percentageToClose) / 100,2);
|
|
|
if(percentageToClose > 0)
|
|
if(percentageToClose > 0)
|
|
|
{
|
|
{
|
|
@@ -1016,7 +996,30 @@ void readData()
|
|
|
{
|
|
{
|
|
|
int digitss = getDoubleSymbolInfo(PositionGetString(POSITION_SYMBOL), "digits");
|
|
int digitss = getDoubleSymbolInfo(PositionGetString(POSITION_SYMBOL), "digits");
|
|
|
trade_close = false;
|
|
trade_close = false;
|
|
|
- // if(PositionGetDouble(POSITION_TP)!=order_array[j].takeprofit || PositionGetDouble(POSITION_SL)!=order_array[j].stoploss)
|
|
|
|
|
|
|
+ //Print("TP/SL | norm cod TP=",NormalizeDouble(cod[i].takeprofit,digitss),
|
|
|
|
|
+ // " norm order TP=",NormalizeDouble(order_array[j].takeprofit,digitss),
|
|
|
|
|
+ // " | norm cod SL=",NormalizeDouble(cod[i].stoploss,digitss),
|
|
|
|
|
+ // " norm order SL=",NormalizeDouble(order_array[j].stoploss,digitss));
|
|
|
|
|
+
|
|
|
|
|
+ if(NormalizeDouble(cod[i].takeprofit, digitss) != NormalizeDouble(order_array[j].takeprofit, digitss))
|
|
|
|
|
+ {
|
|
|
|
|
+ if(NormalizeDouble(order_array[j].takeprofit, digitss) == NormalizeDouble(PositionGetDouble(POSITION_TP), digitss))
|
|
|
|
|
+ {
|
|
|
|
|
+ Print(" Client Position Tp Was Manually Modified. ");
|
|
|
|
|
+ cod[i].takeprofit=NormalizeDouble(order_array[j].takeprofit, digitss);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(NormalizeDouble(cod[i].stoploss, digitss) != NormalizeDouble(order_array[j].stoploss, digitss))
|
|
|
|
|
+ {
|
|
|
|
|
+ if(NormalizeDouble(order_array[j].stoploss, digitss) == NormalizeDouble(PositionGetDouble(POSITION_SL), digitss))
|
|
|
|
|
+ {
|
|
|
|
|
+ Print(" Client Position SL Was Manually Modified. ");
|
|
|
|
|
+ cod[i].stoploss = NormalizeDouble(order_array[j].stoploss, digitss);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
if(NormalizeDouble(cod[i].takeprofit, digitss) != NormalizeDouble(order_array[j].takeprofit, digitss) || NormalizeDouble(cod[i].stoploss, digitss) != NormalizeDouble(order_array[j].stoploss, digitss))
|
|
if(NormalizeDouble(cod[i].takeprofit, digitss) != NormalizeDouble(order_array[j].takeprofit, digitss) || NormalizeDouble(cod[i].stoploss, digitss) != NormalizeDouble(order_array[j].stoploss, digitss))
|
|
|
{
|
|
{
|
|
|
if(trade.PositionModify(PositionGetInteger(POSITION_TICKET),order_array[j].stoploss,order_array[j].takeprofit))
|
|
if(trade.PositionModify(PositionGetInteger(POSITION_TICKET),order_array[j].stoploss,order_array[j].takeprofit))
|
|
@@ -1027,6 +1030,7 @@ void readData()
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
|
|
+ //ExpertRemove();
|
|
|
Print("Order not modified error:",GetLastError());
|
|
Print("Order not modified error:",GetLastError());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1149,6 +1153,7 @@ void emptyStruct()
|
|
|
if(mod1[i].ticket != -1)
|
|
if(mod1[i].ticket != -1)
|
|
|
{
|
|
{
|
|
|
mod1[i].ticket=-1;
|
|
mod1[i].ticket=-1;
|
|
|
|
|
+ mod1[i].magic=0;
|
|
|
mod1[i].price=-1;
|
|
mod1[i].price=-1;
|
|
|
mod1[i].symbol="";
|
|
mod1[i].symbol="";
|
|
|
mod1[i].ordertype=-1;
|
|
mod1[i].ordertype=-1;
|