Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 64

 
alexey1979621:

Dear forum users, please help me very much.


if (TimeBar==Time[0]) return(0);


double MA1 = NormalizeDouble(iMA(NULL,TimeFrame_2,MA_Period_2,MA_Shift_2,MA_Method_2,Applied_Price_2,0),Digits); // where 0 is shift from the current bar by the specified number of periods back
//double MA21 = NormalizeDouble(iMA(NULL,timeframe_2,period_2,ma_shift_2,ma_method_2,applied_price_2,2),Digits);
double MA2 = NormalizeDouble(iMA(NULL,timeFrame_3,MA_Period_3,MA_Shift_3,MA_Method_3,Applied_Price_3,0),Digits);
//double MA31 = NormalizeDouble(iMA(NULL,timeframe_3,period_3,ma_shift_3,ma_method_3,applied_price_3,2),Digits)
double MA3 = NormalizeDouble(iMA(NULL,TimeFrame_4,MA_Period_4,MA_Shift_4,MA_Method_4,Applied_Price_4,0),Digits);

double OsMA = NormalizeDouble(iOsMA(NULL,TimeFrame_5,FastEMA_5,SlowEMA_5,SignalSMA_5,Applied_Price_5,0),Digits)

if (MaxOrders>b && Low[0]>=MathMax(MA1,MA2)&& Low[0]>MA3 && Ask>MathMax(MA1,MA2)+DeltaOpen*Point && Ask>MA3 && MA2<MA3 && MA1<MA3 && OsMA>0 && Trade)
{
if (OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,Digits),Slippage,SL,TP, "Puria_1",Magic,0,Blue) ==-1) TimeBar=0;
else TimeBar=Time[0];

}
if (MaxOrders>s && High[0]<=MathMin(MA1,MA2) && High[0]<MA3 && Bid<MathMin(MA1,MA2)-DeltaOpen*Point && Bid<MA3 && MA1>MA3 && MA2>MA3 && OsMA<0 && Trade)
{
if (OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Bid,Digits),Slippage,SL,TP, "Puria_1",Magic,0,Red) ==-1) TimeBar=0;
else TimeBar=Time[0];
}

return(0);


With these conditions, the Expert Advisor opens a trade, say, on SELL, closes it on profit, and immediately opens another trade on SELL. How to prescribe in an EA, that when the signal is received, only one deal should open, i.e. one signal - one deal.
Thank you in advance.



1 variant - either check the deal condition so that: index 2 shows a buy signal and index 1 a sell signal, then at the opening of a bar with index 0 will open a sell deal.

The 2nd variant is to check the order history and compare the signal and order indices, if they coincide, then do not open any more orders.

 

Where and how is the TimeBar variable initialised?

Although it won't help you much in your case. I see the Trade variable in the conditions, so adjust the opening with it.

 
webman1988:

I've been struggling for two days now and can't figure it out. I need to find the lowest price for the last n bars, but not from the current bar, but from the bar received through the function. The function returns the index of the bar at which the order was opened. This is the bar from which we need to look back through the history for the n bars to find the lowest price. Below is my code, what is wrong with it?



int n = 10;  //баров в глубь истории 

index_bar= ND(iLow(Symbol(),0,i)); // начинаем с этого бара

double val=Low[iLowest(NULL,0,MODE_LOW,n,index_bar)];
like this
 
r772ra:


something like this.

Thank you very much! Tried to use this function too, but again in a loop, it turns out to be simple )))) Thanks again!
 
FAQ:

gyfto:

I have the following question. How do I intercept the mouse wheel, what winapi functions? Let me explain why. There is an int parameter in externs. You need to rotate the wheel to increase or decrease it.


When you find out how to do this, post it...

So far, that's just the way it's worked out:

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 RoyalBlue
#import "user32.dll"
        int GetKeyState(int nVirtKey);//обрабочик клавиатуры
#import

extern int       period = 1;
extern bool      WinAPI = false;//включение-отключение перехвата клавиатуры
extern string    s1="Alt+ArrowUp - increment of period";//памятка
extern string    s2="Alt+ArrowDown - decrement of period";
extern string    s3="Alt+Home - period=1";

double SMA[];
int Alt, ArrowUp, ArrowDown, Home;

int init(){
    SetIndexStyle(0,DRAW_LINE);
    SetIndexBuffer(0,SMA);
    if(WinAPI){//запоминаем состояние клавиш
        Alt = GetKeyState(18);
        ArrowUp = GetKeyState(38);
        ArrowDown = GetKeyState(40);
        Home = GetKeyState(36);
    }
    return(0);
}

int deinit(){
    if(WinAPI) Comment(" ");
    return(0);
}

int start(){
    if(WinAPI){//ставим сконденсированный флаг и снова запоминаем состояние клавиш НА КАЖДОМ ТИКЕ
        int flag = ((Alt!=GetKeyState(18)) && Home==GetKeyState(36)) + 10*((Alt!=GetKeyState(18)) && (ArrowUp==GetKeyState(38))) + 100*((Alt!=GetKeyState(18)) && (ArrowDown==GetKeyState(40)));
        Alt = GetKeyState(18);
        ArrowUp = GetKeyState(38);
                ArrowDown = GetKeyState(40);
        Home = GetKeyState(36);
    }
    int    counted_bars=IndicatorCounted();
    if(WinAPI){//разводка сконденсированного флага; перед limit, чтобы отсюда эмулировать прикрепление к графику
        switch(flag){
            case 11: 
                    if(period>1){
                            period--; 
                            counted_bars = 0;
                    } 
                    break;
            case 101: 
                    period++; 
                    counted_bars = 0; 
                    break;
            case 110: 
                    period=1; 
                    counted_bars = 0;
            }
        }
        int limit = Bars - counted_bars - 1;
        /*Шпаргалка. В первый заход counted_bars = 0, limit = Bars - 1 (номер самого левого БАРа, т.к. считается с нуля)
        на первом тике нулевого бара counted_bars = Bars - 2, limit = 1 (пересчитаем предпоследний БАР)
        на следующих тиках counted_bars = Bars - 1, limit = 0 (нулевой, он же текущий, БАР)*/
        if(WinAPI) Comment("flag=", flag, ", period=", period);//принтуем в коммент для визуализации
        for(int bar=0; bar<=period*(limit/period); bar++){//обычный цикл индикаторов
                SMA[bar] = iMA(NULL, 0, period, 0, MODE_SMA, PRICE_CLOSE, bar);
        }
        return(0);
}
 
It's not interesting, it's the mouse wheel hijacking that's the issue : https://www.mql5.com/ru/forum/139237
 
FAQ, I saw this thread before contacting this thread, so I wasn't surprised by your reaction to the question then)
 
The issue is with hooks, although I solved this problem in a simpler way - if necessary, I make my own settings window in the DLL and there I can do what I want with the Windows controls.
 
As Vadim told me not to use hooks from under MT4, the platform doesn't like them, so I don't touch them. Probably for nothing)
 
gyfto:
As Vadim told me not to use hooks from under MT4, the platform doesn't like them, so I don't touch them. Probably for nothing)
It is MT4 itself that does not like hooks, but from within it (from DLL) you can apply hooks to others.