Many thanks for the hard work for the whole team.
I think that it would be a useful option to stop EA after close, for example, 8 (xx) baskets a day.
What do you think? Would this be useful?
Can you add it to Drone?
Best Regards
Wojtek
Code: Select all
void TradeDirectionBySwap(string symbol)
{
//Cancel a trade signal if the swap is negative and the user
//does not want to trade high swap pairs in the wrong direction.
//Also if the user does not want to trade negative swap at all.
GetBasics(symbol);
if (CadPairsPositiveOnly)
{
if (StringSubstrOld(symbol, 0, 3) == "CAD" || StringSubstrOld(symbol, 0, 3) == "cad" || StringSubstrOld(symbol, 3, 3) == "CAD" || StringSubstrOld(symbol, 3, 3) == "cad" )
{
if (BuySignal)
if (longSwap < 0)
BuySignal = false;
if (SellSignal)
if (shortSwap < 0)
SellSignal = false;
}//if (StringSubstrOld()
}//if (CadPairsPositiveOnly)
if (AudPairsPositiveOnly)
{
if (StringSubstrOld(symbol, 0, 3) == "AUD" || StringSubstrOld(symbol, 0, 3) == "aud" || StringSubstrOld(symbol, 3, 3) == "AUD" || StringSubstrOld(symbol, 3, 3) == "aud" )
{
if (BuySignal)
if (longSwap < 0)
BuySignal = false;
if (SellSignal)
if (shortSwap < 0)
SellSignal = false;
}//if (StringSubstrOld()
}//if (AudPairsPositiveOnly)
if (NzdPairsPositiveOnly)
{
if (StringSubstrOld(symbol, 0, 3) == "NZD" || StringSubstrOld(symbol, 0, 3) == "nzd" || StringSubstrOld(symbol, 3, 3) == "NZD" || StringSubstrOld(symbol, 3, 3) == "nzd" )
{
if (BuySignal)
if (longSwap < 0)
BuySignal = false;
if (SellSignal)
if (shortSwap < 0)
SellSignal = false;
}//if (StringSubstrOld()
}//if (AudPairsPositiveOnly)
//OnlyTradePositiveSwap filter
if (OnlyTradePositiveSwap)
{
if (BuySignal)
if (longSwap < 0)
BuySignal = false;
if (SellSignal)
if (shortSwap < 0)
SellSignal = false;
}//if (OnlyTradePositiveSwap)
//MaximumAcceptableNegativeSwap filter
if (BuySignal)
if (longSwap < MaximumAcceptableNegativeSwap)
BuySignal = false;
if (SellSignal)
if (shortSwap < MaximumAcceptableNegativeSwap)
SellSignal = false;
}//void TradeDirectionBySwap()
Code: Select all
extern string sep3="================================================================";
extern string gri="---- Grid inputs ----";
extern string ggi="-- General grid inputs --";
extern bool UseGridTrading=false;
extern GridTypes TypeOfGrid=Stop;
extern int GridSize=5;
extern int DistanceBetweenTradesPips=30;
//Filling the gaps when the market has moved against the original trade
extern bool FillTheGaps=false;
//An expiry time for grid stop orders
extern int GridOrderExpiryMinutes=0;
extern string strg="-- Using ATR to calculate the distance between trades --";
extern bool UseAtrForGrid=false;
extern ENUM_TIMEFRAMES GridAtrTimeFrame=PERIOD_D1;
extern int GridAtrPeriod=20;
extern double GridAtrDivisor=5;
//Pending order deletion following a FLAT or opposite direction signal.
extern string god="-- Pending order deletion inputs --";
extern bool DeletePendingOrdersOnFlatSignal=true;
extern bool DeletePendingOrdersOnOppositeSignal=true;
//Adding to the grid when there is a strong move in our favour and all the stop orders have filled
extern string rgi="--Rolling grid inputs --";
extern bool RollingGrid=false;
extern int MaxRolledTrades=20;
//Close the grid when there are the max trades open and the market reaches the next level
extern bool CloseGridAtMrtPlusOneLevel=false;
extern string gtp="-- Individual grid trades take profit --";
//This tells Desky to set the take profit for each trade at the open price of the next trade in the grid.
extern bool UseNextLevelForTP=false;
////////////////////////////////////////////////////////////////////////////////////////
double DistanceBetweenTrades=0;
////////////////////////////////////////////////////////////////////////////////////////
Code: Select all
//There is no hedge in place and trading is not stopped.
//Is there a gap to fill
if (FillTheGaps)
FillTheGap(symbol);
Code: Select all
void FillTheGap(string symbol)
{
//Add a ned pending order if the market has moved DistanceBetweenTrades * 2
//against the original trade.
double hiLowestPrice = 0;//Store the highest/lowest price of buy/sell trades
double targetPrice = 0;//Hold the 'target'price at which to send the new stop order
double price = 0;//Stop order send price
bool sendTrade = false;
int type = 0;
double take = 0;
double stop = 0;
double sendLots = Lot;
if (UseIncrementalLotSizing)
if (!CloseEnough(HighestLotSoFar, 0))
sendLots = NormalizeLots(symbol, HighestLotSoFar + LotIncrement);
GetBasics(symbol);
//Buys. Does not apply to limit orders
if (BuyOpen || BuyStopOpen)
{
//Find the lowest price in the grid. This can be either a market
//or a stop order.
//Market buy only
if (BuyOpen)
if (!BuyStopOpen)
hiLowestPrice = LowestBuyPrice;
//Buy stops only
if (!BuyOpen)
if (BuyStopOpen)
hiLowestPrice = LowestBuyStopPrice;
//Both
if (BuyOpen)
if (BuyStopOpen)
hiLowestPrice = MathMin(LowestBuyPrice, LowestBuyStopPrice);
//Has the market reached DistanceBetweenTrades * 2
targetPrice = hiLowestPrice;
targetPrice-= (DistanceBetweenTrades / factor) * 2;
if (ask <= targetPrice)//It is, so set up the trade
{
sendTrade = true;
type = OP_BUYSTOP;
price = NormalizeDouble(hiLowestPrice - (DistanceBetweenTrades / factor), digits);
take = CalculateTakeProfit(symbol, OP_BUY, price);
if (UseNextLevelForTP)
take = hiLowestPrice;
stop = CalculateStopLoss(symbol, OP_BUY, price);
}//if (ask <= targetPrice)
}//if (BuyOpen || BuyStopOpen)
//Sells. Does not apply to limit orders
if (SellOpen || SellStopOpen)
{
//Find the lowest price in the grid. This can be either a market
//or a stop order.
//Market buy only
if (SellOpen)
if (!SellStopOpen)
hiLowestPrice = HighestSellPrice;
//Sell stops only
if (!SellOpen)
if (SellStopOpen)
hiLowestPrice = HighestSellStopPrice;
//Both
if (SellOpen)
if (SellStopOpen)
hiLowestPrice = MathMin(HighestSellPrice, HighestSellStopPrice);
//Has the market reached DistanceBetweenTrades * 2
targetPrice = hiLowestPrice;
targetPrice+= (DistanceBetweenTrades / factor) * 2;
if (bid >= targetPrice)//It is, so set up the trade
{
sendTrade = true;
type = OP_SELLSTOP;
price = NormalizeDouble(hiLowestPrice + (DistanceBetweenTrades / factor), digits);
take = CalculateTakeProfit(symbol, OP_SELL, price);
if (UseNextLevelForTP)
take = hiLowestPrice;
stop = CalculateStopLoss(symbol, OP_SELL, price);
}//if (bid >= targetPrice)
}//if (SellOpen || SellStopOpen)
//Send an stop order
if (sendTrade)
{
bool result = SendSingleTrade(symbol, type, TradeComment, sendLots, price, stop, take);
if (!result)
{
int err=GetLastError();
if (err == 132)//Market is closed
return;
if (type == OP_BUYSTOP)
Alert(symbol, " Buy stop failure: Lots ", NormalizeDouble(sendLots, 2),
": Price ", NormalizeDouble(price, 2), ": TP ", take, ": SL ", stop);
else
Alert(symbol, " Sell stop failure: Lots ", NormalizeDouble(sendLots, 2),
": Price ", NormalizeDouble(price, 2), ": TP ", take, ": SL ", stop);
}//if (!result)
}//if (sendTrade)
}//End void FillTheGap(string symbol)
Thanks. I found the bloop within seconds of starting to look. Fix is in post 1.JockTrader » Thu Mar 14, 2019 7:46 pm wrote:Hi Steve i think i might have found an issue with new gap feature, when you go Short, it seams to add orders until your account cant take no more, it does not do this every time, i'm sure its only when the first grid has not been hit, Long seams fine, i have uploaded 2 video of Long and Short - please note i had to shoehorn your code into my dashboard so that i can test it out but i'm sure ive not f8cked any thing up in the new code.
Seems the videos wont upload, is 6MB to big.
The best way to get in touch will be by PM.nanningbob wrote:I’m going to be in New Zealand April 13-22. Auckland 13-16 and the rest of the time traveling the South Island. If any kiwis want to meet be glad to say hi. I also will be in Fiji islands 4/10-13
Don’t know how to send out a message like this??
Bob