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
...
1. In general. no, there is no point in checking it since mostly you will have much more bars than you need for a moving average to "stabilize" . It is not an old bug, but is a simple check of how many bars are there in the history
2. Yes. Just bare in mind that since iClose() (it the similar iOpen(), iHigh() and iLow()) are functions while Close[],Open,High[],Low[] is a simple arrays with much, much faster access to values, so you have to weight if you really need the flexibility of the function over the speed and simplicity of the arrays accessing
Hi, I am new to programming but not new to trading. I did not post anything for a while and now, since I started developing my EA, I have lots of questions. I started with building an indicator first, and once it does what I want I will go further. I read all the manuals I could find, so now it is time for me to move ahead with coding.
Sorry, if it is a wrong thread - please let me know where I should post such questions then.
I have 2, probably, basic questions for now, please:
1. In many indicators using MAs I see lines checking for how many bars are on the chart. So, if I need MA200 and the chart only has, say, 100 bars, would iMA200 work then? I think yes - I checked and any MA is drawn without any problems on any chart, so I think this is an old bug that Metaquotes fixed now. So, is there a point of checking how many bars are there on the chart for drawing MA or using iMA function?
2. What is a difference between Close and iClose? My understanding is that Close can return a close of the bars on the current chart only, and iClose can return any close of any currency pair and any timeframe. And in both cases, in order to get a last closed bar I have to use index [1]. Am I seeing it correct?
Thank you.DoubleStochastic for MT4, real DoubleStochastic
Hello guys - new MT4 user.
I am struggling to find DoubleStochastic indicator for MT4. It was my favourite indicator on VTT platform. And I mean REAL DoubleStochastic - not Bressert Double Stochastic which gives totally different indication that original DoubleStochastic. See attached file - Double from VTT gives a bit different indications than Double from MT4:
Is anyone able to help me code VTT'2 DoubleStochastic into MT4? Here is VTT code and logic:
Fast %K = ((Today's Close - Lowest Low in %K Periods) / (Highest High in %K Periods - Lowest Low in %K Periods)) * 100
Slowing %K = N-period moving average of Fast %K
Double %K = ((Today's Slowing %K - Lowest Low Slowing %K in %K Periods) / (Highest High Slowing %K in %K Periods - Lowest Low Slowing %K in %K Periods)) * 100
Double Slowing %K = N-period moving average of Double %K
%D = 3-period simple moving average of Double Slowing %K
and the code itself:
St:= Mov(((C-LLV(L,K))/(HHV(H,K)-LLV(L,K)))*100,Sl,Mt);
DSt:= Mov(((St-LLV(St,K))/(HHV(St,K)-LLV(St,K)))*100,Sl,Mt);
DStD:= Mov(DSt,D,MtD);
Anyone fluent at MT4?
I got used so much to VTT's version that I can not use other.
...
gmailer
Posted a double stochastic here : https://www.mql5.com/en/forum/177239/page28 (in order to keep all versions of stochastic at one place)
I think that it is what you are looking for
Hello guys - new MT4 user.
I am struggling to find DoubleStochastic indicator for MT4. It was my favourite indicator on VTT platform. And I mean REAL DoubleStochastic - not Bressert Double Stochastic which gives totally different indication that original DoubleStochastic. See attached file - Double from VTT gives a bit different indications than Double from MT4:
Is anyone able to help me code VTT'2 DoubleStochastic into MT4? Here is VTT code and logic:
Fast %K = ((Today's Close - Lowest Low in %K Periods) / (Highest High in %K Periods - Lowest Low in %K Periods)) * 100
Slowing %K = N-period moving average of Fast %K
Double %K = ((Today's Slowing %K - Lowest Low Slowing %K in %K Periods) / (Highest High Slowing %K in %K Periods - Lowest Low Slowing %K in %K Periods)) * 100
Double Slowing %K = N-period moving average of Double %K
%D = 3-period simple moving average of Double Slowing %K
and the code itself:
St:= Mov(((C-LLV(L,K))/(HHV(H,K)-LLV(L,K)))*100,Sl,Mt);
DSt:= Mov(((St-LLV(St,K))/(HHV(St,K)-LLV(St,K)))*100,Sl,Mt);
DStD:= Mov(DSt,D,MtD);
Anyone fluent at MT4?
I got used so much to VTT's version that I can not use other.^ Thanks - that might be it. Do you know how to get rid off those "green and pink points" at the bottoms and tops?
thank you mladen. it makes sense.
Hi All,
I am struggling to find a way to find a way to trigger trade when my stochastic line crosses within the overbrought(80) or oversold(20) region. I am able to trigger a trade when my line crosses, however I am not able to set it to trigger a trade ONLY when it is in the overbrought or oversold region. Does anyone have any idea as to how I can go about doing this or is there any other place where I can reference?
I came across some sites that said something about setting some values to 20.1 and 80.1 but nothing more.
Please help to shed some light. Thanks.
Regards
Terrance
...
Terrance,
Here is one thread with some practical code that could be used as an example for what you need : https://www.mql5.com/en/forum/179114
Hi All,
I am struggling to find a way to find a way to trigger trade when my stochastic line crosses within the overbrought(80) or oversold(20) region. I am able to trigger a trade when my line crosses, however I am not able to set it to trigger a trade ONLY when it is in the overbrought or oversold region. Does anyone have any idea as to how I can go about doing this or is there any other place where I can reference?
I came across some sites that said something about setting some values to 20.1 and 80.1 but nothing more.
Please help to shed some light. Thanks.
Regards
TerranceHi, Ive corrected the functions and am happy with them now. Looks good. However the trade results log when I backtest only contains 1 buy order. I think it might be to do with my GetLots function but Im not 100% despite looking over it several times - would you mind casting your eye over it and letting me know if you spot something not right? Thanks.
//--- Function for calculating lots for long positions
double GetLotsLong (int LowRisk, int HighRisk, double SLDistanceLong, int LastOpenTicket, int LastTicket)
{
RefreshRates();
double MinLots, MaxLots, LotStep;
int LotDigit = 2;
double LotsLong = 0;
MinLots = NormalizeDouble(MarketInfo(Symbol(), MODE_MINLOT), 2); // Lots need to be normalized to accommodate LotStep.
MaxLots = NormalizeDouble(MarketInfo(Symbol(), MODE_MAXLOT), 2); // Normalization does not round, but cuts any portion of lot that is larger than LotStep.
LotStep = NormalizeDouble(MarketInfo(Symbol(), MODE_LOTSTEP), 2); // That way the risk is a bit smaller.
if (MarketInfo(Symbol(), MODE_DIGITS) == 3 || MarketInfo(Symbol(), MODE_DIGITS) == 5) SLDistanceLong *= 10.0;
if (LotStep == 1.00) LotDigit = 0;
if (LotStep == 0.10) LotDigit = 1;
if (LotStep == 0.01) LotDigit = 2;
if (GetWinLossPreviousLong (LastOpenTicket, LastTicket, WinLossPreviousLong) == "W")
{
if (AccountBalance() > AccountFreeMargin())
LotsLong = NormalizeDouble(AccountFreeMargin() * (HighRisk / 100) / (SLDistanceLong * MarketInfo (Symbol(), MODE_TICKVALUE)), LotDigit);
else LotsLong = NormalizeDouble(AccountBalance() * (HighRisk / 100) / (SLDistanceLong * MarketInfo (Symbol(), MODE_TICKVALUE)), LotDigit);
}
LotsLong = NormalizeDouble(NormalizeDouble(LotsLong / LotStep, 0) * LotStep, LotDigit);
LotsLong = MathMax(MathMin(LotsLong, MaxLots), MinLots);
return (LotsLong);
if (GetWinLossPreviousLong (LastOpenTicket, LastTicket, WinLossPreviousLong) == "L")
{
if (AccountBalance() > AccountFreeMargin())
LotsLong = NormalizeDouble(AccountFreeMargin() * (LowRisk / 100) / (SLDistanceLong * MarketInfo (Symbol(), MODE_TICKVALUE)), LotDigit);
else LotsLong = NormalizeDouble(AccountBalance() * (LowRisk / 100) / (SLDistanceLong * MarketInfo (Symbol(), MODE_TICKVALUE)), LotDigit);
}
LotsLong = NormalizeDouble(NormalizeDouble(LotsLong / LotStep, 0) * LotStep, LotDigit);
LotsLong = MathMax(MathMin(LotsLong, MaxLots), MinLots);
return (LotsLong);
}
...
GetLots() in the form I posted it is tested and it works as it should. No need for any change of it. Use it as a function that will determine the lot size at the moment of opening order. Keep the rest of the logic out of it (that function should do only that : find out the order size depending on risk, stop loss and current account state)
Without the rest of the code I can not help you. It would be as if I could look trough a tiny hole and see the whole world. Impossible. If you want to keep the rest of the code secret all I can help with is the code you post here, and I will repeat : rest assured that GetLots() in the original form works as it should and it should be used in its original form.
If you want to use it with variable results change the risk or the stop loss feed to it dynamicaly ("decide" of the risk or the stop loss in the code prior to GetLots() and then call it with those altered risk or stop loss - the function will calculate correctly for given aletered inputs) No need to change the code of the function
Hi, Ive corrected the functions and am happy with them now. Looks good. However the trade results log when I backtest only contains 1 buy order. I think it might be to do with my GetLots function but Im not 100% despite looking over it several times - would you mind casting your eye over it and letting me know if you spot something not right? Thanks.
//--- Function for calculating lots for long positions
double GetLotsLong (int LowRisk, int HighRisk, double SLDistanceLong, int LastOpenTicket, int LastTicket)
{
RefreshRates();
double MinLots, MaxLots, LotStep;
int LotDigit = 2;
double LotsLong = 0;
MinLots = NormalizeDouble(MarketInfo(Symbol(), MODE_MINLOT), 2); // Lots need to be normalized to accommodate LotStep.
MaxLots = NormalizeDouble(MarketInfo(Symbol(), MODE_MAXLOT), 2); // Normalization does not round, but cuts any portion of lot that is larger than LotStep.
LotStep = NormalizeDouble(MarketInfo(Symbol(), MODE_LOTSTEP), 2); // That way the risk is a bit smaller.
if (MarketInfo(Symbol(), MODE_DIGITS) == 3 || MarketInfo(Symbol(), MODE_DIGITS) == 5) SLDistanceLong *= 10.0;
if (LotStep == 1.00) LotDigit = 0;
if (LotStep == 0.10) LotDigit = 1;
if (LotStep == 0.01) LotDigit = 2;
if (GetWinLossPreviousLong (LastOpenTicket, LastTicket, WinLossPreviousLong) == "W")
{
if (AccountBalance() > AccountFreeMargin())
LotsLong = NormalizeDouble(AccountFreeMargin() * (HighRisk / 100) / (SLDistanceLong * MarketInfo (Symbol(), MODE_TICKVALUE)), LotDigit);
else LotsLong = NormalizeDouble(AccountBalance() * (HighRisk / 100) / (SLDistanceLong * MarketInfo (Symbol(), MODE_TICKVALUE)), LotDigit);
}
LotsLong = NormalizeDouble(NormalizeDouble(LotsLong / LotStep, 0) * LotStep, LotDigit);
LotsLong = MathMax(MathMin(LotsLong, MaxLots), MinLots);
return (LotsLong);
if (GetWinLossPreviousLong (LastOpenTicket, LastTicket, WinLossPreviousLong) == "L")
{
if (AccountBalance() > AccountFreeMargin())
LotsLong = NormalizeDouble(AccountFreeMargin() * (LowRisk / 100) / (SLDistanceLong * MarketInfo (Symbol(), MODE_TICKVALUE)), LotDigit);
else LotsLong = NormalizeDouble(AccountBalance() * (LowRisk / 100) / (SLDistanceLong * MarketInfo (Symbol(), MODE_TICKVALUE)), LotDigit);
}
LotsLong = NormalizeDouble(NormalizeDouble(LotsLong / LotStep, 0) * LotStep, LotDigit);
LotsLong = MathMax(MathMin(LotsLong, MaxLots), MinLots);
return (LotsLong);
}Hi mladen I agree with you entirely, the GetLots function you provided does work as it should; I tested it as part of my code and it worked.
I have made changes to it simply because I want to change my risk peramter depending on whether I am winning or losing. I have basically elaborated on the existing code (or tried to anyway) incorporating additional money management rules.
I can honestly say that my code is not secret; I am sure many others have considered and implemented in code what I am trying to do; but I suppose there is an element of privacy because I personally have spent so much time developing it.
I will keep reviewing my code, I obviously want to try and resolve any problems myself as I take pride in learning and doing things from scratch.
But I understand your final paragraph; I will use one 'Risk' variable and change this risk accordingly on the output of a function.
Anyway thanks for responding yet again, this forum honestly wouldnt be the same without you; you've helped me out countless amount of times.
Cheers :-)