if(Sell==true && Count.Buy()==0){
int ticket = Trade.OpenBuyOrder(_Symbol,lotSize);
int gSellTicket = OrderSend(_Symbol,OP_SELL,0.1,Bid,Slippage,(Bid+(900*Point)),0,"Sell order",NewMagicNumber,0,clrRed);
lastBuy=NormalizeDouble(FindLastBuyPrice(),Digits);
}
Above code is copied from an EA, i attach it to chart, it execute the first buy order but it did not execute the second sell order. i want to know how to solve this problem. Note: The problem is not hedge is disallowed in the account (Demo or Real) or platform (FXTM) type, i already found out. Thank you in advance for anybody's answer.
Related
So I have this EA that should close 2 trades together under certain conditions. Sometimes it closes only 1/2, sometimes it closes both smoothly. I cannot really pinpoint the times it closes only one and detect a pattern so I can spot the logical error.
P.S.: Obviously the trades are from different pairs running from an EA within 1 chart/pair.
The error message is this:
invalid ticket for OrderClose function
But the trade clearly exists, and i make sure I have it within the int as every time I restart the EA, if trade is already open (detected by comment) it has a message like that:
"Buy trade: [ticket number], recognised."
So I know for fact that it is recognised and within the proper int to be used. Any ideas about the error's source?
OrderClose(TicketA,LotSize,iClose(NULL,0,0),Slippage,clrGray);
OrderClose(TicketB,LotSize,iClose(SymbolB,0,0),Slippage,clrGray);
Will this fix this? I mean... it will be errored out 2/4 close orders... but I don't really care about how beautiful it looks.
OrderClose(TicketA,LotSize,Ask,Slippage,clrGray);
OrderClose(TicketB,LotSize,Bid,Slippage,clrGray);
OrderClose(TicketA,LotSize,Ask,Slippage,clrGray);
OrderClose(TicketB,LotSize,Ask,Slippage,clrGray);
Make sure that you didn't override TicketA or TicketB variable somewhere.
You can use OrderLots() function instead of using LotSize, especially when this value is changing during EA process. Additionally, by checking the OrderType(), you will avoid a mistake at the closing price.
Example:
if(yourCloseCondition){
if(OrderSelect(ticket, SELECT_BY_TICKET)){
if(OrderType() == OP_BUY){
if(OrderClose(ticket, OrderLots(), Bid, 0)){
//Print("success");
}
}
if(OrderType() == OP_SELL){
if(OrderClose(ticket, OrderLots(), Ask, 0)){
//Print("success");
}
}
}
}
Also check docs: OrderClose() and OrderType().
Update:
For different pairs running within 1 chart use close price from MarketInfo
Example:
MarketInfo("EURUSD",MODE_BID);
Check MarketInfo().
As you can see on this photo: https://gyazo.com/9ca355a460c5602ec073bcbae701dede i clicked on every block. My problem is that every block doens't have the same Value. I want every block when i click at it to go down 1/10 everytime i click and still give me 1 in my backpack pr. click. Right now i can see that the value of the blocks if not the same.
Here is the script for the blocks: https://gyazo.com/b627ae8559b9035f0fdfe88297b13364 (Think the problem is here)
As you can see on this photo the value is 0,8. And the other one downstairs is 0,1 and so on https://gyazo.com/ac5359b7f6a7e123ad31507f4384323d
The damage value is 0.2 as u see here: https://gyazo.com/b9de1795c27eb151caf8db2d79e9f58a
Here is the script for the shovel:
https://gyazo.com/14b5e675be5644056bda8b24f828ec6a
I would appreciate if u could help me to fix this problem. Tell me if u need more information about this to fix this problem. Hope u understand my problem.
In this line (26) u r generating a random damage value
dmg.value = math.random(1, 10)/10
Did u try to set it on
dmg.value = 1/10
?
I'm trying to figure out if there is a correct way to set the Stop Loss (SL) and Take Profit (TP) levels, when sending an order in an Expert Advisor, in MQL4 (Metatrader4). The functional template is:
OrderSend( symbol, cmd, volume, price, slippage, stoploss, takeprofit, comment, magic, expiration, arrow_color);
So naturally I've tried to do the following:
double dSL = Point*MM_SL;
double dTP = Point*MM_TP;
if (buy) { cmd = OP_BUY; price = Ask; SL = ND(Bid - dSL); TP = ND(Ask + dTP); }
if (sell) { cmd = OP_SELL; price = Bid; SL = ND(Ask + dSL); TP = ND(Bid - dTP); }
ticket = OrderSend(SYM, cmd, LOTS, price, SLIP, SL, TP, comment, magic, 0, Blue);
However, there are as many variations as there are scripts and EA's. So far I have come across these.
In the MQL4 Reference in the MetaEditor, the documentation say to use:
OrderSend(Symbol(),OP_BUY,Lots,Ask,3,
NormalizeDouble(Bid - StopLoss*Point,Digits),
NormalizeDouble(Ask + TakeProfit*Point,Digits),
"My order #2",3,D'2005.10.10 12:30',Red);
While in the "same" documentation online, they use:
double stoploss = NormalizeDouble(Bid - minstoplevel*Point,Digits);
double takeprofit = NormalizeDouble(Bid + minstoplevel*Point,Digits);
int ticket=OrderSend(Symbol(),OP_BUY,1,price,3,stoploss,takeprofit,"My order",16384,0,clrGreen);
And so it goes on with various flavors, here, here and here...
Assuming we are interested in a OP_BUY and have the signs correct, we have the options for basing our SL and TP values on:
bid, bid
bid, ask
ask, ask
ask, bid
So what is the correct way to set the SL and TP for a BUY?
(What are the advantages or disadvantages of using the various variations?)
EDIT: 2018-06-12
Apart a few details, the answer is actually quite simple, although not obvious. Perhaps because MT4 only show Bid prices on the chart (by default) and not both Ask and Bid.
So because: Ask > Bid and Ask - Bid = Slippage, it doesn't matter which we choose as long as we know about the slippage. Then depending on what price you are following on the chart, you may wish to decide on using one over the other, adding or subtracting the Slippage accordingly.
So when you use the measure tool to get the Pip difference of currently shown prices, vs your "exact" SL/TP settings, you need to keep this in mind.
So to avoid having to put the Slippage in my code above, I used the following for OP_BUY: TP = ND(Bid + dTP); (and the opposite for OP_SELL.)
If you buy, you OP_BUY at Ask and close (SL, TP) at Bid.
If you sell, OP_SELL operation is made at Bid price, and closes at Ask.
Both SL and TP should stay at least within STOP_LEVEL * Point() distance from the current price to close ( Bid for buy, Ask for sell).
It is possible that STOP_LEVEL is zero - in such cases ( while MT4 accepts the order ) the Broker may reject it, based on its own algorithms ( Terms and Conditions may call it a "floating Stoplevel" rule or some similar Marketing-wise "re-dressed" term ).
It is adviced to send an OrderSend() request with zero values of SL and TP and modify it after you see that the order was sent successfully. Sometimes it is not required, sometimes that is even mandatory.
There is no difference between the two links you gave us: you may compute SL and TP and then pass them into the function or compute them based on OrderOpenPrice() +/- distance * Point().
So what is the correct way to set the SL and TP for a BUY ?
There is no such thing as "The Correct Way", there are rules to meet
Level 0: Syntax is to meet the call-signature ( the easiest one )
Level 1: all at Market XTO-s have to meet the right level of the current Price +/- slippage, make sure to repeat a RefreshRates()-test as close to the PriceDOMAIN-levels settings, otherwise they get rejected from the Broker side ( blocking one's trading engine at a non-deterministic add-on RTT-latency ) + GetLastError() == 129 | ERR_INVALID_PRICE
Level 2: yet another rules get set from Broker-side, in theire respective Service / Product definition in [ Trading Terms and Conditions ]. If one's OrderSend()-request fails to meet any one of these, again, the XTO will get rejected, having same adverse blocking effects, as noted in Level 1.
Some Brokers do not allow some XTO situations due to their T&C, so re-read such conditions with a due care. Any single of theirs rule, if violated, will lead to your XTO-instruction to get legally rejected, with all adverse effects, as noted above. Check all rules, as you will not like to see any of the following error-states + any of others, restricted by your Broker's T&C :
ERR_LONG_POSITIONS_ONLY_ALLOWED Buy orders only allowed
ERR_TRADE_TOO_MANY_ORDERS The amount of open and pending orders has reached the limit set by the broker
ERR_TRADE_HEDGE_PROHIBITED An attempt to open an order opposite to the existing one when hedging is disabled
ERR_TRADE_PROHIBITED_BY_FIFO An attempt to close an order contravening the FIFO rule
ERR_INVALID_STOPS Invalid stops
ERR_INVALID_TRADE_VOLUME Invalid trade volume
...
..
.
#ASSUME NOTHING ; Is the best & safest design-side (self)-directive
I am going through the new Apple Swift language.
Why should I use variable name at the end ?
var largest = 0
for (kind, numbers) in interestingNumbers {
for number in numbers {
if number > largest {
largest = number
}
}
}
largest
Are you asking why the last line is largest? Paste the code into a playground and you'll see it show the value of largest on the right at that line. It's just so you can see what the value is after the loop.
If you are following the learning book (I see the code sample taken from the iBook) without Xcode; you are missing Xcode's Playground.
Download Xcode 6 Beta, open playground, paste above code, see the magic ;-)
Playground is a tool to see what happens in your code as you type.
Also to understand the philosophy behind Xcode Playground take a look at this video:
Bret Victor - Inventing on Principle http://vimeo.com/36579366
I have gone through msdn article, read whitepaper on number sequences and made number sequences a lot many times. But in this scenario I need some help.
Scenario is; I want to get next sequence number through x++ code using just number sequence code and no reference etc.
I have tried following (and many others but this is nearest solution) ;
static void myTestJob(Args _args)
{
NumberSeq num;
num = NumberSeq::newGetNumFromCode('SAO-Y');
info(num.num()) ;
}
It generates number sequence against some number sequence codes, but for other it throws error that;
"Number sequence does not exist."
I have tried many other options mentioned on many other blogs and tried to explore AX as well, but now need some assistance.
P.S. I'm not creating number sequence using x++ code but from front end (organization administration).
I am able to suppress the exception by using following;
num = NumberSeq::newGetNumFromCode(<<someNumberSequenceCode>>, NumberSeqScopeFactory::createDefaultScope(), true, true);
As, fourth optional parameter of NumberSeq::newGetNumFromCode(,,,true); says not to throw exception on missing reference.
boolean _dontThrowOnMissingRefSetUp = false,
As I said earlier, I have created number sequence from organization administration without writing any code (EDT, class, parameters table etc. stuff) so no reference was generated and I think I was getting exception due to this.
Please have a look at your number sequence that you have set up. I recon it has something to do with the numbersequence scope.
Make sure the scope of the number sequence is valid within the company you are calling this.
It's work, but not raice result: Voucher not generated.
Working way:
num = NumberSeq::newGetNumFromCode(<<someNumberSequenceCode>>,
NumberSeqScopeFactory::createDefaultScope(), **false**, true);
When my Number Sequence - Scope is setup as Shared I can use this code:
numSequence = NumberSeq::newGetNumFromCode(<<someNumberSequenceCode>>, NumberSeqScopeFactory::createDataAreaScope(curext()), true, true);
When my Number Sequence - Scope is setup as Company I can use this code:
numSequence = NumberSeq::newGetNumFromCode(<<someNumberSequenceCode>>);