int SetOrder(int type) { double price = 0; color col = clrNONE; if (type == OP_BUY) { price = Ask; col = clrBlue; } if (type == OP_SELL) { price = Bid; col = clrRed; } double lot = Invest; if (Martingale) { int lossCount = GetLossCount(); if (lossCount > MaxMartingaleLevels) lossCount = MaxMartingaleLevels; lot = NormalizeDouble(MathPow(MartingaleMultiplier, lossCount)*Invest, InvestDecimalPoints); if (NormalizeDouble(lot, 2)>NormalizeDouble(MaxInvestment, InvestDecimalPoints)) lot = MaxInvestment; if (lossCount > 0) GlobalVariableSet(gbl+"Martingale", 1); else GlobalVariableSet(gbl+"Martingale", 0); } else GlobalVariableSet(gbl+"Martingale", 0); string com = "BO exp: "+IntegerToString(expiry); int ticket = -1; if (NormalizeDouble(lot, 2) > NormalizeDouble(SplitInvestIfMoreThan, 2)) { int count = 0, retries = 0; while (count < 2 && retries < 10) { if (IsTradeContextBusy()) { Sleep(200); continue; } RefreshRates(); if (type == OP_BUY) { price = Ask; col = clrBlue; } if (type == OP_SELL) { price = Bid; col = clrRed; } if (count == 0) ticket = OrderSend(Symbol(), type, SplitInvestIfMoreThan, price, 0, 0, 0, com, MagicNumber, 0, col); else ticket = OrderSend(Symbol(), type, MathMin(lot-SplitInvestIfMoreThan, SplitInvestIfMoreThan), price, 0, 0, 0, com, MagicNumber, 0, col); if (count == 0 && ticket != -1) { GlobalVariableSet(gbl+"LastEntry1", ticket); count = 1; } else if (count == 1 && ticket != -1) { GlobalVariableSet(gbl+"LastEntry2", ticket); count = 2; } retries ++; } } else { ticket = OrderSend(Symbol(), type, lot, price, 0, 0, 0, com, MagicNumber, 0, col); if (ticket != -1) GlobalVariableSet(gbl+"LastEntry1", ticket); } int err = GetLastError(); if (ticket == -1 && err > 0) Print("err=", IntegerToString(err), ", type=" + IntegerToString(type), ", price=", DoubleToStr(price, _Digits), ", lot=", DoubleToStr(lot, InvestDecimalPoints), ", comment=", com, ", ", ErrorDescription(err)); else { GlobalVariableSet(gbl+"LastEntry", ticket); string file = "TmaBBBinary_" + Symbol() + "_" + IntegerToString(Period()) + "_" + IntegerToString(TimeCurrent()) + ".png"; if (MakeScreenshot) WindowScreenShot(file, 800, 600); } return (ticket); } //+------------------------------------------------------------------+ int GetLossCount() { int count = 0; for (int i = OrdersHistoryTotal() - 1; i >= 0; i--) if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { if (StringFind(OrderComment(), "/LOSS/")!=-1) count++; else break; } return (count); } //+------------------------------------------------------------------+ int DoesSignalCatched(int type, datetime from) { for (int i = OrdersTotal() - 1; i >= 0; i--) if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == type) return (OrderTicket()); for (int i = OrdersHistoryTotal() - 1; i >= 0; i--) if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == type && OrderOpenTime() >= from) return (OrderTicket()); return (-1); }
Click the [SRC] button when posting code.
I don't understand the question; its brevity is obscure to say the least.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
}
Thanks!
Best Regards!