|
@@ -257,52 +257,48 @@ void writeDataClientCof()
|
|
|
ulong ticket = PositionGetTicket(i);
|
|
ulong ticket = PositionGetTicket(i);
|
|
|
if(PositionSelectByTicket(ticket))
|
|
if(PositionSelectByTicket(ticket))
|
|
|
{
|
|
{
|
|
|
- //if(((useMinimumLot && (PositionGetDouble(POSITION_VOLUME) > minimumLot)) || !useMinimumLot) &&
|
|
|
|
|
- // ((useMaximumLot && (PositionGetDouble(POSITION_VOLUME) < maximumLot)) || !useMaximumLot))
|
|
|
|
|
- {
|
|
|
|
|
- string time = TimeToString(PositionGetInteger(POSITION_TIME)-gmtDifference,TIME_DATE|TIME_SECONDS);
|
|
|
|
|
- string symbol = PositionGetString(POSITION_SYMBOL);
|
|
|
|
|
- double digits=getDoubleSymbolInfo(symbol,"digits");
|
|
|
|
|
|
|
+ string time = TimeToString(PositionGetInteger(POSITION_TIME)-gmtDifference,TIME_DATE|TIME_SECONDS);
|
|
|
|
|
+ string symbol = PositionGetString(POSITION_SYMBOL);
|
|
|
|
|
+ double digits=getDoubleSymbolInfo(symbol,"digits");
|
|
|
|
|
|
|
|
- int symbolContractSize=(int)getDoubleSymbolInfo(symbol,"contract");
|
|
|
|
|
|
|
+ int symbolContractSize=(int)getDoubleSymbolInfo(symbol,"contract");
|
|
|
|
|
|
|
|
- ulong tempTicket = PositionGetInteger(POSITION_TICKET);
|
|
|
|
|
|
|
+ ulong tempTicket = PositionGetInteger(POSITION_TICKET);
|
|
|
|
|
|
|
|
- if(suffix != "")
|
|
|
|
|
- symbol = StringSubstr(symbol, 0, StringFind(symbol, suffix, 0));
|
|
|
|
|
- if(prefix != "")
|
|
|
|
|
- StringReplace(symbol, prefix, "");
|
|
|
|
|
|
|
+ if(suffix != "")
|
|
|
|
|
+ symbol = StringSubstr(symbol, 0, StringFind(symbol, suffix, 0));
|
|
|
|
|
+ if(prefix != "")
|
|
|
|
|
+ StringReplace(symbol, prefix, "");
|
|
|
|
|
|
|
|
|
|
|
|
|
- long orderType = PositionGetInteger(POSITION_TYPE);
|
|
|
|
|
- double takeProfit = PositionGetDouble(POSITION_TP), stopLoss = PositionGetDouble(POSITION_SL);
|
|
|
|
|
- if(doReversal)
|
|
|
|
|
- {
|
|
|
|
|
- if(orderType == POSITION_TYPE_BUY)
|
|
|
|
|
- orderType = POSITION_TYPE_SELL;
|
|
|
|
|
- else
|
|
|
|
|
- if(orderType == POSITION_TYPE_SELL)
|
|
|
|
|
- orderType = POSITION_TYPE_BUY;
|
|
|
|
|
|
|
+ long orderType = PositionGetInteger(POSITION_TYPE);
|
|
|
|
|
+ double takeProfit = PositionGetDouble(POSITION_TP), stopLoss = PositionGetDouble(POSITION_SL);
|
|
|
|
|
+ if(doReversal)
|
|
|
|
|
+ {
|
|
|
|
|
+ if(orderType == POSITION_TYPE_BUY)
|
|
|
|
|
+ orderType = POSITION_TYPE_SELL;
|
|
|
|
|
+ else
|
|
|
|
|
+ if(orderType == POSITION_TYPE_SELL)
|
|
|
|
|
+ orderType = POSITION_TYPE_BUY;
|
|
|
|
|
|
|
|
- takeProfit = PositionGetDouble(POSITION_SL);
|
|
|
|
|
- stopLoss = PositionGetDouble(POSITION_TP);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ takeProfit = PositionGetDouble(POSITION_SL);
|
|
|
|
|
+ stopLoss = PositionGetDouble(POSITION_TP);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- double sumOfClosed = dealOutLotsCheck(0, PositionGetInteger(POSITION_TICKET));
|
|
|
|
|
- double currentLot = PositionGetDouble(POSITION_VOLUME);
|
|
|
|
|
|
|
+ double sumOfClosed = dealOutLotsCheck(0, PositionGetInteger(POSITION_TICKET));
|
|
|
|
|
+ double currentLot = PositionGetDouble(POSITION_VOLUME);
|
|
|
|
|
|
|
|
- double totalLot = sumOfClosed + currentLot;
|
|
|
|
|
- double closedPercentage = 0.0;
|
|
|
|
|
|
|
+ double totalLot = sumOfClosed + currentLot;
|
|
|
|
|
+ double closedPercentage = 0.0;
|
|
|
|
|
|
|
|
- if(totalLot > 0.0)
|
|
|
|
|
- closedPercentage = (sumOfClosed / totalLot) * 100.0;
|
|
|
|
|
|
|
+ if(totalLot > 0.0)
|
|
|
|
|
+ closedPercentage = (sumOfClosed / totalLot) * 100.0;
|
|
|
|
|
|
|
|
- Print(" Client Closed % = ", closedPercentage);
|
|
|
|
|
|
|
+ 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, 1)+","+(string)SymbolInfoDouble(PositionGetString(POSITION_SYMBOL),SYMBOL_TRADE_CONTRACT_SIZE)+PositionGetString(POSITION_COMMENT)+"\r\n";
|
|
|
|
|
|
|
+ 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, 1)+","+(string)SymbolInfoDouble(PositionGetString(POSITION_SYMBOL),SYMBOL_TRADE_CONTRACT_SIZE)+PositionGetString(POSITION_COMMENT)+"\r\n";
|
|
|
|
|
|
|
|
- FileWrite(filehandle,OrderToWrite);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ FileWrite(filehandle,OrderToWrite);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -311,58 +307,54 @@ void writeDataClientCof()
|
|
|
ulong ticket = OrderGetTicket(i);
|
|
ulong ticket = OrderGetTicket(i);
|
|
|
if(OrderSelect(ticket))
|
|
if(OrderSelect(ticket))
|
|
|
{
|
|
{
|
|
|
- //if(((useMinimumLot && (OrderGetDouble(ORDER_VOLUME_CURRENT) > minimumLot)) || !useMinimumLot) &&
|
|
|
|
|
- // ((useMaximumLot && (OrderGetDouble(ORDER_VOLUME_CURRENT) < maximumLot)) || !useMaximumLot))
|
|
|
|
|
- {
|
|
|
|
|
- string time = TimeToString(OrderGetInteger(ORDER_TIME_SETUP)-gmtDifference, TIME_DATE|TIME_SECONDS);
|
|
|
|
|
- string symbol = OrderGetString(ORDER_SYMBOL);
|
|
|
|
|
- double digits = getDoubleSymbolInfo(symbol,"digits");
|
|
|
|
|
|
|
+ string time = TimeToString(OrderGetInteger(ORDER_TIME_SETUP)-gmtDifference, TIME_DATE|TIME_SECONDS);
|
|
|
|
|
+ string symbol = OrderGetString(ORDER_SYMBOL);
|
|
|
|
|
+ double digits = getDoubleSymbolInfo(symbol,"digits");
|
|
|
|
|
|
|
|
- if(suffix != "")
|
|
|
|
|
- symbol = StringSubstr(symbol, 0, StringFind(symbol, suffix, 0));
|
|
|
|
|
- if(prefix != "")
|
|
|
|
|
- StringReplace(symbol, prefix, "");
|
|
|
|
|
|
|
+ if(suffix != "")
|
|
|
|
|
+ symbol = StringSubstr(symbol, 0, StringFind(symbol, suffix, 0));
|
|
|
|
|
+ if(prefix != "")
|
|
|
|
|
+ StringReplace(symbol, prefix, "");
|
|
|
|
|
|
|
|
- long orderType = OrderGetInteger(ORDER_TYPE);
|
|
|
|
|
- double takeProfit = OrderGetDouble(ORDER_TP);
|
|
|
|
|
- double stopLoss = OrderGetDouble(ORDER_SL);
|
|
|
|
|
|
|
+ long orderType = OrderGetInteger(ORDER_TYPE);
|
|
|
|
|
+ double takeProfit = OrderGetDouble(ORDER_TP);
|
|
|
|
|
+ double stopLoss = OrderGetDouble(ORDER_SL);
|
|
|
|
|
|
|
|
- if(doReversal)
|
|
|
|
|
- {
|
|
|
|
|
- if(orderType == ORDER_TYPE_BUY_STOP)
|
|
|
|
|
- orderType = ORDER_TYPE_SELL_LIMIT;
|
|
|
|
|
|
|
+ if(doReversal)
|
|
|
|
|
+ {
|
|
|
|
|
+ if(orderType == ORDER_TYPE_BUY_STOP)
|
|
|
|
|
+ orderType = ORDER_TYPE_SELL_LIMIT;
|
|
|
|
|
+ else
|
|
|
|
|
+ if(orderType == ORDER_TYPE_SELL_STOP)
|
|
|
|
|
+ orderType = ORDER_TYPE_BUY_LIMIT;
|
|
|
else
|
|
else
|
|
|
- if(orderType == ORDER_TYPE_SELL_STOP)
|
|
|
|
|
- orderType = ORDER_TYPE_BUY_LIMIT;
|
|
|
|
|
|
|
+ if(orderType == ORDER_TYPE_BUY_LIMIT)
|
|
|
|
|
+ orderType = ORDER_TYPE_SELL_STOP;
|
|
|
else
|
|
else
|
|
|
- if(orderType == ORDER_TYPE_BUY_LIMIT)
|
|
|
|
|
- orderType = ORDER_TYPE_SELL_STOP;
|
|
|
|
|
- else
|
|
|
|
|
- if(orderType == ORDER_TYPE_SELL_LIMIT)
|
|
|
|
|
- orderType = ORDER_TYPE_BUY_STOP;
|
|
|
|
|
|
|
+ if(orderType == ORDER_TYPE_SELL_LIMIT)
|
|
|
|
|
+ orderType = ORDER_TYPE_BUY_STOP;
|
|
|
|
|
|
|
|
- takeProfit = OrderGetDouble(ORDER_SL);
|
|
|
|
|
- stopLoss = OrderGetDouble(ORDER_TP);
|
|
|
|
|
- }
|
|
|
|
|
- double closedPercentage = 0;
|
|
|
|
|
- string OrderToWrite =
|
|
|
|
|
- time + "," +
|
|
|
|
|
- symbol + "," +
|
|
|
|
|
- IntegerToString(orderType) + "," +
|
|
|
|
|
- DoubleToString(OrderGetDouble(ORDER_PRICE_OPEN),(int)digits) + "," +
|
|
|
|
|
- DoubleToString(OrderGetDouble(ORDER_VOLUME_CURRENT),2) + "," +
|
|
|
|
|
- DoubleToString(stopLoss,(int)digits) + "," +
|
|
|
|
|
- DoubleToString(takeProfit,(int)digits) + "," +
|
|
|
|
|
- IntegerToString(OrderGetInteger(ORDER_TICKET)) + "," +
|
|
|
|
|
- IntegerToString(OrderGetInteger(ORDER_MAGIC)) + "," +
|
|
|
|
|
- (string)AccountInfoDouble(ACCOUNT_BALANCE) + "," +
|
|
|
|
|
- DoubleToString(closedPercentage) +","+
|
|
|
|
|
- (string)SymbolInfoDouble(OrderGetString(ORDER_SYMBOL), SYMBOL_TRADE_CONTRACT_SIZE) +
|
|
|
|
|
- OrderGetString(ORDER_COMMENT) + "\r\n";
|
|
|
|
|
-
|
|
|
|
|
- Print("Client Cof Writing Pending Order Block.");
|
|
|
|
|
- FileWrite(fileHandleClientCof, OrderToWrite);
|
|
|
|
|
|
|
+ takeProfit = OrderGetDouble(ORDER_SL);
|
|
|
|
|
+ stopLoss = OrderGetDouble(ORDER_TP);
|
|
|
}
|
|
}
|
|
|
|
|
+ double closedPercentage = 0;
|
|
|
|
|
+ string OrderToWrite =
|
|
|
|
|
+ time + "," +
|
|
|
|
|
+ symbol + "," +
|
|
|
|
|
+ IntegerToString(orderType) + "," +
|
|
|
|
|
+ DoubleToString(OrderGetDouble(ORDER_PRICE_OPEN),(int)digits) + "," +
|
|
|
|
|
+ DoubleToString(OrderGetDouble(ORDER_VOLUME_CURRENT),2) + "," +
|
|
|
|
|
+ DoubleToString(stopLoss,(int)digits) + "," +
|
|
|
|
|
+ DoubleToString(takeProfit,(int)digits) + "," +
|
|
|
|
|
+ IntegerToString(OrderGetInteger(ORDER_TICKET)) + "," +
|
|
|
|
|
+ IntegerToString(OrderGetInteger(ORDER_MAGIC)) + "," +
|
|
|
|
|
+ (string)AccountInfoDouble(ACCOUNT_BALANCE) + "," +
|
|
|
|
|
+ DoubleToString(closedPercentage) +","+
|
|
|
|
|
+ (string)SymbolInfoDouble(OrderGetString(ORDER_SYMBOL), SYMBOL_TRADE_CONTRACT_SIZE) +
|
|
|
|
|
+ OrderGetString(ORDER_COMMENT) + "\r\n";
|
|
|
|
|
+
|
|
|
|
|
+ Print("Client Cof Writing Pending Order Block.");
|
|
|
|
|
+ FileWrite(fileHandleClientCof, OrderToWrite);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -813,9 +805,6 @@ void readData()
|
|
|
if(closedPercentage < order_array[i].closedPercentageOfTrade)
|
|
if(closedPercentage < order_array[i].closedPercentageOfTrade)
|
|
|
{
|
|
{
|
|
|
percentageToClose = MathAbs(order_array[i].closedPercentageOfTrade - closedPercentage);
|
|
percentageToClose = MathAbs(order_array[i].closedPercentageOfTrade - closedPercentage);
|
|
|
- //Print(" Cod Lot Size: ", cod[j].masterLot, " Order Array Lot: ", order_array[i].lots);
|
|
|
|
|
- //Print("Closed % = ", closedPercentage, " Master Ticket Percentage: ", order_array[i].closedPercentageOfTrade);
|
|
|
|
|
- //Print("Order is partial close:",cod[j].magic, " Percentage To Be Closed: ", percentageToClose);
|
|
|
|
|
trade_taken=1;
|
|
trade_taken=1;
|
|
|
partialCloseOrderPosition=j;
|
|
partialCloseOrderPosition=j;
|
|
|
}
|
|
}
|
|
@@ -838,20 +827,17 @@ void readData()
|
|
|
roundDigit++;
|
|
roundDigit++;
|
|
|
step=step*10;
|
|
step=step*10;
|
|
|
}
|
|
}
|
|
|
- // Print("Round Digits:", roundDigit);
|
|
|
|
|
|
|
+
|
|
|
double lotClosePer = NormalizeDouble((totalLot * percentageToClose) / 100, roundDigit);
|
|
double lotClosePer = NormalizeDouble((totalLot * percentageToClose) / 100, roundDigit);
|
|
|
if(percentageToClose > 0 && lotClosePer > SymbolInfoDouble(cod[partialCloseOrderPosition].symbol,SYMBOL_VOLUME_MIN))
|
|
if(percentageToClose > 0 && lotClosePer > SymbolInfoDouble(cod[partialCloseOrderPosition].symbol,SYMBOL_VOLUME_MIN))
|
|
|
{
|
|
{
|
|
|
if(!trade.PositionClosePartial(cod[partialCloseOrderPosition].ticket, lotClosePer))
|
|
if(!trade.PositionClosePartial(cod[partialCloseOrderPosition].ticket, lotClosePer))
|
|
|
{
|
|
{
|
|
|
- // ExpertRemove();
|
|
|
|
|
Print("Partial order did not close:",cod[partialCloseOrderPosition].ticket, " Lot To Close is: ", lotClosePer);
|
|
Print("Partial order did not close:",cod[partialCloseOrderPosition].ticket, " Lot To Close is: ", lotClosePer);
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
isOrderClose=true;
|
|
isOrderClose=true;
|
|
|
- //cod[partialCloseOrderPosition].lots=cod[partialCloseOrderPosition].lots-closeLot; //PositionGetDouble(POSITION_VOLUME);
|
|
|
|
|
- //cod[partialCloseOrderPosition].masterLot = order_array[i].lots;
|
|
|
|
|
Print("Order Partial Close. currentLot Was =", currentLot,
|
|
Print("Order Partial Close. currentLot Was =", currentLot,
|
|
|
" Percentage to close = ", percentageToClose,
|
|
" Percentage to close = ", percentageToClose,
|
|
|
" Lot I am Going To close = ", lotClosePer);
|
|
" Lot I am Going To close = ", lotClosePer);
|