Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 52

 
trader781:

What to do if the stop/stop is 200

but

tp=NormalizeDouble((price+(TakeProfit*_Point)),Digits);

on a dollar-yen will yield 317.000 at the exchange rate of 117.000

expected result 117.200

If Point()==0.001 (on USDJPY), then 200*0.001 equals 0.2

Now if we add 0.2 to 117.0 we get 117.2

Where is the "unfairness"?

 
Artyom Trishkin:

If Point()==0.001 (on USDJPY), then 200*0.001 equals 0.2

Now if we add 0.2 to 117.0 we get 117.2

And where is the "unfairness"?

it is expected that 117+(200*_Point) will yield 117.200

it is normally tested on EURUSD

Vitaly described it above, thank you.

I think I have found it.

I think it is good enough as intermediate algorithm and now it is necessary to filter these moments somehow

https://www.mql5.com/ru/charts/6351907/audjpy-m5-metaquotes-software-corp

График AUDJPY, M5, 2017.01.02 22:49 UTC, MetaQuotes Software Corp., MetaTrader 4, Demo
График AUDJPY, M5, 2017.01.02 22:49 UTC, MetaQuotes Software Corp., MetaTrader 4, Demo
  • www.mql5.com
Символ: AUDJPY. Период графика: M5. Брокер: MetaQuotes Software Corp.. Торговая платформа: MetaTrader 4. Режим торговли: Demo. Дата: 2017.01.02 22:49 UTC.
 
trader781:

117+(200*_Point) is expected to give an output of 117.200

...

Well, that's what he's giving... I showed you the calculation. Or do you have multicurrency and take data from a "non-native" symbol?

Then use SymbolInfoDouble() and (int)SymbolInfoInteger() instead of Point() and Digits()

 
Artyom Trishkin:

Well, that's what he's giving... I showed you the calculation. Or do you have a multi-currency, and take the data from a "non-native" symbol?

Then instead of Point() and Digits() use SymbolInfoDouble() and (int)SymbolInfoInteger()

Thanks, it works)))

I am currently looking for a way to insert a trailing stop in a chain of orders

I have 10 orders in steps of 200 from 115.000 to 117.000

Each lot is larger by x value than the previous one

the target is to put a trailing stop on the whole order chain using the following calculation (average price)+(y*_Point)

I have a trailing stop. My question is how to attach it to the average price for the whole stack and how it is calculated depending on lots

 
trader781:

Thank you, it works)))

Currently looking for a way to insert trailing in a chain of orders

I have 10 orders in steps of 200 from 115.000 to 117.000

Each lot is larger by x value than the previous one

the target is to put a trailing stop on the whole order chain using the following calculation (average price)+(y*_Point)

I have a trailing stopper itself; the question is how to attach it to the average price for the whole st ack and how it is calculated depending on lots

One universal advice: Learn to program from scratch. Then you won't have such questions, programming is not an easy task.

And to the essence of the question: So, you have to go through ALL orders in a loop, selecting only "necessary" and modify them. But you have to be very careful with this, because the probability of replacing the selected order to work is very high.

 
Alexey Viktorov:

One universal piece of advice: Learn to program from scratch. Then there will be no such questions, programming is not easy.

And to the essence of the question: So, you need to go through ALL orders in the loop, selecting only "necessary" and modify them. But you have to be very careful with this question, because the probability of replacing the selected order to work is very high.

It is not high, but 100%. At the moment I am working on the last one and the rest are on pause, but the scheme is inaccurate and I would like to do better
 

Good day to all, I wrote an EA based on MAs. (I myself started to write in MQL4 not so long ago, so I decided to start with something simple. So I wanted to know what I did wrong. The essence of the Expert Advisor is simple: give an alert when two or three MAs are crossed (depending on the METHOD: Aggressive = crossover of two MAs, conservative = crossover of 3 MAs) ... That's all. I will enter the market on my own. In my Expert Advisor, I prescribed two functions: Aggressive - this is a signal at a simple crossover of two fastest MAs and Conservative - when at the crossover of two fast MAs you should also consider the slowest one (that is, the signal in the direction of the trend). The problem is that the Expert Advisor gives only ONE alert (when it starts or changes timeframe) and is silent on all subsequent signals! I would be grateful if you tell me what's wrong. I have prescribed the function for all events according to MQL4 rules. Of course I could register everything without functions in On Tick event, but I want to register functions separately, so thefunctions could be easilycalled and I want to add new "filters" functions with time.

Code

================================================================================================

extern bool Metod=false; // method selection: Conservative or Aggressive.

extern int Time_Frame=1;//Time frame

input bool Metod=false; //Conservative-TRUE | Aggressive-FALSE

extern inttern FastMA_Parametr=5;

extern int int intMA_Parametr=8;

extern int SlowMA_Parametr=18;

extern inttern TrendMA=163;

extern bool DemarkGo=false;

extern inttern Demperiod=4;

int rez;// if MA crosses downwards, rez=-1. if upwards, rez=1.

//+------------------------------------------------------------------+

// Initialize MA

double FastMA=iMA(Symbol(),Time_Frame,FastMA_Parametr,0,3,0,0);// FastMA

double MiddiMA=iMA(Symbol(),Time_Frame,MidMA_Parametr,0,3,0,0);// Average MA

double SlowMA=iMA(Symbol(),Time_Frame,SlowMA_Parametr,0,1,0,0); Slow МА


//+------------------------------------------------------------------+

int OnInit()

{

rez=0;

return(INIT_SUCCEEDED);

}

//=======================================

//------------------------------------------------------------------------------

void OnDeinit(const int reason)

{



}

//=============================================

//+---------------------Function for Konservative signal if Metod=true---------------------------------------------+

int Konservative()

//Check for an upward crossover of 3 lines

{

if (Metod==true)


{

if(FastMA>MiddiMA&&&MiddiMA>SlowMA&&rez<=0)

{

Alert(Symbol(),Time_Frame,"----Up----. Conservative");

rez=1;

Comment("FastMA ",FastMA," MiddiMA ",MiddiMA," SlowMA ",SlowMA," rez ",rez);

return(rez);


}


//Check for downward crossover of 3 lines

if(FastMA<MiddiMA&&MiddiMA<SlowMA&&rez>=0)

{

Alert(Symbol(),Time_Frame," ---- DOWN----. Conservative");

rez=-1;

Comment("FastMA ",FastMA," MiddiMA ",MiddiMA," SlowMA ",SlowMA," rez ",rez);

return(rez);


}

}

return(rez);

}

//=================================================

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Aggressive function if

int Agressive()

// Check for upward crossover of 2 lines without slow


{

if (Metod==false)

{

if(FastMA>MiddiMA&&rez<=0)

{

Alert(Symbol(),Time_Frame,"----Up----. aggressive");

rez=1;

Comment("FastMA ",FastMA," MiddiMA ",MiddiMA," SlowMA ",SlowMA," rez ",rez);


}


//Check for downward crossover of 2 lines without a slow line

if(FastMA<MiddiMA&&rez>=0)

{

Alert(Symbol(),Time_Frame," ---- DOWN----. Aggressive");

rez=-1;

Comment("FastMA ",FastMA," MiddiMA ",MiddiMA," SlowMA ",SlowMA," rez ",rez);

}

}

return(rez);

}

 
Олег:


Here, I think you can do it yourself.
Files:
6645.mq4  7 kb
 
trader781:
It is not high, but 100 %. At the current moment it is the last order and the others are on pause, but the scheme is not precise and I'd like it to be better.

No, not 100%. Or maybe you're talking about something else.

In general, the algorithm is as follows:

You set up a loop to go through all the orders.

You select the next order to work with it.

You check to see if that order is needed... If not, the next iteration of the loop...

If it is "needed", check if it is suitable for modification. Simply compare how far away it is from its StopLoss level

If the distance is sufficient, the order is modified.


So, if you have a modification function with a loop on all orders, and before its call, the loop is also working, then the selected order will be changed...

 
Alexey Viktorov:

No, not 100%. Or maybe you're talking about something else.

In general, the algorithm is as follows:

You set up a loop to go through all the orders.

You select the next order to work with it.

You check to see if that order is needed... If not, the next iteration of the loop...

If it is "needed", check if it is suitable for modification. Simply compare how far away it is from its StopLoss level

If it is far enough, the order is modified.


So, if you have a modification function with a loop on all orders, and before its calling, the loop is also working, then the selected order will be changed...

The point is that there will ALWAYS be losing orders with a certain lot, which will also have to be filled at the expense of the rest. The trigger is the closing time. If we close even one, the whole chain will be lost. Therefore the question is how to trawl the average price of all chosen ones.
Reason: