|
@@ -101,21 +101,21 @@ void OnTimer()
|
|
|
int buyTickett = -1, sellTickett = -1;
|
|
int buyTickett = -1, sellTickett = -1;
|
|
|
//Print(" Symbol to Buy is: ", symbolToBuy, " Symbol to Sell: ", symbolToSell);
|
|
//Print(" Symbol to Buy is: ", symbolToBuy, " Symbol to Sell: ", symbolToSell);
|
|
|
|
|
|
|
|
- if(canTradeSymbol(symbolToBuy, symbolToSell, POSITION_TYPE_BUY, POSITION_TYPE_SELL))
|
|
|
|
|
|
|
+ if(noOfActiveCombinations() < maxOpenPositions)
|
|
|
{
|
|
{
|
|
|
- if(noOfActiveOrdersOfType(POSITION_TYPE_BUY) < maxOpenPositions)
|
|
|
|
|
|
|
+ if(canTradeSymbol(symbolToBuy, symbolToSell, POSITION_TYPE_BUY, POSITION_TYPE_SELL))
|
|
|
{
|
|
{
|
|
|
- if(symbolToBuy != NULL && symbolToBuy != "")
|
|
|
|
|
|
|
+ if(symbolToBuy != symbolToSell)
|
|
|
{
|
|
{
|
|
|
- buyTickett = placeBuyTrade(symbolToBuy);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if(symbolToBuy != NULL && symbolToBuy != "")
|
|
|
|
|
+ {
|
|
|
|
|
+ buyTickett = placeBuyTrade(symbolToBuy);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if(noOfActiveOrdersOfType(POSITION_TYPE_SELL) < maxOpenPositions)
|
|
|
|
|
- {
|
|
|
|
|
- if(symbolToSell != NULL && symbolToSell != "")
|
|
|
|
|
- {
|
|
|
|
|
- sellTickett = placeSellTrade(symbolToSell);
|
|
|
|
|
|
|
+ if(symbolToSell != NULL && symbolToSell != "")
|
|
|
|
|
+ {
|
|
|
|
|
+ sellTickett = placeSellTrade(symbolToSell);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -271,21 +271,14 @@ string getSymbolWithHighestBid()
|
|
|
//+------------------------------------------------------------------+
|
|
//+------------------------------------------------------------------+
|
|
|
//| |
|
|
//| |
|
|
|
//+------------------------------------------------------------------+
|
|
//+------------------------------------------------------------------+
|
|
|
-int noOfActiveOrdersOfType(ENUM_POSITION_TYPE type)
|
|
|
|
|
|
|
+int noOfActiveCombinations()
|
|
|
{
|
|
{
|
|
|
int count = 0;
|
|
int count = 0;
|
|
|
-
|
|
|
|
|
- for(int i= PositionsTotal()-1; i>=0; i--)
|
|
|
|
|
|
|
+ for(int i = 0; i < MaxOrders; i++)
|
|
|
{
|
|
{
|
|
|
- ulong ticket = PositionGetTicket(i);
|
|
|
|
|
- if(PositionSelectByTicket(ticket))
|
|
|
|
|
|
|
+ if(newTradeStore[i].buyTicket != -1 && newTradeStore[i].sellTicket != -1)
|
|
|
{
|
|
{
|
|
|
- if(PositionGetInteger(POSITION_MAGIC) == magicNo
|
|
|
|
|
- && (PositionGetInteger(POSITION_TYPE) == type)
|
|
|
|
|
- && isGoldPair(PositionGetString(POSITION_SYMBOL)))
|
|
|
|
|
- {
|
|
|
|
|
- count++;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ count++;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return count;
|
|
return count;
|
|
@@ -295,52 +288,33 @@ int noOfActiveOrdersOfType(ENUM_POSITION_TYPE type)
|
|
|
//+------------------------------------------------------------------+
|
|
//+------------------------------------------------------------------+
|
|
|
void checkBasketTakeProfit()
|
|
void checkBasketTakeProfit()
|
|
|
{
|
|
{
|
|
|
- double netProfit = 0;
|
|
|
|
|
-
|
|
|
|
|
- for(int i = PositionsTotal() - 1; i >= 0; i--)
|
|
|
|
|
|
|
+ for(int i = 0; i < MaxOrders; i++)
|
|
|
{
|
|
{
|
|
|
- ulong ticket = PositionGetTicket(i);
|
|
|
|
|
- if(PositionSelectByTicket(ticket))
|
|
|
|
|
|
|
+ if(newTradeStore[i].buyTicket != -1 && newTradeStore[i].sellTicket != -1)
|
|
|
{
|
|
{
|
|
|
- if(isGoldPair(PositionGetString(POSITION_SYMBOL)) &&
|
|
|
|
|
- PositionGetInteger(POSITION_MAGIC) == magicNo)
|
|
|
|
|
|
|
+ double combinationProfit = 0;
|
|
|
|
|
+
|
|
|
|
|
+ if(PositionSelectByTicket(newTradeStore[i].buyTicket))
|
|
|
{
|
|
{
|
|
|
- netProfit += PositionGetDouble(POSITION_PROFIT)+PositionGetDouble(POSITION_SWAP);
|
|
|
|
|
|
|
+ combinationProfit += PositionGetDouble(POSITION_PROFIT) + PositionGetDouble(POSITION_SWAP);
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- if(netProfit >= basketTakeProfit)
|
|
|
|
|
- {
|
|
|
|
|
- Print("Basket TP hit: Closing all trades. Profit = ", netProfit);
|
|
|
|
|
- closeAllActiveOrders();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-//+------------------------------------------------------------------+
|
|
|
|
|
-//| |
|
|
|
|
|
-//+------------------------------------------------------------------+
|
|
|
|
|
-void closeAllActiveOrders()
|
|
|
|
|
- {
|
|
|
|
|
- for(int i=PositionsTotal()-1; i >=0 ; i--)
|
|
|
|
|
- {
|
|
|
|
|
- ulong ticket = PositionGetTicket(i);
|
|
|
|
|
- if(PositionSelectByTicket(ticket))
|
|
|
|
|
- {
|
|
|
|
|
- if(PositionGetInteger(POSITION_MAGIC) == magicNo &&
|
|
|
|
|
- isGoldPair(PositionGetString(POSITION_SYMBOL)))
|
|
|
|
|
|
|
+ if(PositionSelectByTicket(newTradeStore[i].sellTicket))
|
|
|
{
|
|
{
|
|
|
- if(trade.PositionClose(ticket))
|
|
|
|
|
- {
|
|
|
|
|
- Print("Position closed ", ticket);
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- Print("Cannot close order: ",GetLastError());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ combinationProfit += PositionGetDouble(POSITION_PROFIT) + PositionGetDouble(POSITION_SWAP);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(combinationProfit >= basketTakeProfit)
|
|
|
|
|
+ {
|
|
|
|
|
+ Print("Combination TP hit: Closing trades. Profit = ", combinationProfit);
|
|
|
|
|
+
|
|
|
|
|
+ trade.PositionClose(newTradeStore[i].buyTicket);
|
|
|
|
|
+ Print("Buy Trade Closed: ", newTradeStore[i].buyTicket);
|
|
|
|
|
+ trade.PositionClose(newTradeStore[i].sellTicket);
|
|
|
|
|
+ Print("Sell Trade Closed: ", newTradeStore[i].sellTicket);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
//+------------------------------------------------------------------+
|
|
//+------------------------------------------------------------------+
|
|
|
//| |
|
|
//| |
|