Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 816

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
Dear programmers....I have a problem... Icreated an EA....it opens trades normally (in the tester) .... but closes only buy trades....it only closes sell trades after completing testing... here is a piece of code.... can you help me...
//---------------------------------------------------------------------------------------------------------
void CloseSell()
{
for (int trade = OrdersTotal() - 1; trade >= 0; trade--)
{
if (OrderSelect(trade, SELECT_BY_POS, MODE_TRADES) == true)
{
if (OrderSymbol() == Symbol())
{
if (OrderMagicNumber() == Magic && OrderType() == OP_SELL)
OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, Green);
}
}
}
}
//+------------------------------------------------------------------+
void CloseBuy()
{
for (int trade = OrdersTotal() - 1; trade >= 0; trade--)
{
if (OrderSelect(trade, SELECT_BY_POS, MODE_TRADES) == true)
{
if (OrderSymbol() == Symbol())
{
if (OrderMagicNumber() == Magic && OrderType() == OP_BUY)
OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, Green);
}
}
}
}
//+------------------------------------------------------------------+
void OpenSellOrder()
{
mlots = GetLots();
if (AutoSL) sl = CalcSL(OP_SELL);
else sl = ND(Bid - StopLoss*Point);
tp = ND(Bid - TakeProfit*Point);
ticket = OrderSendReliable(Symbol(), OP_SELL, mlots, Bid, Slippage, 0, 0, comment, Magic, 0, Red);
if(ticket > 0)
OrderModifyReliable(OrderTicket(), OrderOpenPrice(), sl, tp, 0);
}
//+------------------------------------------------------------------+
int OpenBuyOrder()
{
mlots = GetLots();
if (AutoSL) sl = CalcSL(OP_BUY);
else sl = ND(Bid - StopLoss*Point);
tp = ND(Ask + TakeProfit*Point);
ticket = OrderSendReliable(Symbol(), OP_BUY, mlots, Ask, Slippage, 0, 0, comment, Magic, 0, Blue);
if(ticket > 0)
OrderModifyReliable(OrderTicket(), OrderOpenPrice(), sl, tp, 0);
}
//+------------------------------------------------------------------+
void ModifyLoss()
{
for (int trade = OrdersTotal() - 1; trade >= 0; trade--)
{
if (OrderSelect(trade, SELECT_BY_POS, MODE_TRADES) == true)
{
if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic) continue;
if (OrderType() == OP_BUY)
{
sl = ND(OrderOpenPrice() + LossPoints*Point);
if (OrderStopLoss() < sl && (Ask - OrderOpenPrice())/Point >= LossLimit)
{
if (sl != ND(OrderStopLoss()))
OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0);
}
}
else
if (OrderType() == OP_SELL)
{
sl = ND(OrderOpenPrice() - LossPoints*Point);
if (OrderStopLoss() > sl && (OrderOpenPrice()-Bid)/Point >= LossLimit)
{
if (sl != ND(OrderStopLoss()))
OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0);
}
}
}
}
}
//+------------------------------------------------------------------+
double CalcSL(int otype)
{
double sloss = 10000000;
if (otype == OP_BUY)
{
double min;
for (int i=1; i<=SLBars; i++)
{
min = iLow(NULL, 0, i);
if (min < sloss)
sloss = min;
}
sloss = ND(sloss - SLPips*Point);
if ((Ask-sloss)/Point < MinSL)
sloss = ND(Ask - MinSL*Point);
if ((Ask - sloss)/Point > MaxSL)
sloss = ND(Ask - MaxSL*Point);
else
sloss = ND(sloss - SLPips*Point);
return(sloss);
}
else
if (otype == OP_SELL)
{
double max;
sloss = 0;
for (i=1; i<=SLBars; i++)
{
max = iHigh(NULL, 0, i);
if (max > sloss)
sloss = max;
}
if ((sloss - Bid)/Point < MinSL)
sloss = ND(Bid + MinSL*Point);
if ((sloss - Bid)/Point > MaxSL)
sloss = ND(Bid + MaxSL*Point);
else
sloss = ND(sloss + SLPips*Point);
return(sloss);
}
return(0);
}
//+------------------------------------------------------------------+
double GetLots()
{
if (!UseMM) return(FixLot);
double clots;
clots = AccountBalance() / 10000.0 * LotsFor10000;
clots = MathMax(clots, MarketInfo(Symbol(), MODE_MINLOT));
clots = MathMin(clots, MarketInfo(Symbol(), MODE_MAXLOT));
clots = NormalizeDouble(clots, 2);
return (clots);
}
//+------------------------------------------------------------------+
int CountBuy()
{
int count = 0;
for (int trade = OrdersTotal() - 1; trade >= 0; trade--)
{
if (OrderSelect(trade, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_BUY)
count++;
}
}
return (count);
}
//+------------------------------------------------------------------+
int CountSell()
{
int count = 0;
for (int trade = OrdersTotal() - 1; trade >= 0; trade--)
{
if (OrderSelect(trade, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_SELL)
count++;
}
}
return (count);
}
//+------------------------------------------------------------------+
int CountTrades()
{
return(CountBuy() + CountSell());
}
//+------------------------------------------------------------------+
double ND(double value)
{
return (NormalizeDouble(value, Digits));
Pre-select order OrderSelect (Ticket_first_order, SELECT_BY_TICKET);
if(OrderOpenPrice()+10*Point==Ask)
OrderSend(Symbol(),OP_BUY,Lot,Ask,10,Ask-SL*Point,Ask+TP*Point,NULL,Magic,0,Green);
I think it's a working branch...oops, sorry.
Goodnight all!!! Happy New Year!
Decided to save buffer data through a file. No problem to create a file and write to it, but it's hard to read from it.
Here is a trial program. Please help. The problem is, that either there is extra writing to the file, or it cannot be read from the file. I just want to read a list from a file into, e.g., arrays... If I'm too lazy to write please link to similar material, but I've found only tutorial... BUT BETTER A READY VARIANT ON THE SITE))):
THANKS IN ADVANCE ANYWAY!!!))
Alas, it's not so easy with RECORDING in the file!!!(((
And it seemed ... on the contrary.
Reading is sorted out thanks to the tutorial examples, but RECORDING into a file requires more complex code. In short I'm already fooled... I can't figure out how to move the record in sync with the Read from file.
I corrected setting of levels for day bars and for history (initial buffered data).
QUESTION IS THE SAME. PLEASE GIVE ME A HINT, IF THERE IS TOO MUCH WRITING, ON HOW TO WRITE BUFFER DATA TO A FILE.
MODIFIED CODE OF THE PROGRAM
FOUND WHERE TO LOOK FOR ANSWERS TO MY QUESTIONS...ABOUT FILE OPERATIONS))):
SCRIPTS FOR OUTPUTTING INFORMATION FROM A FILE TO A CHART.
HISTORY OF FREE MT4 CODES THERE ARE OPTIONS FOR TRANSFERRING DATA TO A FILE, AS WELL AS THE REVERSE OPERATION.
THANK YOU ALL, EVERYONE CIAO)))):
There is a large file with dates in this form "20141231". To convert the string todatetime formatyou need"YYYY.MM.DD"dots between the year, month and number.
How can this be done?
Hi all, I want the EA to find the highest high or lowest low in 100 bars, advise where to read?
You can read the help, it's all there, with examples.
You can read the help, it's all there, with examples.