About closing positions :
void CloseAllPositions() { for(int i=PositionsTotal()-1; i>=0; i--) { ulong ticket=PositionGetTicket(i); trade.PositionClose(ticket); } }
No idea what you are trying to do beside that.
//+------------------------------------------------------------------+ //| FirstTrade_MQL5_ABG.mq5 | //| Copyright © 2018, Anwar Goulouh | //| compstuffcrazy@gmail.com | //+------------------------------------------------------------------+ #property copyright "Copyright © 2018, Anwar Goulouh" #property link "compstuffcrazy@gmail.com" #property version "1.000" //--- #include <Trade\Trade.mqh> void OnTick() { double AccBal = AccountInfoDouble(ACCOUNT_BALANCE); double AccProf = AccountInfoDouble(ACCOUNT_PROFIT); double AccEq = AccountInfoDouble(ACCOUNT_EQUITY); Comment("Account Balance: ", AccBal, "/n", "Account Profit: " ,AccProf, "/n", "Account Equity: ", AccEq, "/n"); MqlTradeRequest MyReq; MqlTradeResult MyRes; ZeroMemory (MyReq); MyReq.action = TRADE_ACTION_DEAL; MyReq.type = ORDER_TYPE_BUY; MyReq.symbol = _Symbol; MyReq.volume = 0.01; MyReq.type_filling = ORDER_FILLING_FOK; MyReq.price = SymbolInfoDouble(_Symbol, SYMBOL_ASK); MyReq.tp = 0; MyReq.deviation = 50; Comment("First Auto Trade"); if(!PositionSelect(_Symbol)) // If Open position (!) Does not exist. { OrderSend(MyReq,MyRes); } if(AccEq >= AccBal+2) { CloseAllOrders(); } } CTrade trade; void CloseAllOrders() { for(int i=PositionsTotal()-1; i>=0; i--) { ulong ticket=PositionGetTicket(i); trade.PositionClose(ticket); } } // //void CloseAllOrders() //{ // // int i=PositionsTotal()-1; // while (i>=0) // { // if(trade.PositionClose(PositionGetSymbol())) i--; // } // //}
HI,
Having similar issues attempting to follow tutorial...
https://www.youtube.com/watch?v=JClTPth8aXA&list=PLV8YK-9p3TcM1gb106qDgzvwPExB5Fxra&index=8
Compiled Fine except for close all orders function..
Followed your suggestion @Alain Verleyen
A bit better. Now only get warning.
return value of 'OrderSend' should be checked | FirstTrade_MQL5_ABG.mq5 37 7
Any help would be appreciated honestly I am finding getting into MQL5 horrendous especially debugging and the tutorials? Do I have to pay for correct/professional training manuals or something?
Thanks Mate Peace From NZ
HI,
Having similar issues attempting to follow tutorial...
https://www.youtube.com/watch?v=JClTPth8aXA&list=PLV8YK-9p3TcM1gb106qDgzvwPExB5Fxra&index=8
Compiled Fine except for close all orders function..
Followed your suggestion @Alain Verleyen
A bit better. Now only get warning.
return value of 'OrderSend' should be checked | FirstTrade_MQL5_ABG.mq5 37 7
Any help would be appreciated honestly I am finding getting into MQL5 horrendous especially debugging and the tutorials? Do I have to pay for correct/professional training manuals or something?
Thanks Mate Peace From NZ
it should return true, and returned code from server should be 10009, which means it's done successfully.
you can read about all these functions in documentation : Trade Functions section.
Although the tutorial does not ever make a profit in the strategy tester? and because the tutorial was not correctly explained, im not sure where, how and why it is supposed to be making money? Any links to better tuts?
\\\thnx
that warning simply means you should check whether the SendOrder() has done the supposed operations successfully or not.
it should return true, and returned code from server should be 10009, which means it's done successfully.
you can read about all these functions in documentation : Trade Functions section.
thnx reading now
Like this for the checking just me trying...
This is edited with two errors
'oChkRes' - undeclared identifier | FirstTrade_MQL5_ABG.mq5 44 8
'retcode' - struct or class type expected | FirstTrade_MQL5_ABG.mq5 44 16
//---Added This MqlTradeCheckResult MyChkRes; //---Below These MqlTradeRequest MyReq; //--- MqlTradeResult MyRes; if(!PositionSelect(_Symbol)) { bool oChkRes = (OrderCheck(MyReq,MyChkRes)); } if (oChkRes.retcode != 10009) { if(!PositionSelect(_Symbol)) // If Open position (!) Does not exist. { OrderSend(MyReq,MyRes); } }
AND again read the docs to learn what is the reason/meaning of each error code and warnings during compilation.
you can fix the issues , or if not, ask someone to do so (pay them)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I want my EA to place a pending order at the prices (Hoch- und Tiefpreis as prices) and to replace the pending order, when on of them was filled and closed by the tp or sl. Unfortunately my EA wont to this. Furthermore I want to close all open postions at the end of the day, but it wont close the position, causing trades to go on for several days. Thank you for your help :D