Coding help - page 36

 

Need hand regading STOPLOSS

mladen:
kemal44

Here is a link to a thread where it is explained how to use functions in code : https://www.mql5.com/en/forum/173005

It is explained very good there (and more than I can explain in one post) how to use them

Dear Mladen ,

when backtesting ,BreakEven-Stoplos seems working but when the real account , as far as I see that it doesnt work properly ,

would you mind taking a look an expert file, and then tell me what's wrong with it?

thanks in advance

Files:
xpexpert.txt  24 kb
 

...

kemal

Check in the experts tab of terminal what error is written out.

I can not check it since it is missing the entry logic (it never sets BuyCondition or SellCondition to true the way it is written)

kemal44:
Dear Mladen ,

when backtesting ,BreakEven-Stoplos seems working but when the real account , as far as I see that it doesnt work properly ,

would you mind taking a look an expert file, and then tell me what's wrong with it?

thanks in advance
 
mladen:
kemal

Check in the experts tab of terminal what error is written out.

I can not check it since it is missing the entry logic (it never sets BuyCondition or SellCondition to true the way it is written)

here is the expert with buy sell logic ,

problem is breakeven stop-loss .

What I wanna to do by breakeven is that if profit jump up 5 pip from entry point ,stop-loss should be set to entry point in order to protect portfolio ,

thanks in advance

Files:
xpexpert_1.txt  24 kb
 

...

Since the minimal distance of the stop loss depends from symbol to symbol, from broker to broker and can vary from one moment to another, before setting the break even, add a check that would go something like this (this is a generic example when an order is a buy order, you can write it very similar to sell order) :

double minimalDistance = MarketInfo(Symbol(),MODE_STOPLEVEL)*Point;

if (OrderType()=OP_BUY && (Bid-OrderOpenPrice())>=minimalDistance)

... your code for setting stop loss

PS: this is all valid (according to latest changes - from build 419 upwards) in cases when you broker is not an ECN broker. If your broker is an ECN broker in that case MarketInfo(Symbol(),MODE_STOPLEVEL) will return 0 in latest builds and you will have to do some experimenting to adjust the minimal distance (if there is one) of the stop loss

kemal44:
here is the expert with buy sell logic ,

problem is breakeven stop-loss .

What I wanna to do by breakeven is that if profit jump up 5 pip from entry point ,stop-loss should be set to entry point in order to protect portfolio ,

thanks in advance
 
mladen:
Since the minimal distance of the stop loss depends from symbol to symbol, from broker to broker and can vary from one moment to another, before setting the break even, add a check that would go something like this (this is a generic example when an order is a buy order, you can write it very similar to sell order) :
double minimalDistance = MarketInfo(Symbol(),MODE_STOPLEVEL)*Point;

if (OrderType()=OP_BUY && (Bid-OrderOpenPrice())>=minimalDistance)

... your code for setting stop loss

PS: this is all valid (according to latest changes - from build 419 upwards) in cases when you broker is not an ECN broker. If your broker is an ECN broker in that case MarketInfo(Symbol(),MODE_STOPLEVEL) will return 0 in latest builds and you will have to do some experimenting to adjust the minimal distance (if there is one) of the stop loss

thank you ;

Distance is nice idea ,

I have no idea about ECN Broker rules, my broker is local company

 

...

kemal44

Of your broker - try the following : a simple way to check is to try to open an order manually but when you do that try setting stop loss and / or take profit. If those fields are disabled (like on the picture bellow) in the open order dialog or whatever value except 0 you set in those you get an error then your broker is an "ECN / STP" type of broker

kemal44:
thank you ;

Distance is nice idea ,

I have no idea about ECN Broker rules, my broker is local company
Files:
order_open.gif  22 kb
 
mladen:
kemal44

Of your broker - try the following : a simple way to check is to try to open an order manually but when you do that try setting stop loss and / or take profit. If those fields are disabled (like on the picture bellow) in the open order dialog or whatever value except 0 you set in those you get an error then your broker is an "ECN / STP" type of broker

My trading windows is the exactly same as above pic .I undurstood my borker is type of "ECN / STP" .

thank you

in the meantime , Can we get channels(StdDev etc..) provided by MT4 automaticly in our chart by the indicator or ea based code ,I have no idea how to code it , would you mind helping me to get sample code for that?

thanks in advance

 

...

kemal44

I am not sure if I understand the question about the "channels", but let me try :

You can use any metatrader built in indicator using functions they provided. For standard deviation for example the syntax is the following:

[/TR]

[TR]

[TD="width: 100%"]MA shift.

[TR]

[TD]ma_method

[TD] - [TD="width: 100%"]MA method. It can be any of Moving Average method enumeration value.

[TR]

[TD]applied_price [TD] - [TD="width: 100%"]Applied price. It can be any of Applied price enumeration values.

[TR]

[TD]shift [TD] - [TD="width: 100%"]Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).
double iStdDev(

[/TD]

string symbol, int timeframe, int ma_period, int ma_shift, int ma_method, int applied_price, int shift)[/TD]

[/TR]

[/TABLE]

Calculates the Standard Deviation indicator and returns its value. Parameters:

[TABLE="class: docparams"]

symbol[/TD] - [/TD] Symbol the data of which should be used to calculate indicator. NULL means the current symbol.[/TD]

[/TR]

timeframe[/TD] - [/TD] Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.[/TD]

[/TR]

ma_period[/TD] - [/TD] MA period. ma_shift -

Sample:

double val=iStdDev(NULL,0,10,0,MODE_EMA,PRICE_CLOSE,0);

_________________________________________

Similar is for other built in indicators (these ones :

So you can use any of those as a function call from another indicator, script or EA

If You meant to display some of the built in indicators values on chart, then you have to use a drawing buffer (like in regular indicators) assign values of some of the above functions to the drawing buffer and it will be displayed on chart. EAs do not have drawing buffers, so you can not do that using drawing buffers from an EA (you would need to use objects, but that is a completely different story)

kemal44:
My trading windows is the exactly same as above pic .I undurstood my borker is type of "ECN / STP" .

thank you

in the meantime , Can we get channels(StdDev etc..) provided by MT4 automaticly in our chart by the indicator or ea based code ,I have no idea how to code it , would you mind helping me to get sample code for that?

thanks in advance
 
mladen:
kemal44

I am not sure if I understand the question about the "channels", but let me try :

You can use any metatrader built in indicator using functions they provided. For standard deviation for example the syntax is the following:

[/TR]

[TR]

[TD="width: 100%"]MA shift.

[TR]

[TD]ma_method [TD] - [TD="width: 100%"]MA method. It can be any of Moving Average method enumeration value.

[TR]

[TD]applied_price [TD] - [TD="width: 100%"]Applied price. It can be any of Applied price enumeration values.

[TR]

[TD]shift [TD] - [TD="width: 100%"]Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).
double iStdDev([/TD] string symbol, int timeframe, int ma_period, int ma_shift, int ma_method, int applied_price, int shift)[/TD]

[/TR]

[/TABLE]

Calculates the Standard Deviation indicator and returns its value. Parameters:

[TABLE="class: docparams"]

symbol[/TD] -[/TD] Symbol the data of which should be used to calculate indicator. NULL means the current symbol.[/TD]

[/TR]

timeframe[/TD] -[/TD] Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.[/TD]

[/TR]

ma_period[/TD] -[/TD] MA period. ma_shift -

Sample:

double val=iStdDev(NULL,0,10,0,MODE_EMA,PRICE_CLOSE,0);

_________________________________________

Similar is for other built in indicators (these ones :

So you can use any of those as a function call from another indicator, script or EA

If You meant to display some of the built in indicators values on chart, then you have to use a drawing buffer (like in regular indicators) assign values of some of the above functions to the drawing buffer and it will be displayed on chart. EAs do not have drawing buffers, so you can not do that using drawing buffers from an EA (you would need to use objects, but that is a completely different story)

What I mean by Sdv Channel is the channel like as below ,

by the way , thank you for promp response.

Files:
xxx.gif  13 kb
 

EA with Parabolic SAR

Have some one idea trading with parabolic SAR. I want make EA with Parabolic SAR but until now I don't get good result. So If you have Idea with Parabolic SAR I will make it better. The last I make it can make that profit. but Equity never same with balance.

Files:
Reason: