There is no take profit. So far, just the correct minimal code:
//+------------------------------------------------------------------+ //| 1.mq5 | //| Copyright © 2020, Vladimir Karputov | //+------------------------------------------------------------------+ #property copyright "Copyright © 2020, Vladimir Karputov" #property version "1.000" //--- #include <Trade\Trade.mqh> #include <Trade\SymbolInfo.mqh> //--- CTrade m_trade; // object of CTrade class CSymbolInfo m_symbol; // object of CSymbolInfo class //--- input parameters input group "Position size management (lot calculation)" input double InpLots = 0.25; // Lots input group "Additional features" input ulong InpDeviation = 10; // Deviation input ulong InpMagic = 201; // Magic number //--- datetime m_prev_bars = 0 ; // "0" -> D'1970.01.01 00:00'; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { if(!m_symbol.Name(Symbol())) // sets symbol name { Print(__FILE__," ",__FUNCTION__,", ERROR: CSymbolInfo.Name"); return(INIT_FAILED); } //--- m_trade.SetExpertMagicNumber(InpMagic); m_trade.SetMarginMode(); m_trade.SetTypeFillingBySymbol(m_symbol.Name()); m_trade.SetDeviationInPoints(InpDeviation); //--- return (INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- we work only at the time of the birth of new bar datetime time_0=iTime(m_symbol.Name(),Period(),0); if(time_0==m_prev_bars) return; m_prev_bars=time_0; //--- check the number of 'BUY' positions for the current symbol and with the specified 'Magic number' ulong tickets_buy[]; int position_exist_buy=PositionExist(m_symbol.Name(),POSITION_TYPE_BUY,InpMagic,tickets_buy); if(position_exist_buy>0) return; //--- check the number of 'SELL' positions for the current symbol and with the specified 'Magic number' ulong tickets_sell[]; int position_exist_sell=PositionExist(m_symbol.Name(),POSITION_TYPE_SELL,InpMagic,tickets_sell); if(position_exist_sell>0) return; //--- m_trade.Buy(InpLots,m_symbol.Name()); //--- } //+------------------------------------------------------------------+
Vladimir Karputov thank you very much for your response and corrections. So is it not possible to input profit target (TP) as the close of the candle only if the trade is in profit. ?Whereas if candle closes in a loss TP, will have to set a fixed TP of say 10 pips?
The bar's closing price cannot be a Take Profit target - since the bar's closing price is the current price (plus or minus the spread). You can use either a fixed Take Profit (N points) or the second option: close the position (close by the market) if the position has reached profit (profit either in Points or in the money of the deposit).
The bar's closing price cannot be a Take Profit target - since the bar's closing price is the current price (plus or minus the spread). You can use either a fixed Take Profit (N points) or the second option: close the position (close by the market) if the position has reached profit (profit either in Points or in the money of the deposit).
The bar's closing price cannot be a Take Profit target - since the bar's closing price is the current price (plus or minus the spread). You can use either a fixed Take Profit (N points) or the second option: close the position (close by the market) if the position has reached profit (profit either in Points or in the money of the deposit).
So may you help me adding tp to the script 110 points
Specify:
pips=0, // Pips (1.00045-1.00055=1 pips) points=1, // Points (1.00045-1.00055=10 points)
?
Specify:
?
That means i will only specify pip/ point conversion like that and write the code under onTick right
Forum on trading, automated trading systems and testing trading strategies
Need EA to have a Take Profit at the current candle close
Vladimir Karputov, 2020.09.03 13:42
Specify:
pips=0, // Pips (1.00045-1.00055=1 pips) points=1, // Points (1.00045-1.00055=10 points)
?
//+------------------------------------------------------------------+ //| 1.mq5 | //| Copyright © 2020, Vladimir Karputov | //+------------------------------------------------------------------+ #property copyright "Copyright © 2020, Vladimir Karputov" #property version "1.000" //--- #include <Trade\Trade.mqh> #include <Trade\SymbolInfo.mqh> //--- CTrade m_trade; // object of CTrade class CSymbolInfo m_symbol; // object of CSymbolInfo class //--- input parameters input group "Position size management (lot calculation)" input double InpLots = 0.25; // Lots input group "Additional features" input ulong InpDeviation = 10; // Deviation input ulong InpMagic = 201; // Magic number //--- datetime m_prev_bars = 0 ; // "0" -> D'1970.01.01 00:00'; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { if(!m_symbol.Name(Symbol())) // sets symbol name { Print(__FILE__," ",__FUNCTION__,", ERROR: CSymbolInfo.Name"); return(INIT_FAILED); } //--- m_trade.SetExpertMagicNumber(InpMagic); m_trade.SetMarginMode(); m_trade.SetTypeFillingBySymbol(m_symbol.Name()); m_trade.SetDeviationInPoints(InpDeviation); //--- return (INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- we work only at the time of the birth of new bar datetime time_0=iTime(m_symbol.Name(),Period(),0); if(time_0==m_prev_bars) return; m_prev_bars=time_0; //--- check the number of 'BUY' positions for the current symbol and with the specified 'Magic number' ulong tickets_buy[]; int position_exist_buy=PositionExist(m_symbol.Name(),POSITION_TYPE_BUY,InpMagic,tickets_buy); if(position_exist_buy>0) return; //--- check the number of 'SELL' positions for the current symbol and with the specified 'Magic number' ulong tickets_sell[]; int position_exist_sell=PositionExist(m_symbol.Name(),POSITION_TYPE_SELL,InpMagic,tickets_sell); if(position_exist_sell>0) return; //--- m_trade.Buy(InpLots,m_symbol.Name()); //--- } pips=0, // Pips (1.00045-1.00055=1 pips) points=1, // Points (1.00045-1.00055=10 points) if(PositionSelectByTicket(PositionExist)){ double posPrice = PositionGetDouble(POSITION_PRICE_OPEN); double posTp = PositionGetDouble(POSITION_TP); if(posTp == 0){ double Tp = posPrice + 0.0010 trade.PositonModify(PositionExist, Tp);I have been researching and trying to figure out how best i can fuse Take profit together with the rest of the script that you coded Vlad. I am lost on this one. There are 2 errors. Also from my research i have noticed i have to clarify how TP has to be done depending on whether broker is a 3 or 4 digit. But for now i need some help with the EA to take profit. You can set any TP target for now, otherwise i will change later when backtesting.
- 2020.03.05
- www.mql5.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello people. I am just starting out to learn coding my EA and its been a week of thick studying how best i can code it.
This EA trades 1M candle open and does not have a Stop loss, and i am well with that.
Can anyone help me with the code or help me complete the script. I would be grateful
1. I need Take profit to be the price at the close of the current candle (only if trade is in profit). if its in loss don't close trade.
2. Help with the right coding for lot/position size. the EA is only using minimum lot size even if i change it on the input tab after attaching EA to chart