double PSAR = iSAR(NULL,0,PSAR_Step,PSAR_Max,0); double PSAR_2 = iSAR(NULL,0,PSAR_Step2,PSAR_Max2,0); // Filter Function double PSAR_filter_1 = iSAR(NULL,0,PSAR_Step,PSAR_Max,1); double PSAR_filter_2 = iSAR(NULL,0,PSAR_Step2,PSAR_Max2,1);
These variables never change. Assign them in your function.if(Volume[0]==1) // new bar if(itotal==1) MoveStopsToPSAR(); if(itotal==0) Signals();
You have two indented if statements, but only the first one is part of "new bar."-
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 and MetaTrader 4 -
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 and MetaTrader 4 - MQL4 programming forum ticket=OrderSend( result=OrderModify(
Check your return codes for errors and report them.
What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articlesif(NormalizeDouble(PSAR,Digits)<Close[1] && NormalizeDouble(PSAR,Digits)!=OrderStopLoss())
Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong- SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 and MetaTrader 4 - MQL4 programming forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 and MetaTrader 4 - MQL4 programming forum
- Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 and MetaTrader 4 - MQL4 programming forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 and MetaTrader 4 - MQL4 programming forum
- Lot size must also be adjusted to a multiple of LotStep and check against min and max. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
- Doubles are rarely equal.
The == operand. - MQL4 and MetaTrader 4 - MQL4 programming forum if(OrderSelect(1,SELECT_BY_POS,MODE_TRADES)==true)
How do you know that the second order in the list is from your EA and on the current chart? Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 and MetaTrader 4 - MQL4 programming forum- You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled where as Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence.
whroeder1:
- These variables never change. Assign them in your function.
- You have two indented if statements, but only the first one is part of "new bar."
-
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 and MetaTrader 4 -
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 and MetaTrader 4 - MQL4 programming forum -
Check your return codes for errors and report them.
What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles -
Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't
use it. It's use is always wrong
- SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 and MetaTrader 4 - MQL4 programming forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 and MetaTrader 4 - MQL4 programming forum
- Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 and MetaTrader 4 - MQL4 programming forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 and MetaTrader 4 - MQL4 programming forum
- Lot size must also be adjusted to a multiple of LotStep and check against min and max. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
- Doubles are rarely equal.
The == operand. - MQL4 and MetaTrader 4 - MQL4 programming forum - How do you know that the second order in the list is from your EA and on the current chart?
Using OrdersTotal directly and/or no Magic number filtering on your
OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual
trading.)
Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 and MetaTrader 4 - MQL4 programming forum - You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled where as Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence.
Wow, thank you very much for this comprehensive help! I will work on it some more, but might come back for further questions
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello everyone,
I am quite new to MQL programming, but I am basically reading through every tutorial I can find these days. However, now that I have a version of an EA, I noticed it does not work as anticipated. Right now I have no idea why this is the case, so maybe someone can explain where I went wrong.
Short explanation for how it is supposed to work:
- if TotalOrders = 0, check for Buy/Sell Signals
- if Total Order = 1, move Trailing Stop (which already limits the amount of orders open at the time to 1)
Buy/Sell Signals (I know my code can be shortened quite a bit, but for the start I wanted to keep it as simple as possible):
- if current iSARs are below current opening price --> BUY
- if current iSARs are above current opening price --> SELL
- Filter: Both iSARs in previous period should be opposite (therefore only a change if both iSARs entirely changed)
Problems I ran into:
- EA does not stick to the Buy/Sell signals and seems to "randomly" open orders
- Trailing Stop does not actually put the StopLoss to iSAR value
Picture for the "weird signals":
as you can see it doesn't set the StopLoss on iSAR (see red lines under) and also doesn't follow my filter rules (both iSARs had to change)
Can anybody explain to my why this the case? I'll attach the code below.
Thank you very much!
Code: