How to code? - page 308

 

Hi Mladen,

I came across a code done by you on stochastic. However, when I pluck it into my systems, nothing happens. Can I check with you what does it do?

http://www.forexmt4.com/mt_yahoo/Color%20Stochastic%20v1[1].04.mq4

Regards

Terrance

 

...

Try some of these posted here : https://www.mql5.com/en/forum/175297/page3

Or here : https://www.mql5.com/en/forum/177239/page2

Tested and they work

tkuan77:
Hi Mladen,

I came across a code done by you on stochastic. However, when I pluck it into my systems, nothing happens. Can I check with you what does it do?

http://www.forexmt4.com/mt_yahoo/Color%20Stochastic%20v1[1].04.mq4

Regards

Terrance
 

This is strange.

I looked into the padlock issue in a bit more detail. Apparently its to do with my UAC (User Account Control) settings, so I went into my windows7 control panel and turned UAC comletely off. Once I had restarted I noticed the padlock had disapared from the file. I opened it up and its the same as the file I posted on this forum. Completely different to the code I have been writing for the past several weeks even though it is actually the same file. I thought I had lost all my coding work. I turned UAC back on and restarted, the padlock had returned and the code I had written was back to normal again.

But then I tried to compile the code and it picks up a load of errors. But the errors it picks up isnt from this code, but the completely different code when I switch off UAC- I know this because its picking up variables that are only wirtten in the other code.

I think I will need to open a bran new EA and manually type in all this code and save it.

 

...

It is a usual problem with windows 7 (with its protection)

The simplest way to avoid that under windows 7 is to install metatrader on a partition different than C and you will have no problems of that sort

crsnape@btinternet.com:
This is strange.

I looked into the padlock issue in a bit more detail. Apparently its to do with my UAC (User Account Control) settings, so I went into my windows7 control panel and turned UAC comletely off. Once I had restarted I noticed the padlock had disapared from the file. I opened it up and its the same as the file I posted on this forum. Completely different to the code I have been writing for the past several weeks even though it is actually the same file. I thought I had lost all my coding work. I turned UAC back on and restarted, the padlock had returned and the code I had written was back to normal again.

But then I tried to compile the code and it picks up a load of errors. But the errors it picks up isnt from this code, but the completely different code when I switch off UAC- I know this because its picking up variables that are only wirtten in the other code.

I think I will need to open a bran new EA and manually type in all this code and save it.
 

I have finally achieved a proper working EA. Works exactly as it should- I ended up copying my code to notepad, turning of UAC, then pasting it into a new EA file. And I sussed out why my functions were playing up- I had put an int variable inside a normalizeddouble. Didnt know I couldnt do this but now I do- only took me a week to figure it out! :/

Anyway, I have written this:

if (VariableRisk == true) Risk = GetRiskShort (LastOpenTicket, RiskShort);

if (VariableRisk == false) Risk = StaticRisk;

And was wondering if it can be shortened like this?

if (VariableRisk == true)

{

Risk = GetRiskShort (LastOpenTicket, RiskShort);

else Risk = StaticRisk;

}

And also I have written this:

//--- Function for calculating take profit position when long

double GetTPPriceLong (double SLPriceLong, int RiskRewardRatio, int StaticTP, bool AutoCalcTakeProfit)

{

double TPPriceLong = 0;

if (AutoCalcTakeProfit == true)

{

RefreshRates();

TPPriceLong = OrderOpenPrice() + ((OrderOpenPrice() - SLPriceLong) * RiskRewardRatio);

Print("Take profit position calculated successfully");

return (TPPriceLong);

}

if (AutoCalcTakeProfit == false)

{

RefreshRates();

TPPriceLong = OrderOpenPrice() + (StaticTP * 0.0001);

Print("Static take profit position calculated successfully");

return (TPPriceLong);

}

}

And was wondering if it can be shortened like this?

//--- Function for calculating take profit position when long

double GetTPPriceLong (double SLPriceLong, int RiskRewardRatio, int StaticTP, bool AutoCalcTakeProfit)

{

double TPPriceLong = 0;

RefreshRates();

if (AutoCalcTakeProfit == true)

{

TPPriceLong = OrderOpenPrice() + ((OrderOpenPrice() - SLPriceLong) * RiskRewardRatio);

Print("Take profit position calculated successfully");

else TPPriceLong = OrderOpenPrice() + (StaticTP * 0.0001);

Print("Static take profit position calculated successfully");

return (TPPriceLong);

}

And one final question, to provide some more flexibility to my EA, I want to define my timeframes as external variables. My signal chart is to be D1 say, and my trigger chart is to be H4. So under external variables could I do this:

extern int SignalChart = PERIOD_D1;

extern int TriggerChart = PERIOD_H4;

And then reference it by doing this for example:

SlowMACurrent = iMA(Symbol(), SignalChart, SlowMAPeriod, 0, MODE_SMA, PRICE_CLOSE, 1);

 

About this part :

And then reference it by doing this for example: SlowMACurrent = iMA(Symbol(), SignalChart, SlowMAPeriod, 0, MODE_SMA, PRICE_CLOSE, 1);

Yes, that is a 100% correct way to use it (even to the point that you are using a closed bar (shift in that example is set to 1) and that, by using a closed bar in testing, you are going to avoid the usual trap of using open bar in multi time framing)

crsnape@btinternet.com:
I have finally achieved a proper working EA. Works exactly as it should- I ended up copying my code to notepad, turning of UAC, then pasting it into a new EA file. And I sussed out why my functions were playing up- I had put an int variable inside a normalizeddouble. Didnt know I couldnt do this but now I do- only took me a week to figure it out! :/

Anyway, I have written this:

if (VariableRisk == true) Risk = GetRiskShort (LastOpenTicket, RiskShort);

if (VariableRisk == false) Risk = StaticRisk;

And was wondering if it can be shortened like this?

if (VariableRisk == true)

{

Risk = GetRiskShort (LastOpenTicket, RiskShort);

else Risk = StaticRisk;

}

And also I have written this:

//--- Function for calculating take profit position when long

double GetTPPriceLong (double SLPriceLong, int RiskRewardRatio, int StaticTP, bool AutoCalcTakeProfit)

{

double TPPriceLong = 0;

if (AutoCalcTakeProfit == true)

{

RefreshRates();

TPPriceLong = OrderOpenPrice() + ((OrderOpenPrice() - SLPriceLong) * RiskRewardRatio);

Print("Take profit position calculated successfully");

return (TPPriceLong);

}

if (AutoCalcTakeProfit == false)

{

RefreshRates();

TPPriceLong = OrderOpenPrice() + (StaticTP * 0.0001);

Print("Static take profit position calculated successfully");

return (TPPriceLong);

}

}

And was wondering if it can be shortened like this?

//--- Function for calculating take profit position when long

double GetTPPriceLong (double SLPriceLong, int RiskRewardRatio, int StaticTP, bool AutoCalcTakeProfit)

{

double TPPriceLong = 0;

RefreshRates();

if (AutoCalcTakeProfit == true)

{

TPPriceLong = OrderOpenPrice() + ((OrderOpenPrice() - SLPriceLong) * RiskRewardRatio);

Print("Take profit position calculated successfully");

else TPPriceLong = OrderOpenPrice() + (StaticTP * 0.0001);

Print("Static take profit position calculated successfully");

return (TPPriceLong);

}

And one final question, to provide some more flexibility to my EA, I want to define my timeframes as external variables. My signal chart is to be D1 say, and my trigger chart is to be H4. So under external variables could I do this:

extern int SignalChart = PERIOD_D1;

extern int TriggerChart = PERIOD_H4;

And then reference it by doing this for example:

SlowMACurrent = iMA(Symbol(), SignalChart, SlowMAPeriod, 0, MODE_SMA, PRICE_CLOSE, 1);
 

Hi, I am getting error code 4059:

[TD]Function is not allowed in testing mode.

ERR_FUNC_NOT_ALLOWED_IN_TESTING[/TD]

4059

Ive done a search but cant find any more information about what it means?

 

Can you help add the following codes to this parabolic sar indicator?

Pip:
Thanks Mladen,

I will re-read your post to understand, honestly i got a bit lost reading it but it is most likely my ignorance taking play. I will post questions if i have any.

Thanks mate.

Cheers,

Pip

Dear Friend,

CAN YOU HELP ADD THE FOLLOWING CODES TO THIS PARABOLIC SAR alert parabolic_alert_mod.mq4INDICATOR?

I am not looking for an EA. If possible atleast add the SHIFT option to the indicator.

extern double TakeProfit = 50;

extern double Lots = 0.1;

extern double TrailingStop = 30;

extern double SAR_Step = 0.02;

extern double SAR_Maximum = 0.2;

extern double Shift=1;

Files:
 

...

joelnelson

TakeProfit, Lots and TrailingStop have nothing to do with the way how parabolic sar s calculated (those parameters are obviously taken from an EA using sar in its work). So, if you are not looking for an EA, it is not possible to add those parameters in a meaningful way

Also. the shift in the parameters is reffering to the bar that is tested (parabolic SAR is not shifted as movinga average can be shifted usually) Those parameters are probably meant for a call to a built in sar and the built in sar has the following form

double iSAR([/TD] [TD]string symbol, int timeframe, double step, double maximum, int shift)

Shift 1 in that case mans to test the value of the first closed bar of parabolic sar

joelnelson:
Dear Friend,

CAN YOU HELP ADD THE FOLLOWING CODES TO THIS PARABOLIC SAR alert parabolic_alert_mod.mq4INDICATOR?

I am not looking for an EA. If possible atleast add the SHIFT option to the indicator.

extern double TakeProfit = 50;

extern double Lots = 0.1;

extern double TrailingStop = 30;

extern double SAR_Step = 0.02;

extern double SAR_Maximum = 0.2;

extern double Shift=1;
 

...

That error can be returned by some functions.

The functions that can cause that error in testing are the following :

MarketInfo

MessageBox

SendFTP

SendMail

WindowIsVisible

WindowFind

WindowHandle

So, a call to some of the above functions caused that error

crsnape@btinternet.com:
Hi, I am getting error code 4059: [TD]Function is not allowed in testing mode.
ERR_FUNC_NOT_ALLOWED_IN_TESTING[/TD] 4059
Ive done a search but cant find any more information about what it means?
Reason: