coding problem
Thank you very much for your response and your promptness. I will have one last question, the problem with this code is that it opens multiple positions per second, unfortunately I can't find the code that opens a position every 15 candles.
If it's possible, can you help me please
#include <Trade\Trade.mqh> CTrade trade ; bool symbolIsAlreadyTrade(string symbole, uint period){ if(HistorySelect(TimeCurrent() - period, TimeCurrent())){ for(int i = 0; i < HistoryDealsTotal(); i += 1){ ulong ticket = HistoryDealGetTicket(i); if(HistoryDealGetString(ticket, DEAL_SYMBOL) == symbole && HistoryDealGetInteger(ticket, DEAL_ENTRY) == (int)DEAL_ENTRY_IN){ return true; } } } return false; } void OnTick(){ MqlRates mrate[]; ArraySetAsSeries(mrate,true); if(CopyRates(_Symbol,_Period,0,10,mrate)<0) return; { if(mrate[1].close>mrate[9].close) { double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK); double stoploss = ask - 20000 * _Point ; double takeprofit = ask + 50 * _Point ; if(trade.Buy(0.1 , _Symbol, ask, stoploss, takeprofit)) { int code = (int) trade . ResultRetcode(); ulong ticket = trade . ResultOrder(); Print(" Code: " + (string) code); Print(" Ticket: " + (string) ticket); } } } if(mrate[1].close<mrate[9].close) { double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID); double sellStoploss = bid + 20000 * _Point ; double sellTakeprofit = bid - 30 * _Point ; if(trade.Sell(0.1, _Symbol, bid, sellStoploss, sellTakeprofit)) { int code = (int) trade . ResultRetcode(); ulong ticket = trade . ResultOrder(); Print(" Code: " + (string) code); Print(" Ticket: " + (string) ticket); } } }
?
Thank you very much for your response and your promptness. I will have one last question, the problem with this code is that it opens multiple positions per second, unfortunately I can't find the code that opens a position every 15 candles.
If it's possible, can you help me please
?
//+------------------------------------------------------------------+ //| ProjectName | //| Copyright 2020, CompanyName | //| http://www.companyname.net | //+------------------------------------------------------------------+ #include <Trade\Trade.mqh> CTrade trade ; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool symbolIsAlreadyTrade(string symbole, uint period) { if(HistorySelect(TimeCurrent() - period, TimeCurrent())) { for(int i = 0; i < HistoryDealsTotal(); i += 1) { ulong ticket = HistoryDealGetTicket(i); if(HistoryDealGetString(ticket, DEAL_SYMBOL) == symbole && HistoryDealGetInteger(ticket, DEAL_ENTRY) == (int)DEAL_ENTRY_IN) { return true; } } } return false; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnTick() { MqlRates mrate[]; ArraySetAsSeries(mrate,true); if(CopyRates(_Symbol,_Period,0,10,mrate)<0) return; datetime open_time; if(PositionsTotal()>0) if(PositionSelectByTicket(PositionGetTicket(PositionsTotal()-1))) { open_time=(datetime)PositionGetInteger(POSITION_TIME); if(TimeCurrent()<open_time+(15*tf_turn(_Period))) return; } if(mrate[1].close>mrate[9].close) { double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK); double stoploss = ask - 20000 * _Point ; double takeprofit = ask + 50 * _Point ; if(trade.Buy(0.1, _Symbol, ask, stoploss, takeprofit)) { int code = (int) trade . ResultRetcode(); ulong ticket = trade . ResultOrder(); Print(" Code: " + (string) code); Print(" Ticket: " + (string) ticket); } } if(mrate[1].close<mrate[9].close) { double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID); double sellStoploss = bid + 20000 * _Point ; double sellTakeprofit = bid - 30 * _Point ; if(trade.Sell(0.1, _Symbol, bid, sellStoploss, sellTakeprofit)) { int code = (int) trade . ResultRetcode(); ulong ticket = trade . ResultOrder(); Print(" Code: " + (string) code); Print(" Ticket: " + (string) ticket); } } } //+------------------------------------------------------------------+ int tf_turn(int tf) { switch(tf) { case 0: return(PERIOD_CURRENT*60); case 1: return(1*60); case 5: return(5*60); case 15: return(15*60); case 30: return(30*60); case 60: return(60*60); case 240: return(240*60); case 1440: return(1440*60); case 10080: return(10080*60); case 43200: return(43200*60); case 2: return(2*60); case 3: return(3*60); case 4: return(4*60); case 6: return(6*60); case 10: return(10*60); case 12: return(12*60); case 16385: return(60*60); case 16386: return(120*60); case 16387: return(180*60); case 16388: return(240*60); case 16390: return(360*60); case 16392: return(480*60); case 16396: return(720*60); case 16408: return(1440*60); case 32769: return(10080*60); case 49153: return(43200*60); default: return(PERIOD_CURRENT*60); } } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+
here you go sir
Code simplified | int tf_turn(int tf){ return PeriodSeconds(tf); } |
ici vous allez monsieur
Thank you very much ! This is exactly what I wanted, the code was really complicated 😮
Code simplifié |
Thank you very much !
Code simplified |
thank you that was amazing but actually it needs to be like this :
int tf_turn(ENUM_TIMEFRAMES tf){ return PeriodSeconds(tf); }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Thank you.