- Proper place
- Iamidiot ass: The issue I am seeing is the last order is not setting stop loss porperly."Doesn't work" is meaningless — just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires — meaningless.
Do you really expect an answer with the information you've provided? There are no mind readers here and our crystal balls are cracked. Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you? -
lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/1000.0,1); ⋮ res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,"",MAGICMA,0,Red);
Is your broker's minlot actual 0.1? - Never risk more than a small percentage of your trading funds, certainly less than 2% per trade, 6% total.
Risk depends on your initial stop loss, lot size, and the value of the pair. It does not depend on margin and leverage. No SL means you have infinite risk.
- You place the stop where it needs to be — where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
- AccountBalance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the spread, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
- Do NOT use TickValue by itself - DeltaPerLot
and verify that MODE_TICKVALUE is returning a value in your deposit currency, as promised by the documentation, or
whether it is returning a value in the instrument's base currency.
MODE_TICKVALUE is not reliable on non-fx instruments with many brokers - MQL4 programming forum 2017.10.10
Is there an universal solution for Tick value? - Currency Pairs - General - MQL5 programming forum 2018.02.11
Lot value calculation off by a factor of 100 - MQL5 programming forum 2019.07.19 - You must normalize lots properly and check against min and max.
- You must also check FreeMargin to avoid stop out
Most pairs are worth about $10 per PIP. A $5 risk with a (very small) 5 PIP SL is $5/$10/5 or 0.1 Lots maximum.
-
res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,"",MAGICMA,0,Red); ⋮ fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldStopLoss,OrderTakeProfit(),0,CLR_NONE);
Check your return codes for errors, and report them including GLE/LE, your variable values, and the market. That way we would know that at least you are calling your code.Don't look at GLE/LE unless you have an error. Don't just silence the compiler, it is trying to help you.
What are Function return values ? How do I use them ? - MQL4 programming forum
Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles -
if(Volume[0]>1) return;
For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
New candle - MQL4 programming forum
the first part of code is just a pickup from demo script given by MT4
Second part is the trailing functionality added
You give me few give me few points which will help in trading but I still dont know a lot about Mt4
Probably someone can look at code and understand it easily as it not complicated and comes with me MT4
- If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into yours.
- or pay (Freelance) someone to code it.
Hiring to write script - General - MQL5 programming forum
No free help
sorry I come from python background
will hire someone than
thanks
MetaTrader 5 platform beta build 2055: Integration with Python, C++ like scope and Strategy Tester improvements - Automated Trading Strategies - General - MQL5 programming forum 2019.05.16
New MetaTrader 5 platform build 2085: Integration with Python and Strategy Tester improvements - General - MQL5 programming forum 2019.06.11
New MetaTrader 5 Platform Build 2340: Managing account settings in the Tester and expanded integration with Python - MQL5 programming forum 2020.02.20

- 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 am using following code to set buy/sell order and than set trailing stop/loss order.
It uses SMA for setting order and than set trailing stop loss on stock
The issue I am seeing is the last order is not setting stop loss porperly.
I have just started on MT4. It took me 2 weeks to understand pick the code
Can someone please help me what I am doing wrong