miron_like: I looked at your example. Frankly speaking, while there is not enough knowledge to fully understand it and then write it as it should. Can you tell me how to implement this task based on this code?To get started, just take an example and remove all the extra stuff - what you don't need.
miron_like:
I looked at your example. Frankly speaking, while there is not enough knowledge to fully understand it and then write it as it should.
Can you tell me how to implement this task based on this code?
To get started, just take an example and remove all the extra stuff – what you don’t need.
miron_like: And so the code in its full form looks right?...No, it's not right. You caught a transaction with the TRADE_TRANSACTION_DEAL_ADD type - this is adding a transaction to the history, please note that there is no mention of an order here. Forget about the orders. There are only positions. NRead more
miron_like:
And so the code in its full form looks right?
…
No, it’s not right. You caught a transaction with the TRADE_TRANSACTION_DEAL_ADD type – this is adding a transaction to the history, please note that there is no mention of an order here. Forget about the orders. There are only positions.
Next, see that the transaction must have the DEAL_REASON_SL property – again, the transaction, orders do not even smell.
Now it remains to open a position:
Forum on trading, automated trading systems and testing of trading strategies
Opening an order in the opposite direction
Vladimir Karputov, 2017.07.27 14:05
And for an example of opening a position (namely, a position, and not placing a pending order), see the same code that I gave (the OpenBuy and OpenSell functions).
To begin with, just write the code in which it opens a position after you find the trade that appeared as a result of the Stop loss trigger – then, when I see your code, I will tell you further.
miron_like: long deal_reason =-1; deal_reason=HistoryDealGetInteger(trans.deal,DEAL_REASON); if(deal_reason==DEAL_REASON_SL) and here is what I need...Am I right?"Yes. That's right.
miron_like:
long deal_reason =-1;
deal_reason=HistoryDealGetInteger(trans.deal,DEAL_REASON); if(deal_reason==DEAL_REASON_SL)
and here is what I need...
miron_like: Please tell me, when closing an order for StopLoss, I need to open an order in the opposite direction with the same parameters, but once. I.e. if the first order was closed for SL, then for subsequent closed orders for SL, do not open an order in the opposite direction.Example of how toRead more
miron_like: Please tell me, when closing an order for StopLoss, I need to open an order in the opposite direction with the same parameters, but once. I.e. if the first order was closed for SL, then for subsequent closed orders for SL, do not open an order in the opposite direction.
Example of how to catch a 100% guaranteed trade as a result of triggering the Stop Loss code Stop Loss Take Profit – in OnTradeTransaction, catch a trade that is closed as a result of the Stop loss trigger (the DEAL_REASON_SL property of the trade).
After you have caught a closed trade as a result of the Stop Loss trigger, you can already do what you need.
Don't understand how you are when using the method NormalizePrice of the CSymbolInfo class, do you get prices that do not end in "0"on this symbol in SL and TP? You have both "1" and "9" there.Second: put these prints://+------------------------------------------------------------------+ //| Open BRead more
Don’t understand how you are when using the method NormalizePrice of the CSymbolInfo class, do you get prices that do not end in “0”on this symbol in SL and TP? You have both “1” and “9” there.
Second: put these prints:
//+------------------------------------------------------------------+ //| Open Buy position | //+------------------------------------------------------------------+ void OpenBuy(double lot,double sl,double tp)
{
sl=m_symbol.NormalizePrice(sl);
tp=m_symbol.NormalizePrice(tp);
double volume=LotCheck(lot); if(volume==0.0) return; //--- check volume before OrderSend to avoid "not enough money" error (CTrade) double check_volume_lot=m_trade.CheckVolume(m_symbol.Name(),volume,m_symbol.Ask(),ORDER_TYPE_BUY);
Fresto: I created the object. And with each new call to the onTick() function, I call the Refresh method. Just the most interesting thing is that in the position opening code everything is assigned in real time and why then the first orders pass, and the others do not.. First, it writes that invalidRead more
Fresto:
I created the object. And with each new call to the onTick() function, I call the Refresh method. Just the most interesting thing is that in the position opening code everything is assigned in real time and why then the first orders pass, and the others do not.. First, it writes that invalid_price, then it also intersects with invalid_stop. Although I have been optimizing the exact same position opening code on other Expert Advisors for a long time, and everything is fine there.
P. s. is there any way to find out why this particular error crashes? Not just-invalid_price, but more specifically, what is the problem?
I think this is the imposition of a ban on trading on gluing. No more thoughts.
You need to write an Expert Advisor on the indicator
barabashkakvn
You will be helped in the Freelance service.
You will be helped in the Freelance service.
See lessOpening an order in the opposite direction
barabashkakvn
miron_like: Please tell me, what can I do based on my code, so as not to rewrite it?No, you can't.
No, you can’t.
See lessOpening an order in the opposite direction
barabashkakvn
miron_like: I looked at your example. Frankly speaking, while there is not enough knowledge to fully understand it and then write it as it should. Can you tell me how to implement this task based on this code?To get started, just take an example and remove all the extra stuff - what you don't need.
To get started, just take an example and remove all the extra stuff – what you don’t need.
See lessOpening an order in the opposite direction
barabashkakvn
miron_like: And so the code in its full form looks right?...No, it's not right. You caught a transaction with the TRADE_TRANSACTION_DEAL_ADD type - this is adding a transaction to the history, please note that there is no mention of an order here. Forget about the orders. There are only positions. NRead more
No, it’s not right. You caught a transaction with the TRADE_TRANSACTION_DEAL_ADD type – this is adding a transaction to the history, please note that there is no mention of an order here. Forget about the orders. There are only positions.
Next, see that the transaction must have the DEAL_REASON_SL property – again, the transaction, orders do not even smell.
Now it remains to open a position:
Forum on trading, automated trading systems and testing of trading strategies
Opening an order in the opposite direction
Vladimir Karputov, 2017.07.27 14:05
And for an example of opening a position (namely, a position, and not placing a pending order), see the same code that I gave (the OpenBuy and OpenSell functions).
To begin with, just write the code in which it opens a position after you find the trade that appeared as a result of the Stop loss trigger – then, when I see your code, I will tell you further.
See lessOpening an order in the opposite direction
barabashkakvn
miron_like: long deal_reason =-1; deal_reason=HistoryDealGetInteger(trans.deal,DEAL_REASON); if(deal_reason==DEAL_REASON_SL) and here is what I need...Am I right?"Yes. That's right.
Yes. That’s right.
See lessOpening an order in the opposite direction
barabashkakvn
miron_like: Please tell me, when closing an order for StopLoss, I need to open an order in the opposite direction with the same parameters, but once. I.e. if the first order was closed for SL, then for subsequent closed orders for SL, do not open an order in the opposite direction.Example of how toRead more
Example of how to catch a 100% guaranteed trade as a result of triggering the Stop Loss code Stop Loss Take Profit – in OnTradeTransaction, catch a trade that is closed as a result of the Stop loss trigger (the DEAL_REASON_SL property of the trade).
After you have caught a closed trade as a result of the Stop Loss trigger, you can already do what you need.
See lessThe invalid price error is thrown
barabashkakvn
Don't understand how you are when using the method NormalizePrice of the CSymbolInfo class, do you get prices that do not end in "0"on this symbol in SL and TP? You have both "1" and "9" there.Second: put these prints://+------------------------------------------------------------------+ //| Open BRead more
Don’t understand how you are when using the method NormalizePrice of the CSymbolInfo class, do you get prices that do not end in “0”on this symbol in SL and TP? You have both “1” and “9” there.
Second: put these prints:
//+------------------------------------------------------------------+
//| Open Buy position |
//+------------------------------------------------------------------+
void OpenBuy(double lot,double sl,double tp)
{
sl=m_symbol.NormalizePrice(sl);
tp=m_symbol.NormalizePrice(tp);
double volume=LotCheck(lot);
if(volume==0.0)
return;
//--- check volume before OrderSend to avoid "not enough money" error (CTrade)
double check_volume_lot=m_trade.CheckVolume(m_symbol.Name(),volume,m_symbol.Ask(),ORDER_TYPE_BUY);
if(check_volume_lot!=0.0)
if(check_volume_lot>=volume)
{
if(m_trade.Buy(volume,NULL,m_symbol.Ask(),sl,tp))
{
if(m_trade.ResultDeal()==0)
{
Print("Buy -> false. Result Retcode: ",m_trade.ResultRetcode(),
", description of result: ",m_trade.ResultRetcodeDescription(),
", Bid: ",DoubleToString(m_symbol.Bid(),m_symbol.Digits()),
", Ask: ",DoubleToString(m_symbol.Ask(),m_symbol.Digits()),
", Last: ",DoubleToString(m_symbol.Last(),m_symbol.Digits()));
}
else
{
Print("Buy -> true. Result Retcode: ",m_trade.ResultRetcode(),
", description of result: ",m_trade.ResultRetcodeDescription(),
", Bid: ",DoubleToString(m_symbol.Bid(),m_symbol.Digits()),
", Ask: ",DoubleToString(m_symbol.Ask(),m_symbol.Digits()),
", Last: ",DoubleToString(m_symbol.Last(),m_symbol.Digits()));
}
}
else
{
Print("Buy -> false. Result Retcode: ",m_trade.ResultRetcode(),
", description of result: ",m_trade.ResultRetcodeDescription(),
", Bid: ",DoubleToString(m_symbol.Bid(),m_symbol.Digits()),
", Ask: ",DoubleToString(m_symbol.Ask(),m_symbol.Digits()),
", Last: ",DoubleToString(m_symbol.Last(),m_symbol.Digits()));
}
}
//---
}
//+------------------------------------------------------------------+
//| Open Sell position |
//+------------------------------------------------------------------+
void OpenSell(double lot,double sl,double tp)
{
sl=m_symbol.NormalizePrice(sl);
tp=m_symbol.NormalizePrice(tp);
double volume=LotCheck(lot);
if(volume==0.0)
return;
//--- check volume before OrderSend to avoid "not enough money" error (CTrade)
double check_volume_lot=m_trade.CheckVolume(m_symbol.Name(),volume,m_symbol.Bid(),ORDER_TYPE_SELL);
if(check_volume_lot!=0.0)
if(check_volume_lot>=volume)
{
if(m_trade.Sell(volume,NULL,m_symbol.Bid(),sl,tp))
{
if(m_trade.ResultDeal()==0)
{
Print("Sell -> false. Result Retcode: ",m_trade.ResultRetcode(),
", description of result: ",m_trade.ResultRetcodeDescription(),
", Bid: ",DoubleToString(m_symbol.Bid(),m_symbol.Digits()),
", Ask: ",DoubleToString(m_symbol.Ask(),m_symbol.Digits()),
", Last: ",DoubleToString(m_symbol.Last(),m_symbol.Digits()));
}
else
{
Print("Sell -> true. Result Retcode: ",m_trade.ResultRetcode(),
", description of result: ",m_trade.ResultRetcodeDescription(),
", Bid: ",DoubleToString(m_symbol.Bid(),m_symbol.Digits()),
", Ask: ",DoubleToString(m_symbol.Ask(),m_symbol.Digits()),
", Last: ",DoubleToString(m_symbol.Last(),m_symbol.Digits()));
}
}
else
{
Print("Sell -> false. Result Retcode: ",m_trade.ResultRetcode(),
", description of result: ",m_trade.ResultRetcodeDescription(),
", Bid: ",DoubleToString(m_symbol.Bid(),m_symbol.Digits()),
", Ask: ",DoubleToString(m_symbol.Ask(),m_symbol.Digits()),
", Last: ",DoubleToString(m_symbol.Last(),m_symbol.Digits()));
}
}
//---
}
Errors occur when: the opening price of the position does not match the Last price and the Last is equal to the stop (SL or TP).
See lessThe invalid price error is thrown
barabashkakvn
Fresto: 10. The prices of the RTS instrument are multiples of 10.No, you check by gluing, not by RTS.
No, you check by gluing, not by RTS.
See lessThe invalid price error is thrown
barabashkakvn
Fresto: I created the object. And with each new call to the onTick() function, I call the Refresh method. Just the most interesting thing is that in the position opening code everything is assigned in real time and why then the first orders pass, and the others do not.. First, it writes that invalidRead more
I think this is the imposition of a ban on trading on gluing. No more thoughts.
See lessThe invalid price error is thrown
barabashkakvn
So this is gluing - is it allowed to trade on it?
So this is gluing – is it allowed to trade on it?
See less